Select
A labeled select box that takes its options from an array or from the slot.
zb:select zubazar/ui · free (MIT)
Basic usage
Pass the options with options as a value => text array; placeholder adds a first option that cannot be selected.
<zb:select wire:model="status" label="Status" :options="['1' => 'Active', '0' => 'Inactive']" placeholder="Select…" />
| Prop | Values |
|---|---|
options | value => text array |
placeholder | First option that cannot be selected |
Options in the slot
For grouped options or per-option attributes, write <option> and <optgroup> elements in the slot.
<zb:select name="payment_method" label="Payment method">
<optgroup label="Card payment">
<option value="credit_card">Credit card</option>
<option value="debit_card">Debit card</option>
</optgroup>
<optgroup label="Other">
<option value="bank_transfer">Bank transfer</option>
</optgroup>
</zb:select>
Floating label
variant="floating" puts the label on the top edge of the box; it matches floating-label text inputs in the same form.
<zb:select name="district" variant="floating" label="District" :options="['kadikoy' => 'Kadıköy', 'besiktas' => 'Beşiktaş', 'uskudar' => 'Üsküdar']" />
| Prop | Values |
|---|---|
variant | default | floating |
Hint and validation error
hint shows help text below; if there is an error for the field's name, the message replaces the hint and the border turns red.
<div class="space-y-4">
<zb:select wire:model="customer_group" label="Customer group" :options="['retail' => 'Retail', 'wholesale' => 'Wholesale']" hint="The price list applied to the customer." />
<zb:select wire:model="carrier_id" label="Carrier" required :options="['1' => 'Swift Cargo', '2' => 'Express Courier']" placeholder="Select…" />
</div>
| Prop | Values |
|---|---|
hint | Help text below |
With Livewire
Use wire:model.live so the value goes to the server as soon as it changes.
<zb:select wire:model.live="district_id" label="District" :options="$districts" placeholder="Select…" />
@if ($district_id)
<zb:select wire:model="neighborhood_id" label="Neighborhood" :options="$neighborhoods" placeholder="Select…" />
@endif
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
label | — | null | Label; * is added next to it when the required attribute is present |
name | — | null | Field name; defaults to the wire:model value |
old | boolean | true | false: never the value a failed validation sent back (old()), only value; several forms with fields of the same name (an address list) don't fill each other |
options | — | [] | value => text; listed after the options in the slot |
placeholder | — | null | First option that does not appear in the list; shown while the value is null or empty |
nullable | boolean | false | true: the placeholder becomes an empty option one can pick again ("No brand"); for fields that may stay empty |
variant | — | default | default · floating |
hint | — | null | Help text below while there is no error; linked to the field with aria-describedby |
input-class | — | null | Classes of the <select> element itself; class places the whole field |
(attributes) | — | — | Layout attributes such as class, style, x-show and wire:key go on the outer element; wire:model, required, disabled, id, aria-*, data-* … go straight to the <select> element |
Slots: default (<option> and <optgroup> elements)
Developer notes
- Label, hint and error behavior are the same as
zb:input. placeholdershows in the box while the value isnullor empty; once the user makes a choice, they cannot go back to this empty value (passnullableto allow it).- Since a select box always shows a value, the floating label always stays at the top and turns the primary color on focus.
- A box with an error gets
aria-invalid="true"; the hint or message is linked to the box witharia-describedby(id: the box id +-message), and your ownaria-describedbyvalue is kept. - For boxes added later by a Livewire update (e.g. a field revealed in an
@ifblock), the selected value is reapplied in the next tick; no extra code is needed. disableddraws the box with a gray background and text.