Skip to content
iv-ui v0.3.0

Checkbox

since 0.1.0

A binary choice with an optional label and a mixed state.

import { Checkbox } from '@elluzion/iv-ui';

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>
  • Bind checked for two-way state; onchange receives { checked }.
  • Use indeterminate for a parent control that represents a partial selection.
  • Pass label for the visible text; the label is part of the click target.

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>
import { Checkbox } from '@elluzion/iv-ui';

Props

8 props · 3 events · 1 snippets
PropTypeDefaultDescription
checked bindablebooleanfalseChecked state. Bind with bind:checked.
indeterminate booleanfalseRenders the mixed state; useful for “select all”.
disabled booleanfalseDisables interaction and applies the disabled treatment.
required booleanfalseMarks 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

EventHandler typeDescription
onchange(e: CustomEvent<{ checked: boolean }>) => voidCalled with { checked } after the state changes.
onfocus(e: FocusEvent) => voidCalled when the control receives focus.
onblur(e: FocusEvent) => voidCalled when the control loses focus.

The legacy on:name form is accepted for every event.

Snippets

SnippetTypeDescription
childrenSnippetContent rendered inside the component.
KeysAction
TabMoves focus to the checkbox.
SpaceToggles the checked state.
  • A native checkbox input backs the control, so form submission works without extra wiring.
  • indeterminate is applied to the native input and announced as mixed.
  • Focus is drawn on the box and is never removed.
Class hooks
.iv-box.iv-checked.iv-disabled.iv-indeterminate.iv-label.iv-md.iv-native.iv-root.iv-sm
iv-ui
↑ ↓ navigate ↵ open esc close minisearch · 482 records