v0.0.2
Demos (demo panel, opens in a new tab)

Select

A labeled select box that takes its options from an array or from the slot.

zb:select zubazar/ui · free (MIT)

Basic usage

Basic usage: view
BLADE

Pass the options with options as a value => text array; placeholder adds a first option that cannot be selected.

blade
<zb:select wire:model="status" label="Status" :options="['1' => 'Active', '0' => 'Inactive']" placeholder="Select…" />
PropValues
optionsvalue => text array
placeholderFirst option that cannot be selected

Options in the slot

Options in the slot: view
BLADE

For grouped options or per-option attributes, write <option> and <optgroup> elements in the slot.

blade
<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

Floating label: view
BLADE

variant="floating" puts the label on the top edge of the box; it matches floating-label text inputs in the same form.

blade
<zb:select name="district" variant="floating" label="District" :options="['kadikoy' => 'Kadıköy', 'besiktas' => 'Beşiktaş', 'uskudar' => 'Üsküdar']" />
PropValues
variantdefault | floating

Hint and validation error

Hint and validation error: view
BLADE

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.

blade
<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>
PropValues
hintHelp text below

With Livewire

BLADE

Use wire:model.live so the value goes to the server as soon as it changes.

blade
<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?

PropTypeDefaultDescription
label—nullLabel; * is added next to it when the required attribute is present
name—nullField name; defaults to the wire:model value
oldbooleantruefalse: 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—nullFirst option that does not appear in the list; shown while the value is null or empty
nullablebooleanfalsetrue: the placeholder becomes an empty option one can pick again ("No brand"); for fields that may stay empty
variant—defaultdefault · floating
hint—nullHelp text below while there is no error; linked to the field with aria-describedby
input-class—nullClasses 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

Events, hooks and details
  • Label, hint and error behavior are the same as zb:input.
  • placeholder shows in the box while the value is null or empty; once the user makes a choice, they cannot go back to this empty value (pass nullable to 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 with aria-describedby (id: the box id + -message), and your own aria-describedby value is kept.
  • For boxes added later by a Livewire update (e.g. a field revealed in an @if block), the selected value is reapplied in the next tick; no extra code is needed.
  • disabled draws the box with a gray background and text.
Zubazar UI · ZubazarDesigned for people.