Toggle

The Toggle component is used to switch between two states, such as on/off.

Usage

Default


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

<Toggle
  checked={checked}
  onChange={setChecked}
  label="Enable setting"
  theme="primary"
/>

Props

Data table
TypeDescription
aria-describedbystringReferences the id of an element that describes the toggle, such as hint text or supporting content.
aria-disabledbooleanExplicitly communicates disabled state to assistive technologies. Normally inferred from `disabled`, but exposed for flexibility.
aria-errormessagestringReferences the id of an element containing an error message.
aria-invalidbooleanIndicates whether the current value is invalid.
aria-labelstringAccessible label for screen readers. Best used when no visible label is rendered.
aria-labelledbystringReferences the id of an element that labels the toggle. Takes precedence over aria-label when provided.
checkedbooleanIndicates whether the toggle is in the "on" (`true`) or "off" (`false`) state.
classNamestringAdditional CSS class names for custom styling.
data-testidstringOptional test ID for testing frameworks.
disabledbooleanIf true, disables user interaction with the toggle.
idstringOptional id for the toggle button. If not provided, one will be generated automatically.
labelstringOptional label to be displayed next to the toggle switch.
onChange(checked: boolean) => voidCallback that is invoked when the toggle's state changes. Receives the new boolean state as an argument.
roundingRoundingTypeRounding applied to the toggle. "none" | "small" | "medium" | "large" | "full"
shadowShadowTypeShadow style applied to the toggle. "none" | "light" | "medium" | "strong" | "intense"
sizeSizeTypeSize variant for the toggle. "xs" | "small" | "medium" | "large" | "xl"
stateStateTypeState of the toggle. "" | "success" | "error" | "warning" | "disabled"
tabIndexnumberOptional tab index for focus management.
themeThemeTypeTheme used for styling the toggle. "primary" | "secondary" | "tertiary" | "quaternary" | "clear"