Switch

Loading...

Installation

Install the component via the CLI in one command.

npx shadcn@latest add @intentui/switch

Composed components

When you install this component via the CLI, it automatically loads all composed components, so you don’t need to add them individually.

Manual installation

Use this approach if you prefer to install and wire up the component yourself instead of using the CLI.

npm install react-aria-components tailwind-merge

Anatomy

import { Description } from "@/components/ui/field"
import { SwitchField, Switch } from "@/components/ui/switch"
<>
  <SwitchField value="profileVisible">
    <Switch>Public profile</Switch>
    <Description>Allow others to see your profile.</Description>
  </SwitchField>
  <SwitchField value="searchEngineIndexing">
    <Switch>Search engine indexing</Switch>
    <Description>
      Allow search engines to index your profile.
    </Description>
  </SwitchField>
</>

Examples

Description

You can add a description to the switch by passing the description prop or using the Description component.

Loading...

Controlled

You can manage the switch's state by setting the isSelected prop.

Loading...

Uncontrolled

You can also use the uncontrolled version of the switch.

Loading...

Disabled

A disabled switch cannot be toggled and is non-interactive.

Loading...

Custom layout

Sometimes you may want a switch to use a checkbox-like layout, with the control on the left and the label on the right.

Loading...

Component API

SwitchField

SwitchField extends the React Aria Components <SwitchField> component.

classNamestring

Switch

Switch extends the React Aria Components <SwitchButton> component.

classNamestring

See the React Aria for the full API reference.

Design