Wirestrap is still in active development
This project is pre-1.0 and may introduce breaking changes at any time without prior notice.
Autocomplete
Text input with a suggestion dropdown and inline ghost text.
The suggestion list comes from a Livewire method via wire-options,
called once on first focus and cached client-side. If a value is already bound
on load, the method is called immediately to resolve it.
Keyboard:
- ↑ ↓ to navigate,
- Tab, Enter or , to confirm,
- Escape to close.
Basic usage
Declare a method returning a list<string> and pass its name to
wire-options. Use icon to add an icon,
and floating for a floating label layout.
#[Renderless]
public function getCities(): array
{
return ['Paris', 'London', 'Berlin'];
}
{{-- Standard --}}
<x-wirestrap::autocomplete
wire:model="city"
wire-options="getCities"
label="City"
icon="bi-geo-alt"
/>
{{-- Floating label --}}
<x-wirestrap::autocomplete ... floating />
Icon prop
The icon prop accepts any class string from your preferred icon library,
or an array of attributes for full control. Custom icon components are also supported,
see icon configuration.
Multiple
Add multiple to enable tag mode. wire:model must
bind to an array property. Tags are synced via
$wire.$set() rather than through the input directly, so
wire:model.live has no effect here. Use the live
prop instead to trigger a Livewire request on each tag change.
Keyboard: Enter, Tab, or , to add a tag. Backspace on an empty input removes the last tag.
public array $tags = [];
<x-wirestrap::autocomplete
...
wire:model="tags"
wire-options="getTags"
multiple
/>
Add live to sync each tag change to Livewire immediately.
Without it, tags are deferred until the next Livewire request.
<x-wirestrap::autocomplete ... live />
Reactive list
Use wire-options-watch to invalidate the cache when a Livewire
property changes. The list reloads on the next focus, or immediately if the
dropdown is already open. To force a reload imperatively, use
$wirestrap.autocomplete.refresh(id).
<x-wirestrap::select
...
wire:model="category"
wire-options="getCategories"
/>
<x-wirestrap::autocomplete
...
wire:model="item"
wire-options="getItems"
wire-options-watch="category"
/>
Disabled
<x-wirestrap::autocomplete ... disabled />
Validation
The component checks $errors for the wire:model
key and applies the invalid state if found. Try submitting without typing
a city.
{{-- Suppress both the invalid class and the error message --}}
<x-wirestrap::autocomplete ... :has-validation="false" />
{{-- Keep the invalid class, hide the error message --}}
<x-wirestrap::autocomplete ... :has-validation-message="false" />
In multiple mode, individual invalid tags are highlighted. Enter any value that is not a valid email address to trigger a per-tag error.
Props
Global configuration
Most prop defaults can be overridden globally via config/wirestrap.php.
x-wirestrap::autocomplete
| Prop | Type | Default | Description |
|---|---|---|---|
id |
string|null |
null |
Input id. Auto-resolved from wire:model when omitted. |
label |
ComponentSlot|string|null |
null |
Label text or slot content. No label element is rendered when null. |
wire-options |
string|null |
null |
Livewire method name returning list<string>. Called once on first focus and cached client-side. |
wire-options-watch |
string|null |
null |
Livewire property to watch. Invalidates the cache on change; reloads on next focus or immediately if open. Requires wire-options. |
icon |
string|array |
null |
Icon identifier forwarded to the configured icon component. |
icon-placement |
string |
'start' |
Icon position: start or end. |
placeholder |
string|null |
null |
Placeholder text. Forced to a space in floating mode. |
floating |
bool |
false |
Use floating label layout. |
multiple |
bool |
false |
Enable tag mode. wire:model must bind to an array property. |
live |
bool |
false |
In multiple mode, sync to Livewire on each tag change instead of deferring. |
disabled |
bool |
false |
Disable the component. |
has-validation-message |
bool |
config |
Render the error message below the field. |
has-validation |
bool |
config |
Apply the invalid class when the wire:model key has an error. |
default-attributes |
array |
config |
Default HTML attributes merged onto the input element. |
dropdown-offset |
int |
config |
Y-axis offset in pixels between the trigger and the dropdown. |
|
No results found
|
|||
$wirestrap.autocomplete
| Method | Type | Default | Description |
|---|---|---|---|
$wirestrap.autocomplete.refresh(id) |
-- |
-- |
Invalidate the cached list and call wire-options immediately. id is the input id (auto-resolved from wire:model when omitted). |
|
No results found
|
|||