Skip to main content

Switch

An animated on/off toggle. Pass a boolean value and an onChange that receives the next boolean. For a single-select group of toggle rows, use Switch.Root and Switch.Item, which internally compose Switch.Label and Switch.Indicator.

On / off toggle​

function NotificationsToggle() {
const [enabled, setEnabled] = useState(false);

return <Switch value={enabled} onChange={setEnabled} label="Notifications" />;
}
PropTypeDefaultDescription
valuebooleanRequired. Whether the toggle is on.
onChange(value: boolean) => voidRequired. Called with the next value when pressed.
labelstringOptional text rendered to the left of the track. The whole row is pressable.
colorTVajraColors'primary'"On" track color.
isDisabledbooleanfalseDisables the toggle and dims it.
size'xs' | 'sm' | 'md' | 'lg''md'Track and thumb size.

Sizes​

Large
<Switch value={value} onChange={setValue} size="lg" label="Large" />

Basic usage​

Wi-Fi
Bluetooth
Airplane mode
function SwitchExample() {
const [value, setValue] = useState('wifi');

return (
<Switch.Root value={value} onChange={setValue}>
<Switch.Item value="wifi" label="Wi-Fi" />
<Switch.Item value="bluetooth" label="Bluetooth" />
<Switch.Item value="airplane" label="Airplane mode" />
</Switch.Root>
);
}

Color and disabled state​

color on Switch.Root sets the "on" track color for every item. Set isDisabled on the root to disable the whole group, or on an individual Switch.Item to disable just that item.

Enabled
Disabled item
<Switch.Root value={value} onChange={setValue} color="warning">
<Switch.Item value="a" label="Enabled" />
<Switch.Item value="b" label="Disabled item" isDisabled />
</Switch.Root>

Props​

Switch.Root Props​

PropTypeDefaultDescription
valuestringRequired. The currently selected item value. Controlled.
onChange(value: string) => voidRequired. Called with the pressed item's value.
colorTVajraColors'primary'Track color token when an item is "on", applied to every item's indicator.
isDisabledbooleanfalseDisables all items unless individually overridden.
size'xs' | 'sm' | 'md' | 'lg''md'Track and thumb size, applied to every item.
childrenReactNodeRequired. Switch.Item elements.

Switch.Item Props​

PropTypeDefaultDescription
valuestringRequired. Unique identifier compared against the root's value.
labelstringOptional label text rendered before the track.
isDisabledbooleanOverrides the root's isDisabled for this item.

Switch.Indicator Props​

PropTypeDefaultDescription
isSelectedbooleanRequired. Whether the track/thumb render in the "on" position.
isDisabledbooleanRequired. Dims the track.
colorTVajraColors'primary'Track color token when selected.

Switch.Label Props​

PropTypeDefaultDescription
labelstringRequired. Text to display.
isDisabledbooleanRequired. Dims the label.