ToggleSwitch

Use a toggle switch for a boolean setting that takes effect immediately.

import {ToggleSwitch} from '@primer/react-brand'

Examples

Default

Loading

Uncontrolled

defaultChecked sets the initial value. onChange receives the next boolean value, not a native change event.

Loading

Controlled

Loading

Sizes

Loading

Disabled

Loading

Without FormControl

Loading

Visually hidden label with FormControl

Loading

Component Props

NameTypeDefaultDescription
checkedbooleanControlled on/off value.
defaultCheckedbooleanfalseInitial uncontrolled value.
onChange(checked: boolean) => voidCalled once per accepted activation with the next value.
onClickReact.MouseEventHandler<HTMLButtonElement>Activation callback receiving the button event.
disabledbooleanfalseBlocks activation while retaining keyboard focusability.
loadingbooleanfalseDisplays pending feedback and exposes aria-busy without blocking interaction.
size'small' | 'medium''medium'Alternative sizes.
loadingLabelstring'Loading'Localized loading announcement.
loadingLabelDelaynumber2000Announcement delay in milliseconds.
spinnerPosition'start' | 'end''end'Indicator placement beside the switch when no visible FormControl label is available.
aria-labelstringExplicit accessible name matching equivalent visible labeling.
aria-labelledbystringIDs of visible labeling elements.
aria-describedbystringDescription IDs, combined with FormControl and loading descriptions.
aria-invalidReact ARIA attributeValidation state of the switch button.
refReact.Ref<HTMLButtonElement>Ref for the focusable button.
classNamestringClass applied to the component wrapper.
data-testidstringTest ID applied to the component wrapper.

Other standard button attributes, including aria-controls, tabIndex, keyboard handlers, and style, apply to the switch button.