Checkbox v0.1.0 Forms

Checkbox built on a visually-hidden native input: native form submission and accessibility for free.

import { Checkbox } from "latticeui-react";

Examples

States

Show code
<Checkbox label="Accept terms and conditions" defaultChecked />
<Checkbox label="Subscribe to newsletter" />
<Checkbox label="Disabled option" disabled />

Controlled

Show code
const [checked, setChecked] = useState(false);

<Checkbox
  label={checked ? "Subscribed" : "Subscribe to updates"}
  checked={checked}
  onCheckedChange={setChecked}
/>

Anatomy

These data-part attributes are a versioned public API - style and test against them; they will not change in a minor release.

PartElementStable selector
rootlabel[data-scope="checkbox"][data-part="root"]
controlspan[data-scope="checkbox"][data-part="control"]
indicatoronly while checkedspan[data-scope="checkbox"][data-part="indicator"]
labelspan[data-scope="checkbox"][data-part="label"]

Props

PropTypeDefaultDescription
label *ReactNode
checkedbooleanControlled value.
defaultCheckedbooleanfalse
onCheckedChange(checked: boolean) => void
disabledboolean
name / value / requirednative form props

Accessibility

Roles: checkbox (native input)

KeyAction
Spacetoggles

Styling

Override styles by targeting the stable selectors below from any unlayered CSS - it always beats the library's @layer latticeui styles, no !important needed.

[data-scope="checkbox"][data-part="control"] {
  /* your overrides */
}

State attributes: data-state=checked|uncheckeddata-disabled