Homelogologo
Sponsor

Switch

A control that allows the user to toggle between checked and unchecked states.

Usage

Used to toggle between two states, typically on and off.

import { Switch } from "@elemnts-ui/react"; <Switch.Root> <Switch.Control> <Switch.Thumb /> </Switch.Control> <Switch.Label>Enable notifications</Switch.Label> <Switch.HiddenInput /> </Switch.Root>;

With label

The Switch.Label component is used to provide a descriptive label for the switch, which is essential for accessibility.

Disabled

Set the disabled prop on Switch.Root to make the switch non-interactive.

API Reference

Switch

The root container that manages the switch state.

PropTypeDefault
asChildbooleanfalse
checkedboolean-
disabledboolean-
idsPartial<{ root: string; hiddenInput: string; control: string; label: string; thumb: string }>-
invalidboolean-
labelstring-
namestring-
onCheckedChange(details: CheckedChangeDetails) => void-
readOnlyboolean-
requiredboolean-
valuestring | number"on"

SwitchRootProvider

Provides switch state created with useSwitch to its child components.

PropTypeDefault
valueUseSwitchReturnrequired
asChildbooleanfalse

SwitchLabel

The accessible label for the switch.

PropTypeDefault
asChildbooleanfalse

SwitchControl

The visual track for the switch.

PropTypeDefault
asChildbooleanfalse

SwitchThumb

The visual thumb that slides along the control.

PropTypeDefault
asChildbooleanfalse

SwitchHiddenInput

A hidden native input used for form submission.

PropTypeDefault
asChildbooleanfalse

SwitchContext

Provides the switch API to a render function.

PropTypeDefault
children(value: UseSwitchReturn) => ReactNode-