Tally UI
Primitives

Switch

A toggle control that switches between on and off states.

Import

import { Switch } from '@tallyui/primitives';

Usage

<Switch.Root checked={enabled} onCheckedChange={setEnabled}>
  <Switch.Thumb />
</Switch.Root>

Components

Switch.Root

The pressable track that manages the on/off state.

PropTypeDefaultDescription
checkedbooleanControlled on/off state
defaultCheckedbooleanfalseInitial state (uncontrolled)
onCheckedChange(checked: boolean) => voidCalled when state changes
disabledbooleanfalsePrevents interaction
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native PressableProps.

Switch.Thumb

The sliding indicator inside the track. Position this with styles based on the checked context.

PropTypeDefaultDescription
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native ViewProps.

Accessibility

  • Role: switch
  • ARIA: aria-checked, aria-disabled
  • Toggles on press

Examples

Controlled

function NotificationToggle() {
  const [enabled, setEnabled] = React.useState(false);

  return (
    <View style={{ flexDirection: 'row', alignItems: 'center', gap: 8 }}>
      <Label.Root nativeID="notifications">Notifications</Label.Root>
      <Switch.Root checked={enabled} onCheckedChange={setEnabled}>
        <Switch.Thumb />
      </Switch.Root>
    </View>
  );
}

On this page