Files

61 lines
2.8 KiB
PHP
Raw Permalink Normal View History

{{--
Full-width search bar that covers the header. A [popover] (top layer, so it
sits over the sticky header with no z-index juggling; Escape and click-away
close come for free). The header's search button opens it via popovertarget.
The `nav-search` controller measures the header on open (→ --search-overlay-h,
since the header isn't a fixed height below `lg`) and focuses the field.
Fade transition and the dimmed page behind live in app.css (#search-overlay).
Live search: from 3 characters, the `nav-search` controller points the
<turbo-frame id="search-suggestions"> under the bar at the same /search
endpoint, which answers that frame with the first few matches
(search/suggestions.blade.php). Enter still goes to the full results page,
unless a suggestion is highlighted with the arrow keys.
ARIA: the input is a combobox for the suggestions listbox; the role="status"
region below announces the result count after each load.
--}}
<div
id="search-overlay"
popover
data-controller="nav-search"
data-nav-search-min-chars-value="{{ \App\Http\Controllers\SearchController::LIVE_MIN_CHARS }}"
class="fixed w-full inset-x-0 top-0 bottom-auto m-0 border-0 bg-transparent p-0"
>
<form
method="get"
action="{{ route('search') }}"
data-nav-search-target="form"
class="flex h-[var(--search-overlay-h)] items-center gap-4 bg-brand px-5 sm:px-8 lg:gap-6 lg:px-10"
>
<label id="search-overlay-label" for="search-overlay-input" class="sr-only">{{ __('storefront.shop.search_label') }}</label>
<input
id="search-overlay-input"
type="search"
name="q"
required
autocomplete="off"
role="combobox"
aria-autocomplete="list"
aria-expanded="false"
aria-controls="search-suggestions-list"
data-nav-search-target="input"
data-action="input->nav-search#suggest keydown->nav-search#navigate"
placeholder="{{ __('storefront.search.placeholder') }}"
class="min-w-0 flex-1 appearance-none border-0 border-b border-black bg-transparent pb-2 placeholder:text-black/60 focus:outline-none [&::-webkit-search-cancel-button]:appearance-none"
>
<button
type="button"
popovertarget="search-overlay"
popovertargetaction="hide"
aria-label="{{ __('storefront.nav.close') }}"
class="shrink-0 text-black transition-opacity hover:opacity-70"
>
<x-ui.icon name="close" :size="44" />
</button>
</form>
<p role="status" class="sr-only" data-nav-search-target="status"></p>
<turbo-frame id="search-suggestions" data-nav-search-target="results"></turbo-frame>
</div>