Switch

An element which can be turned “on” or “off”.

Hot Chocolate

Choice: No Whipped Cream

No whipped cream this time—just hot chocolate in its simplest form!


Headless component

The headless component is meant to be used on a button or input element when you need a “on” - “off” semantic.

For accessibility, the label of the button should not change when the state changes. Also, all descendants of a switch have role presentation. Learn more

The active prop is bindable.

With nuts

{
  "aria-checked": "true",
  "value": "",
  "role": "switch"
}

Headless API

PropDefaultTypeDescription
activefalseboolean | (() => boolean)Whether the switch is initially pressed or not. Defaults to false
setActive-(v: boolean) => void
value-string

Follows the WAI-ARIA Switch Pattern