Feat: Live search accessibility, no-results message and View all styling

This commit is contained in:
elvira committed 2026-10-23 20:59:23 +03:00
1 parent d1d27a9ebd
commit 9217960de0
4 files changed
+118 -33

No files matched your search

@@ -9,7 +9,11 @@
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.
(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"
@@ -24,15 +28,19 @@ class="fixed w-full inset-x-0 top-0 bottom-auto m-0 border-0 bg-transparent p-0"
data-nav-search-target="form"
class="flex h-[var(--search-overlay-h)] items-center gap-6 bg-brand px-10"
>
<label for="search-overlay-input" class="sr-only">{{ __('storefront.shop.search_label') }}</label>
<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"
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"
>
@@ -47,5 +55,7 @@ class="shrink-0 text-black transition-opacity hover:opacity-70"
</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>
@@ -7,7 +7,7 @@
--}}
@if ($products->isEmpty())
<p class="text-neutral-500">{{ __('storefront.shop.no_products') }}</p>
<p class="text-neutral-500">{{ __('storefront.search.no_results', ['query' => $query]) }}</p>
@else
<div class="flex items-center justify-between gap-6 flex-wrap mb-7">
<x-shop.result-count :paginator="$products" />
+54 -28
View File
@@ -4,41 +4,67 @@
Up to six products (thumbnail, name with the matched words underlined,
price), then a link to the full results page. Empty below 3 characters.
ARIA: the overlay's input is a combobox controlling the listbox below. The
options stay out of the tab order (focus remains in the input); the
`nav-search` controller moves aria-selected / aria-activedescendant with
the arrow keys. The hidden summary is copied into the overlay's persistent
role="status" region, since a live region swapped in with the frame isn't
reliably announced.
Vars: $query (string), $products (Collection of ProductCard arrays),
$total (int), $searched (bool)
--}}
<turbo-frame id="search-suggestions">
@if ($searched)
<div class="max-h-[calc(100dvh-var(--search-overlay-h))] overflow-y-auto bg-white border-b border-black">
@forelse ($products as $product)
<a
href="{{ $product['href'] }}"
data-turbo-frame="_top"
class="flex items-center gap-5 border-b border-neutral-300 px-10 py-4 transition-colors hover:bg-neutral-100 focus-visible:bg-neutral-100 focus-visible:outline-none"
>
<span class="flex aspect-[251/335] w-16 shrink-0 items-center justify-center overflow-hidden border border-black bg-white">
@if ($product['image'])
<img src="{{ $product['image'] }}" alt="" loading="lazy" class="block h-auto w-full">
@endif
</span>
<span class="min-w-0 flex-1">{{ \App\Support\SearchHighlight::name((string) $product['name'], $query) }}</span>
@if ($product['price'] !== null)
<span class="shrink-0"><x-ui.price :amount="$product['price']" /></span>
@endif
</a>
@empty
<p class="px-10 py-6 text-neutral-500">{{ __('storefront.shop.no_products') }}</p>
@endforelse
<p hidden data-nav-search-target="summary">{{ trans_choice('storefront.search.results_count', $total, ['count' => $total]) }}</p>
@if ($total > 0)
<a
href="{{ route('search', ['q' => $query]) }}"
data-turbo-frame="_top"
class="flex items-center justify-between px-10 py-5 font-medium uppercase tracking-wide transition-colors hover:bg-neutral-100 focus-visible:bg-neutral-100 focus-visible:outline-none"
<div class="max-h-[calc(100dvh-var(--search-overlay-h))] overflow-y-auto bg-white border-b border-black">
@if ($products->isNotEmpty())
<div
id="search-suggestions-list"
role="listbox"
aria-labelledby="search-overlay-label"
data-nav-search-target="listbox"
>
{{ trans_choice('storefront.search.view_all', $total, ['count' => $total]) }}
<x-ui.icon name="arrow-right" :size="20" />
</a>
@foreach ($products as $product)
<a
id="search-option-{{ $loop->index }}"
href="{{ $product['href'] }}"
role="option"
aria-selected="false"
tabindex="-1"
data-turbo-frame="_top"
data-nav-search-target="option"
class="flex items-center gap-5 border-b border-neutral-300 px-10 py-2 transition-colors hover:bg-neutral-100 aria-selected:bg-neutral-100"
>
<span class="flex aspect-[251/335] w-14 shrink-0 items-center justify-center overflow-hidden border border-black bg-white">
@if ($product['image'])
<img src="{{ $product['image'] }}" alt="" loading="lazy" class="block h-auto w-full">
@endif
</span>
<span class="min-w-0 flex-1">{{ \App\Support\SearchHighlight::name((string) $product['name'], $query) }}</span>
@if ($product['price'] !== null)
<span class="shrink-0"><x-ui.price :amount="$product['price']" /></span>
@endif
</a>
@endforeach
<a
id="search-option-all"
href="{{ route('search', ['q' => $query]) }}"
role="option"
aria-selected="false"
tabindex="-1"
data-turbo-frame="_top"
data-nav-search-target="option"
class="flex items-center gap-3 bg-black px-10 py-4 text-[19px] font-bold italic uppercase text-white transition-colors hover:bg-neutral-800 aria-selected:bg-neutral-800"
>
{{ trans_choice('storefront.search.view_all', $total, ['count' => $total]) }}
<x-ui.icon name="arrow-right" :size="20" />
</a>
</div>
@else
<p class="px-10 py-6 text-neutral-500">{{ __('storefront.search.no_results', ['query' => $query]) }}</p>
@endif
</div>
@endif