Forms
Listbox
A list of options with a search box that filters them as the user types, picked with the mouse or the arrow keys. Each option runs its own click action when chosen. It is the list behind tk:command, tk:autocomplete and tk:combobox; use it directly for an inline picker.
tk:listbox renders the search box, the list and the "no records" message itself; the inner tags are written only to build a list by hand.
Nothing to show
A search input with a magnifier and a clear button, over the three options. Typing "ban" leaves only Banana, highlighted; Enter, or a click, runs its wire:click. With no match, "No records found" shows under the input.
Options from data #
Each entry is a string (the label) or an array of tk:listbox.item props and attributes. With hide-empty the list starts empty and only shows the options that match what is typed.
Nothing to show
Without search #
Only the list, here setting sort in the surrounding Alpine scope. It takes the focus itself: Arrow keys move through the options and Enter or Space picks one.
Nothing to show
Icons, badges and disabled #
Options take the element props (icon, badge, kbd, suffix); disabled keeps an option visible but skipped by the arrows and the pointer.
-
New invoice ⌘N
-
Inbox
-
Customers 1,204
-
Archive
Nothing to show
Sizes #
size scales the search box and the options, from xs to 3xl, and sets the list's maximum height.
-
Apple
-
Banana
-
Apple
-
Banana
-
Apple
-
Banana
Nothing to show
No records message #
no-records changes the message shown when nothing matches; the empty slot replaces it.
-
Ana Souza
-
Bruno Lima
Nothing to show
Selected event #
selected fires on the tag after the option's action ran, with the option in item. clear-on-select empties the search box after a pick.
-
Paid
-
Pending
-
Overdue
Nothing to show
Customization #
Classes go to the wrapper; prefixed attributes reach the search input (search:), the list (items:) and each option from items (item:).
-
Apple
-
Banana
-
Cherry
-
Grape
-
Mango
-
Orange
-
Peach
Nothing to show
Reference
tk:listbox
├── tk:listbox.search
├── tk:listbox.items
│ └── tk:listbox.item
└── tk:listbox.no-records
tk:listbox
| Prop | Type | Default | Description |
|---|---|---|---|
items |
array | Collection | null |
The options, rendered after the slot. Each is a label or an array of tk:listbox.item props and attributes. |
label |
string | null |
The accessible name of the list, translated. |
searchable |
bool | true |
Shows the search box. |
hideEmpty |
bool | false |
Shows no options until something is typed, and never shows the "No records found" message. |
noRecords |
string | false | No records found |
The message when nothing matches. false removes it. |
clearOnSelect |
bool | false |
Empties the search box after an option is picked. |
fuseOptions |
array | null |
Options for the fuzzy search (Fuse.js), such as threshold. |
multiple |
bool | false |
Marks the list as aria-multiselectable. |
size |
string | md |
xs, sm, md, lg, xl, 2xl or 3xl. Also sets the list's maximum height when there is a search box. |
color |
string | null |
The color of the focus ring. |
standalone |
bool | true |
false leaves out the listbox script, for a component that provides its own. |
Slots
| Slot | Description |
|---|---|
| default | The options. |
search |
Replaces the search box. |
empty |
Replaces the "no records" message. |
Events
| Event | Detail | When |
|---|---|---|
ready |
The list is set up. | |
searched |
{ query } |
The user typed in the search box. |
filtered |
{ list, items, filteredItems } |
The visible options changed. |
highlighted |
{ index, item } |
An option was highlighted by the keyboard or the pointer. |
selected |
{ index, item, button } |
An option was picked, after its click action ran. |
Prefixes
| Prefix | Goes to |
|---|---|
search: |
The search input (search:placeholder="Find a fruit"). |
items: |
The <ul role="listbox">. |
item: |
Each option from items. A value set in the item itself wins; classes are added. |
no-records: |
The "no records" message. |
tk:listbox.item
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string | slot | null |
The option text, translated, which the search matches. |
size |
string | inherited | Inherited from the listbox. |
Also accepts the element props (icon, badge, kbd, suffix...). Click attributes (wire:click, x-on:click, href) are the option's action; disabled makes it unselectable.
Slots
| Slot | Description |
|---|---|
| default | The option content, in place of label. |
Prefixes
| Prefix | Goes to |
|---|---|
container: |
The <li role="option"> around the option. |
tk:listbox.items, tk:listbox.search and tk:listbox.no-records
The list (items, size, multiple, color, id), the search input (the props of tk:input, plus controls, the id of the list it filters) and the message (the element props).
Events
Events are dispatched on the tk:listbox element and do not bubble: listen on the tag itself.
With Alpine:
Nothing to show
Calling a Livewire action:
Nothing to show
Customization
Classes and attributes on tk:listbox go to its wrapper. To reach the parts, prefix the attribute (listed in the Reference above).
Nothing to show
Accessibility
Follows the WAI-ARIA listbox pattern, with the search box as a combobox (role="combobox", aria-autocomplete="list", aria-controls pointing to the list). The highlighted option is announced through aria-activedescendant, so the focus stays in the search box. After typing, the number of results is announced ("2 results available", "No records found").
| Key | Action |
|---|---|
| Arrow Down / Arrow Up | Highlights the next / previous option, skipping disabled ones. |
| Home / End | Highlights the first / last option (when the list itself has focus). |
| Enter | Picks the highlighted option. |
| Space | Picks the highlighted option (when the list itself has focus). |
| Tab (in the search box) | Picks the highlighted option and moves on. |
| Escape | Clears the highlight (when there is one; otherwise it is left to the page). |
Behavior notes
- The search matches the option text, ignoring accents and case ("sao" finds "São Paulo"), with fuzzy matching tuned by
fuseOptions. - The matches keep the order of the options, under their group headings. Typing highlights the first match that is not disabled, so Enter picks it right away.
- While an input method (Japanese, Chinese) is composing text, Enter and the arrows belong to it.
- Options added or removed by a Livewire update are picked up, and the current search is applied to them.