zalify-ui

Switch

A form input component for toggling between on and off states.

React

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.

React

Controlled

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

React

Disabled

Use the disabled prop to disable the switch.

React

Invalid

Use the invalid prop to mark the switch as invalid.

React

Tooltip

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

React

Track Indicator

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

React

Thumb Indicator

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

React

Closed Component

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

Props

Root