Switch

Headless switch primitives for boolean state toggles.

Stable direction
@lattice-ui/switch

Part of the stable direction toward v1.0.

What It Is For

Use Switch for immediate on/off settings where the control communicates a binary system state rather than membership in a list.

It is the simplest boolean primitive in the library and works well for preferences panels and toggles.

Preview size

Live demo is experimental and may contain bugs.

Install

Global CLI command: lattice add switch

Monorepo local script

Use your package manager wrapper when running the local lattice command.

pnpm lattice add switch

npm package: @lattice-ui/switch

Peer dependencies

  • @rbxts/react
  • @rbxts/react-roblox

Public Exports

  • Switch
  • Switch.Root
  • Switch.Thumb

State Model

  • Switch.Root tracks a boolean checked state with controlled and uncontrolled entry points.
  • disabled is enforced at the root, and Switch.Thumb reads that shared state rather than maintaining any local state.
  • There is no indeterminate or mixed state in this package.

Key API

Switch.Root

Use checked, defaultChecked, onCheckedChange, and disabled to connect the control to your settings model.

Switch.Root asChild

Use asChild when you already have a visual host and only need switch semantics attached to it.

Switch.Thumb

Render the moving or highlighted interior affordance as a separate piece without re-implementing checked-state wiring.

Composition Patterns

Preference toggles

Combine a switch with nearby helper text when a setting should apply immediately and remain visually compact.

Custom host surfaces

Use asChild for pill, card, or toolbar-based visuals that still need the same binary state semantics.

Cautions / Limits

  • Use Checkbox instead when the control represents selection or needs an indeterminate state.
  • The package provides state semantics; thumb response should come from motion, while you still own the track and skin.

Decision Guides