Forms

Select

A native <select> with its label, description, help text and validation error, filled from an array, a collection, an enum or a query. Use it for picking from a list the browser can show natively; for search or custom option content, use tk:combobox.

$country:
Blade

A "Country" label over a select showing "Brazil", with an empty "---" option first. Choosing United States sets $country to 'us'.

From models or an enum #

A query (or a collection, or a model class) gives one option per row, reading option-value and option-label. A single model instance gives one option, for that record. An enum class gives one option per case, and a single case (Status::Active) one option: the backed value (or the case name) as the option value, and the label() method, when the enum has one, or else the case name as the text.

Blade

Groups and placeholder #

Nested arrays become <optgroup>s labelled by their key. The first option reads "Choose a region" and is selected while no value matches; :placeholder="false" removes it.

Blade

Several values #

A list box four rows tall where Ctrl/Cmd+click picks several options; $tags receives an array of values. The name gets [] appended, so a form sends an array too.

$tags:
Blade

Label, description and help #

The field props build what goes around the control: label, description, help, badge and info.

All dates are shown in this timezone.

You can change it later in your profile.

Blade

Without placeholder #

:placeholder="false" removes the empty first option, so the first real option is selected.

Blade

Sizes #

size scales the control, from xs to 3xl.

Blade

Icon and prefix #

The field control props put content inside the control (icon), and prefix/suffix attach blocks around it.

Protocol
Blade

Options by hand #

Without options, the slot takes tk:select.option tags (or plain <option> and <optgroup> elements). selected picks the initial one.

Blade

Loading state #

loading shows a spinner while the Livewire request runs; with wire:model.live the target is the model.

Blade

Customization #

Classes go to the box when there is an icon; prefixed attributes (select:, option:, placeholder:) reach the inner elements.

Blade

Reference

tk:select
└── tk:select.option ...

tk:select

Prop Type Default Description
options array | Collection | LazyCollection | enum class | enum case | model class | model | query null The options: value as the key and text as the value; in a list, each item is both. Keyed nested arrays become groups.
multiple bool false Lets several options be picked.
rows int 5 With multiple, the height in rows.
placeholder string | false --- The text of the empty first option, translated. false removes it. Not shown with multiple.

Also accepts the field props (label, description, help, value, size...) and the field control props (icon, prepend, loading...). 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: a string, or an array with multiple.

Slots

Slot Description
default <option> and <optgroup> elements written by hand, in place of options.

Prefixes

Prefix Goes to
select: Classes for the <select> itself (select:class).
placeholder: The placeholder option.
option: Each option.
optgroup: Each group.

tk:select.option

Prop Type Default Description
value string null The option value.
label string null The text, translated. The slot takes its place.
selected bool false Selects the option.

Customization

Classes on the tag go to the box around the select (a class alone is enough to render that box), never to the <select>; use select:class for the select itself. Other attributes go to the <select>. Besides the prefixes of the field props and field control props (listed in the Reference above).

blade

Accessibility

A native <select>, with the label linked by for and aria-describedby listing the description, help and error. Keyboard and screen reader support are the browser's own.

Behavior notes

  • Old input from a failed submit selects the options that were chosen.
  • The placeholder is selected whenever the value matches no option, so a stale value shows as empty instead of picking the first option.
  • Option texts from options are translated.