Provides a default checkbox UI component.
daisyUI's .checkbox class only styles the <input> — it does not wrap it
in a <label>, so a hand-rolled checkbox + adjacent text is easy to get
wrong (clicking the text does nothing). This component always renders the
correct <label><input/><span>...</span></label> structure, plus the
hidden-false fallback input so an unchecked box still submits a value.
Summary
Functions
Renders a checkbox.
Functions
Renders a checkbox.
Examples
<.checkbox field={@form[:remember_me]} label="Keep me logged in" />
<.checkbox
name="settings[allow_registration]"
checked={@settings["allow_registration"] == "true"}
label="Anyone can register"
/>
<%!-- Rich label content (badges, icons) via the default slot —
overrides the `label` attr when given: --%>
<.checkbox name="roles[admin]" checked={...} disabled={owner_role?}>
<.role_badge role={role} size={:sm} /> {role.name}
<:description>Grants full administrative access</:description>
</.checkbox>
<%!-- Locked (but still submitted) while a parent switch is off — use
`wrapper_class`, not `disabled`, so the field's real stored value
keeps submitting instead of collapsing to the hidden "false"
fallback: --%>
<.checkbox
name="settings[oauth_google_enabled]"
checked={@settings["oauth_google_enabled"] == "true"}
label="Google Sign-In"
wrapper_class={!@settings["oauth_enabled"] == "true" && "pointer-events-none"}
/>Attributes
field(Phoenix.HTML.FormField)id(:any) - Defaults tonil.name(:any)label(:string) - Defaults tonil.errors(:list) - Defaults to[].checked(:boolean) - Defaults tonil.disabled(:boolean) - Defaults tofalse.title(:string) - tooltip on the wrapping<label>(covers the box and the text), e.g. explaining why a checkbox is disabled. Defaults tonil.class(:any) - extra classes merged onto the<input type="checkbox">(e.g.checkbox-sm,checkbox-accent). Defaults tonil.wrapper_class(:any) - extra classes merged onto the wrapping<label>(e.g. spacing likemb-3, orpointer-events-noneto lock the whole control — box and text — without excluding it from form submission the waydisabledwould). Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["readonly", "required"].
Slots
inner_block- Rich label content (badges, icons, multiple elements). Overrideslabelwhen given.description- Secondary helper text rendered below the label.