Skip to content

Toggle

A focusable checkbox-style toggle control. Integrates with the silvery focus system and responds to Space key to toggle the value.

Import

tsx
import { Toggle } from "silvery"

Props

ToggleProps extends BoxProps (excluding children and onChange).

PropTypeDefaultDescription
valuebooleanrequiredWhether the toggle is on
onChange(value: boolean) => voidrequiredCalled when value changes
labelstring--Label text
isActivebooleanfrom focus systemWhether input is active

All BoxProps layout and style props are also accepted.

Rendering

Renders [x] when on, [ ] when off. When focused, the checkbox indicator is rendered with inverse styling.

Usage

tsx
const [enabled, setEnabled] = useState(false)
<Toggle value={enabled} onChange={setEnabled} label="Dark mode" />

// With explicit active control (bypasses focus system)
<Toggle value={on} onChange={setOn} label="Option" isActive={isEditing} />

See Also

  • Button -- focusable button control
  • Form -- form layout with fields

Released under the MIT License.