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...

Component API

SwitchField

The SwitchField component toggles a setting on or off.

PropTypeDefault
classNamestring-

Switch

The Switch component renders the switch label.

PropTypeDefault
classNamestring-

See the React Aria for the full API reference.