Alpha

Switch

Switches toggle the state of a single setting on or off.

Preview

size

color

isDisabled

1<v />

Anatomy

1<Switch />

Installation

Note
Please ensure your local environment is fully configured as instructed in the getting started guide.
npm install @rootui/switch

Usage

1import { Switch } from "@rootui/switch";
2
3export default function Page() {
4  return (
5    <Switch />
6  )
7}

API Reference

See the React Aria documentation for more information.

Switch

Prop

Type

Default

defaultSelected
Boolean
false

Whether the Switch should be selected (uncontrolled).

isSelected
Boolean
-

Whether the Switch should be selected (controlled).

isDisabled
Boolean
-

Whether the input is disabled.

isReadOnly
Boolean
false

Whether the input can be selected but not changed by the user.

onChange
(isSelected: boolean) => void
-

Handler that is called when the Switch's selection state changes.

Attribute

Description

data-selected

Whether the switch is selected.

data-hovered

Whether the switch is currently hovered with a mouse.

data-pressed

Whether the switch is currently in a pressed state.

data-focused

Whether the switch is focused, either via a mouse or keyboard.

data-focus-visible

Whether the switch is keyboard focused.

data-disabled

Whether the switch is disabled.

data-readonly

Whether the switch is read only.