Switch v0.1.0 Forms

On/off toggle backed by a native role=switch input.

import { Switch } from "latticeui-react";

Examples

States

Show code
<Switch label="Email notifications" defaultChecked />
<Switch label="Public profile" />
<Switch label="Disabled" disabled />

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="switch"][data-part="root"]
controlspan[data-scope="switch"][data-part="control"]
thumbspan[data-scope="switch"][data-part="thumb"]
labelspan[data-scope="switch"][data-part="label"]

Props

PropTypeDefaultDescription
label *ReactNode
checkedboolean
defaultCheckedbooleanfalse
onCheckedChange(checked: boolean) => void
disabledboolean
name / valuenative form props

Accessibility

Roles: switch (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="switch"][data-part="control"] {
  /* your overrides */
}

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