Checkbox
A binary choice with an optional label and a mixed state.
import { Checkbox } from '@elluzion/iv-ui'; 01 Preview
States
Unchecked, checked, mixed, and disabled.
Source· svelte Show Hide
<script lang="ts">
import { Checkbox } from '@elluzion/iv-ui';
let unchecked = $state(false);
let checked = $state(true);
let mixed = $state(false);
</script>
<div class="stack">
<Checkbox label="Unchecked" bind:checked={unchecked} />
<Checkbox label="Checked" bind:checked />
<Checkbox label="Mixed" indeterminate bind:checked={mixed} />
<Checkbox label="Disabled" checked disabled />
</div>
<style>
.stack {
display: flex;
flex-direction: column;
gap: var(--iv_spacing-sm);
}
</style>02 Usage
- Bind
checkedfor two-way state;onchangereceives{ checked }. - Use
indeterminatefor a parent control that represents a partial selection. - Pass
labelfor the visible text; the label is part of the click target.
03 Examples
Sizes
sm and md; md is the default.
Source· svelte Show Hide
<script lang="ts">
import { Checkbox } from '@elluzion/iv-ui';
</script>
<div class="stack">
<Checkbox label="Small" size="sm" checked />
<Checkbox label="Medium" checked />
</div>
<style>
.stack {
display: flex;
flex-direction: column;
gap: var(--iv_spacing-sm);
}
</style>Events
The change event carries { checked } and the bound value stays in sync.
checked false · changes 0
Source· svelte Show Hide
<script lang="ts">
import { Checkbox } from '@elluzion/iv-ui';
let checked = $state(false);
let changes = $state(0);
</script>
<div class="stack">
<Checkbox label="Watch this repository" bind:checked onchange={() => changes++} />
<p class="readout">checked {checked} · changes {changes}</p>
</div>
<style>
.stack {
display: flex;
flex-direction: column;
gap: var(--iv_spacing-sm);
}
.readout {
margin: 0;
font-family: var(--iv_font-mono);
font-size: var(--iv_text-sm);
color: var(--iv_foreground-dim);
}
</style>04 API
import { Checkbox } from '@elluzion/iv-ui';Props
8 props · 3 events · 1 snippets| Prop | Type | Default | Description |
|---|---|---|---|
| checked bindable | boolean | false | Checked state. Bind with bind:checked. |
| indeterminate | boolean | false | Renders the mixed state; useful for “select all”. |
| disabled | boolean | false | Disables interaction and applies the disabled treatment. |
| required | boolean | false | Marks the field as required. |
| label | string | '' | Label text rendered next to the box. |
| name | string | '' | Form field name submitted with the surrounding form. |
| value | string | '' | Value submitted with the form when checked. |
| size | 'sm' | 'md' | 'md' | Control size. |
class, id, style, aria-*, and data-* are forwarded through rest props.
Events
| Event | Handler type | Description |
|---|---|---|
| onchange | (e: CustomEvent<{ checked: boolean }>) => void | Called with { checked } after the state changes. |
| onfocus | (e: FocusEvent) => void | Called when the control receives focus. |
| onblur | (e: FocusEvent) => void | Called when the control loses focus. |
The legacy on:name form is accepted for every event.
Snippets
| Snippet | Type | Description |
|---|---|---|
| children | Snippet | Content rendered inside the component. |
05 Accessibility
| Keys | Action |
|---|---|
| Tab | Moves focus to the checkbox. |
| Space | Toggles the checked state. |
- A native checkbox input backs the control, so form submission works without extra wiring.
indeterminateis applied to the native input and announced as mixed.- Focus is drawn on the box and is never removed.
06 Tokens & CSS hooks
Tokens used
Class hooks
.iv-box.iv-checked.iv-disabled.iv-indeterminate.iv-label.iv-md.iv-native.iv-root.iv-sm