Components
Checkbox
Base UI checkboxes with token styling, labels, sizes, and an indeterminate state.
Checkbox is a Base UI checkbox with token styling and an optional label. It supports controlled and
uncontrolled usage, native form submission, and an indeterminate state.
Import it from @orkest/ui/client because it uses Base UI client state and interactions.
Live preview#
import { Stack } from '@orkest/ui';
import { Checkbox } from '@orkest/ui/client';
export function Example() {
return (
<Stack gap={3}>
<Checkbox label="Unchecked" />
<Checkbox label="Checked" defaultChecked />
<Checkbox label="Disabled" disabled />
<Checkbox label="Disabled checked" defaultChecked disabled />
</Stack>
);
}Sizes#
import { Stack } from '@orkest/ui';
import { Checkbox } from '@orkest/ui/client';
export function Example() {
return (
<Stack gap={3}>
<Checkbox size="sm" label="Small" defaultChecked />
<Checkbox size="md" label="Medium" defaultChecked />
<Checkbox size="lg" label="Large" defaultChecked />
</Stack>
);
}Indeterminate#
indeterminate is an independent visual and ARIA state managed by Base UI. It does not change the
checkbox's checked value; update checked yourself after a selection changes.
import { useState } from 'react';
import { Stack } from '@orkest/ui';
import { Checkbox } from '@orkest/ui/client';
const teams = ['Design', 'Engineering', 'Product'];
export function Example() {
const [selected, setSelected] = useState(['Design']);
const allSelected = selected.length === teams.length;
const partiallySelected = selected.length > 0 && !allSelected;
return (
<Stack gap={2}>
<Checkbox
label="All teams"
checked={allSelected}
indeterminate={partiallySelected}
onCheckedChange={() => setSelected(allSelected ? [] : teams)}
/>
{teams.map((team) => (
<Checkbox
key={team}
label={team}
checked={selected.includes(team)}
onCheckedChange={() =>
setSelected((current) =>
current.includes(team)
? current.filter((item) => item !== team)
: [...current, team],
)
}
/>
))}
</Stack>
);
}Props#
| Prop | Type | Default |
|---|---|---|
checked | boolean | — |
| Controlled checked state. | ||
defaultChecked | boolean | — |
| Initial checked state for uncontrolled usage. | ||
onCheckedChange | (checked: boolean, eventDetails) => void | — |
| Called when the checked state changes. | ||
indeterminate | boolean | false |
| Shows the mixed state without changing the checked value. Sets aria-checked="mixed". | ||
disabled | boolean | false |
| Disables the checkbox. | ||
required | boolean | false |
| Requires the checkbox for native form validation. | ||
name | string | — |
| Form field name. | ||
value | string | — |
| Value submitted with the form. | ||
inputRef | Ref<HTMLInputElement> | — |
| Ref to the hidden native input used for form submission. | ||
size | 'sm' | 'md' | 'lg' | 'md' |
| Control and label size. | ||
label | ReactNode | — |
| Label rendered beside the control. | ||
native attributes | Base UI Checkbox Root props | — |
| ARIA attributes, id, name, form, readOnly, style, and ref are forwarded to the root. className styles the label wrapper. | ||
Accessibility#
- Renders a Base UI checkbox with
role="checkbox"and a hidden native input, so Space toggles it andrequiredparticipates in form validation. - The optional
labelis an implicit label. When omitting it, providearia-label, useFieldLabel, or connect an external label through the Base UI field context. indeterminatesetsaria-checked="mixed"and the hidden input's indeterminate state.- Focus is shown on the custom control with
:focus-visible. - Disabled controls are removed from form submission and cannot be toggled.