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

Checkbox and radio

A checkbox (zb:checkbox) and a radio button (zb:radio) in the brand color.

zb:checkbox · zb:radio zubazar/ui · free (MIT)

Checkbox

Checkbox: view
BLADE

Pass the label with label, and checked to have the box checked initially.

blade
<div class="flex flex-col gap-3">
    <zb:checkbox name="email_notification" label="Email notification" checked />
    <zb:checkbox name="sms_notification" label="SMS notification" />
</div>
PropValues
labelText next to the box
checkedtrue | false

Radio button

Radio button: view
BLADE

Give the buttons in one group the same name and each a different value; only one of the group can be selected.

blade
<div class="flex flex-wrap gap-6">
    <zb:radio name="customer_type" value="individual" label="Individual" checked />
    <zb:radio name="customer_type" value="corporate" label="Corporate" />
</div>
PropValues
nameGroup name
valueValue sent when selected
checkedtrue | false

With Livewire

BLADE

Bind a single box to a bool property with wire:model, and several boxes bound to the same property to an array.

blade
<zb:checkbox wire:model="active" label="Active customer" />

<zb:checkbox-group label="Shipping days" name="days">
    <zb:checkbox wire:model="days" value="monday" label="Monday" />
    <zb:checkbox wire:model="days" value="wednesday" label="Wednesday" />
    <zb:checkbox wire:model="days" value="friday" label="Friday" />
</zb:checkbox-group>

<zb:radio wire:model="priority" value="normal" label="Normal" />
<zb:radio wire:model="priority" value="urgent" label="Urgent" />

Groups

Groups: view
BLADE

Gather several boxes under one title with zb:checkbox-group or zb:radio-group; inline lays them side by side.

blade
<div class="grid gap-8 sm:grid-cols-2">
    <zb:checkbox-group label="Categories" name="categories" description="Where the product is listed." required>
        <zb:checkbox name="categories[]" value="audio" label="Audio and headphones" checked />
        <zb:checkbox name="categories[]" value="wearables" label="Wearable technology" />
        <zb:checkbox name="categories[]" value="home" label="Smart home" />
    </zb:checkbox-group>

    <zb:radio-group label="Shipping" name="shipping" inline>
        <zb:radio name="shipping" value="standard" label="Standard" checked />
        <zb:radio name="shipping" value="express" label="Express" />
        <zb:radio name="shipping" value="store" label="Store pickup" />
    </zb:radio-group>
</div>
PropValues
labelThe group's title (legend)
nameThe key of the error message
descriptionThe text under the title
inlineLays the boxes side by side
requiredAdds an asterisk to the title

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
checkbox: label—nullText next to it; the slot is used when not given
checkbox: name—nullField name; defaults to the wire:model value
checkbox: checkedbooleanfalseInitially checked
checkbox: value (attribute)number1Value sent while checked; the id becomes name-value
radio: label—nullText next to it; the slot is used when not given
radio: name—nullGroup name; defaults to the wire:model value
radio: value—nullValue sent when selected; the id becomes name-value
radio: checkedbooleanfalseInitially selected
checkbox / radio: input-class—nullClasses of the box or button itself. class, style, x-show and wire:key go on the outer element; name, wire:model, aria-*, data-* and events on the box
checkbox-group / radio-group: label—nullThe group's title (fieldset legend)
checkbox-group / radio-group: name—nullThe message key; shown once under the boxes (name and name.*)
checkbox-group / radio-group: description—nullThe text under the title
checkbox-group / radio-group: inlinebooleanfalseLays the boxes side by side
checkbox-group / radio-group: requiredbooleanfalseAdds an asterisk to the title and "(required)" for screen readers

Slots: default (label content when label is not given)

Advanced

2 examples

Rich label

Rich label: view
BLADE

Without label, the slot becomes the label; use it for formatted content such as a link. Wrap the content in a single <span> so the gap between it and the box is not broken.

blade
<zb:checkbox name="privacy_consent">
    <span>I have read and accept the <a href="#" class="font-medium text-primary-ink hover:underline">privacy notice</a>.</span>
</zb:checkbox>

Disabled

Disabled: view
BLADE

The disabled attribute goes straight to the box; a disabled element is drawn faded and cannot be clicked. On radio buttons the label turns gray as well.

blade
<div class="flex flex-wrap gap-10">
    <div class="flex flex-col gap-3">
        <zb:checkbox name="auto_backup" label="Automatic backup" checked disabled />
        <zb:checkbox name="bulk_sms" label="Bulk SMS (no permission)" disabled />
    </div>
    <div class="flex flex-col gap-3">
        <zb:radio name="delivery_method" value="shipping" label="Standard shipping" checked />
        <zb:radio name="delivery_method" value="same_day" label="Same-day delivery (not available in this area)" disabled />
    </div>
</div>
PropValues
disabledAttribute

Developer notes

Events, hooks and details
  • The array holds the value values of the checked boxes; for radio buttons the group name comes from wire:model.
  • A single checkbox shows its validation error inside its label, below the text (the root stays the <label>). Boxes in a list and radio buttons only turn red; the group component shows the list's message once.
  • The group's validation message (categories or categories.*) appears once under the boxes; the boxes get a red border.

Accessibility

Keyboard
Both are real <input> elements. Space toggles a checkbox, and arrow keys move between radios that share a name. This is native browser behaviour.
Label
The label is tied to the box with <label for>, so clicking the label toggles it too. The id is built from the name and the value, so boxes in one list get different ids.
Errors and groups
With an error the box gets aria-invalid="true"; a single checkbox also links its message with aria-describedby. zb:checkbox-group and zb:radio-group render a <fieldset> with a <legend>. The group description and message are linked to the fieldset with aria-describedby, and required adds a hidden "(required)" to the legend.
Focus and disabled
Keyboard focus shows an outline around the box (focus-visible). disabled goes to the input as the real attribute.
What you provide
Set the indeterminate property ("some selected") yourself in JavaScript; the component only styles it. Give a box without a label (a table row selector, for example) an aria-label. Give radios the same name or wire:model so they form one group.
Zubazar UI · ZubazarDesigned for people.