v0.0.2
Demos (demo panel, opens in a new tab)

Search form

A search box with a magnifier icon and a clear button; it works as a GET form that reloads the page or as a live Livewire search.

zb:search zubazar/ui · free (MIT)

Search form that reloads the page

Search form that reloads the page: view
BLADE

With action the component becomes a search form and sends the text to that address by GET, as ?q=.

blade
<zb:search name="q" :value="request('q')" :action="route('customers.index')" button="Search" placeholder="Search customers">
    <input type="hidden" name="status" value="{{ request('status') }}">
</zb:search>
PropValues
actionURL the form is submitted to
methodGET (default) or POST; @csrf is added for POST when the URL is the application's own
buttonText of the attached submit button

Keyboard shortcut

Keyboard shortcut: view
BLADE

Pressing the shortcut key anywhere on the page focuses the field.

blade
<zb:search name="q" shortcut="/" placeholder="Search the menu" />
PropValues
shortcutKey that focuses the field, for example "/"

Live search with Livewire

BLADE

With wire:model.live results arrive as the user types; a spinner replaces the magnifier while the request runs.

blade
<zb:search wire:model.live.debounce.300ms="search" shortcut="/" placeholder="Search customers" />
PropValues
wire:modelThe bound Livewire property; the field's id also comes from it

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
name—nullField name (the query parameter in a GET form)
placeholder—SearchPlaceholder; without a visible label, the field's accessible name
label—nullVisible label above the field
action—nullWhen given, the component is a <form role="search">; otherwise a <div role="search">
method—GETGET or POST; with POST, @csrf is added only for the application's own address
button—nullText of the attached submit button
shortcut—nullKey that focuses the field, for example "/"
clearablebooleantrueClear (×) button and clearing with Esc
size—mdmd (40 px) or lg (48 px)
input-class—nullClasses of the field (<input>) itself
class · style · x-show · wire:key——Added to the element around the whole search; other attributes go to the field

Slots: The default slot is written inside the form, below the field: for hidden fields that keep other query parameters.

Advanced

2 examples

Large size

Large size: view
BLADE

size="lg" gives a larger, 48 px field for a page's main search (e.g. a help centre).

blade
<zb:search name="question" size="lg" button="Search" placeholder="E.g. return policy, downloading invoices" />
PropValues
sizemd (40 px, default) or lg (48 px)

Search form with filters

Search form with filters: view
BLADE

Inside a form with other fields, leave out action and use the form's own submit button. label adds a visible label above the field.

blade
<form wire:submit="search" class="grid items-end gap-4 md:grid-cols-[minmax(0,2fr)_minmax(0,1fr)_auto]">
    <zb:search wire:model="term" label="Search term" placeholder="Name, phone or address" />
    <zb:select wire:model="status" label="Status" :options="['' => 'All statuses', 'pending' => 'Pending', 'approved' => 'Approved']" />
    <zb:button type="submit">Search</zb:button>
</form>
PropValues
labelVisible label above the field

Developer notes

Events, hooks and details
  • class, style, x-show and wire:key go to the element around the whole search, other attributes (name, value, placeholder, autofocus…) to the field; style the field with input-class.
  • Without a visible label, placeholder is the field's name for screen readers.
  • To keep other query parameters in the form, write hidden fields inside the component.
  • An unsafe action (javascript: or another site's // address) is not written: the form searches the current page by GET, no CSRF token is added and a warning is logged.
  • The shortcut does nothing while typing in another field or with Ctrl/⌘; while the field is empty and not focused, a hint of the key shows on the right.
  • The spinner shows only for this property's requests; when the server changes the value, the clear button and the shortcut hint update themselves.
Zubazar UI · ZubazarDesigned for people.