Forms
Combobox
A form field that opens a searchable list of options and stores the value of the one picked, or of several with multiple. Use it when the user must choose from a set too long for a plain select; when free text is allowed, use Autocomplete.
The options usually come from options; tk:combobox.option is written when the list is built in the view, or to give an option a badge or other markup.
Nothing to show
A field labelled "Fruit" showing ---. Clicking it opens a list with a search box on top; typing che leaves only Cherry, and Enter or a click picks it: the field shows "Cherry", the list closes and the form sends c.
Bound to Livewire #
The field starts on Banana. Picking Cherry sets $fruit to 'c'; a value set on the server is shown as soon as the update arrives.
-
Apple
-
Banana
-
Cherry
Nothing to show
Picking several #
The chosen options show as badges inside the field, each with a remove button. The list stays open while the user picks: picking Banana sets $fruits to ['a', 'c', 'b'], and picking a chosen option again removes it.
-
Apple
-
Banana
-
Cherry
Nothing to show
Typing in the field #
With trigger="input" the field itself is the search box and there is none inside the list. Focusing it opens the list, typing filters it, and picking an option writes its label in the input. Text that matches nothing is not kept: the input shows the chosen label again when it loses focus.
-
Apple
-
Banana
-
Cherry
Nothing to show
Creating options #
The picked tags show as removable badges inside the field, next to the text being typed. Typing "Rust", which no option has, shows "Create “Rust”" under the list: Enter or a click adds 'Rust' to $tags and calls addTag('Rust'), where the component can save it and add it to $allTags. A tag with no option shows its value as its label.
-
PHP
-
JavaScript
-
Go
Nothing to show
Rendering from data #
Each tk:combobox.option is one option; its value is what is stored and its label is what is shown and searched. An option written in the slot can carry a badge or other markup (badge="New") and be disabled, which keeps it in the list but stops it from being picked.
-
Brazil
-
Germany
-
Japan
-
Portugal
-
United States
Nothing to show
Search without accents #
The search ignores case and accents: sao finds São Paulo.
-
São Paulo
-
Rio de Janeiro
-
Lisbon
-
New York
-
Tokyo
-
Berlin
Nothing to show
Groups and no search #
Keyed nested arrays render a heading before their options. searchable set to false removes the search box for short lists.
-
Apple
-
Banana
-
Carrot
-
Spinach
Fruits
Vegetables
-
Low
-
Normal
-
High
Nothing to show
States and sizes #
disabled keeps the field out of the tab order and readonly stops it from opening; size scales it, and icon and help work as on any field.
-
Europe
-
United States
-
North
-
South
Nothing to show
Badges and disabled options #
An option written in the slot can carry a badge, and disabled keeps it in the list but stops it from being picked.
-
Free
-
Pro
-
Legacy
Nothing to show
Picked event #
picked fires on the tag with { value } when the user picks or clears an option; here it calls Livewire through $wire.
-
Free
-
Pro
-
Team
Nothing to show
Customization #
combobox:class styles the field, and prefixed attributes reach the panel (popover:), the inner listbox (listbox:search:, listbox:no-records:) and each option (option:).
-
English
-
Portuguese
-
Spanish
-
French
Nothing to show
Reference
tk:combobox
└── tk:combobox.option
tk:combobox
| Prop | Type | Default | Description |
|---|---|---|---|
options |
array | Collection | LazyCollection | enum class | enum case | model class | model | query | null |
The options, value as the key and label as the value. A list of plain values uses each value as its own key. Keyed nested arrays render a heading followed by their options. Labels are translated. |
multiple |
bool | false |
Lets the user pick several options. The value is then an array. |
creatable |
bool | false |
When no option has exactly the text typed, shows "Create “text”" under the list, as its last option: clicking it, Enter on it (the arrow keys reach it after the last option), or Enter with no option highlighted picks that text as a new value and fires created. |
trigger |
string | null |
input turns the field into a text input that filters the list as the user types. Any other value renders a button-like field with a search box inside the list. |
searchable |
bool | true |
false removes the search box from the list. Ignored with trigger="input". |
Also accepts the field props (label, help, placeholder, size...) and the field control props (icon, loading...), and disabled and readonly. Without a placeholder the empty field shows ---. The attributes option-value, option-label, option-group-label, option-group-children, option-group-children-value and option-group-children-label tell how to read options that are arrays or models. Without them, the value is read from id or value and the text from name, label, title or text. A keyed array of arrays without option-value, option-label or option-group-children is read as groups, so records indexed by id need option-label.
wire:model and x-model bind the value of the picked option, or null when none; with multiple, an array of values. A comma-separated string is also accepted as the initial value of a multiple combobox.
Slots
| Slot | Description |
|---|---|
| default | tk:combobox.option tags. They come before the ones from options when both are given. |
search |
Replaces the search box at the top of the list. Ignored with trigger="input". |
Events
| Event | Detail | When |
|---|---|---|
created |
{ value }, the text |
The user created a value with creatable, right before it is picked. Save the new option there (x-on:created="$wire.addTag($event.detail.value)"). |
picked |
{ value }, the new value: the picked option's value, or with multiple the whole array |
The user picked an option or, with multiple, removed one. Also fired with null when a single value is cleared with the clear button, Backspace or Delete. Not fired when the value changes through wire:model or x-model. |
Prefixes
| Prefix | Goes to |
|---|---|
trigger: |
The field (role="combobox"), or with trigger="input" the box around the badges and the text input. class is not passed this way: use combobox:class. |
search: |
The text input, with trigger="input". |
selected: |
The element around the chosen label or badges. Not with trigger="input". |
selected-label: |
The chosen label, or with multiple the placeholder. Not with trigger="input". |
selected-option: |
Each badge, with multiple. |
selected-clear: |
The clear button, without multiple. |
toggle: |
The arrow button at the end, with trigger="input". |
create: |
The "Create" button, with creatable. |
popover: |
The panel that floats under the field. |
listbox: |
The tk:listbox inside the panel; its own prefixes follow (listbox:search:, listbox:items:, listbox:no-records:). |
option: |
Each option coming from options. |
heading: |
Each group heading coming from options. |
tk:combobox.option
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string | slot | null |
The option text, translated. It is what the search matches and what the field shows once picked. |
value is the value stored when the option is picked; without it, the option's text is used. disabled keeps the option in the list but stops it from being picked. size is inherited from the combobox. Also accepts the element props (badge, iconTrailing, suffix...); icon replaces the check mark of the chosen options (mdi:check by default), shown only while the option is chosen.
Slots
| Slot | Description |
|---|---|
| default | The option content, in place of label. |
Events
picked and created are dispatched on the hidden input that holds the value, the element the tag's attributes go to, and does not bubble: listen on the tag itself.
The change event of the hidden input also reaches the tag whenever the value changes. The events of the list inside (opened, selected, filtered...) are dispatched on an inner element and cannot be heard from the tag.
With Alpine:
Nothing to show
Calling a Livewire action:
Nothing to show
Customization
class goes to the box around the field; the other attributes go to the hidden input that holds the value. combobox:class adds classes to the field itself. To reach another element, prefix the attribute (listed in the Reference above).
The field props prefixes (label:, help:...) also work.
Nothing to show
Accessibility
Follows the WAI-ARIA combobox pattern with a listbox popup. The field has role="combobox", aria-haspopup="listbox", aria-expanded and aria-controls pointing to the list, and is labelled by the field label. The list is a role="listbox", with aria-multiselectable when multiple, of role="option" items carrying aria-selected. While the list is open, focus is in the search box (or stays in the input with trigger="input"), and the active option is exposed through aria-activedescendant. After typing, the number of results is announced ("2 results available", "No records found"); with searchable="false" the active option is exposed on the field itself. Each badge's remove button is named "Remove: " followed by the option label.
| Key | Action |
|---|---|
| Enter, Space, Arrow Down, Arrow Up | On the closed field, opens the list and moves focus to the search box. |
| Arrow Down / Arrow Up | With the list open, moves to the next / previous option, wrapping around. |
| Enter | Picks the active option. Without multiple the list closes and focus returns to the field. |
| Tab, Shift+Tab | With the list open, closes it and moves to the next / previous field; without multiple it first picks the active option. |
| Escape | Closes the list and returns focus to the field. On a closed field it is left alone, so it can close a sidebar or modal around it. |
| Backspace, Delete | On the closed field, clears the value; with multiple, removes the last option. |
With trigger="input", focusing the input, typing in it or pressing an arrow key opens the list, and Backspace in an empty input removes the last option of a multiple combobox. With searchable="false" focus stays on the field, and the arrows, Enter and Space act on the list from there.
Behavior notes
- The search ignores case and accents and matches anywhere in the label:
SAOfinds "São Paulo". The matches keep the order of the options, and the first one that is not disabled becomes the active option. - The search text is kept when the list closes, so reopening shows the same filtered list. Without
multiple, picking an option empties it. - With
trigger="input"the input holds the chosen label and follows the value when it changes on the server or with a form reset; focusing it again lists every option until the text is changed. After a pick or Escape, typing in the input or pressing Arrow Down / Arrow Up opens the list again, as do focusing it anew and the arrow button. - Clearing a single value with the clear button, Backspace or Delete sets a bound Livewire property to
''and dispatchespickedwithnull. - A
disabledfield is out of the tab order and never opens. Areadonlyfield does not open and cannot be cleared; withtrigger="input"it still opens its list on focus, and amultipleone still takes a picked option. - A disabled option cannot be picked, and the arrow keys and the pointer skip it.
- The options are rendered once (the combobox has
wire:ignore, like the other pickers that keep their value in a hidden field): a Livewire update that changesoptionsor the slot does not reach a combobox already on the page. The value still followswire:modelboth ways. To change the options, give the combobox awire:keythat changes with them, so it is rendered again. - Inside a Livewire component, bind the combobox with
wire:model. Unbound (:wire-model="false"), the field showsvaluebut the hidden input starts empty until the user picks something. - Outside Livewire, a
multiplecombobox sends onename[]input per chosen value. A form reset brings back the value the combobox started with. - Each option's value is compared as a string:
1and'1'are the same option.