Park UI

Switch

A form control for toggling between on and off states.

Installation

Usage

Shortcuts

The Switch component also provides a set of shortcuts for common use cases.

SwitchControl

The Switch.Control renders the Switch.Thumb within it by default.

This works:

This might be more concise, if you don't need to customize the thumb:

Examples

Sizes

Use the size prop to change the size of the switch.

Controlled

Use the checked and onCheckedChange prop to control the state of the switch.

Disabled

Use the disabled prop to disable the switch.

Invalid

Use the invalid prop to mark the switch as invalid.

Tooltip

Wrap the Switch.Root with a Tooltip to show a tooltip on hover or focus.

Track Indicator

Use the Switch.Indicator component to display different indicators based on the checked state.

Thumb Indicator

Use the Switch.ThumbIndicator component to add an icon to the switch thumb.

Closed Component

Here's how to setup the switch for a closed component composition.

Props

Root