Skip to content

Forms

Switch

Bundle size
5.59 KB
3.0.0

An element that allows you to toggle the Boolean value of a field.

This component is an expansion of the Switch developed and maintained by Radix UI.

Terminal window
pnpm add @inpulse-ui/switch

Contains all the parts of a switch. An input will also render when used within a form to ensure events propagate correctly.

PropTypeDefault ValueRequired
asChildbooleanfalseNo
defaultCheckedbooleanfalseNo
checkedboolean-No
disabledboolean-No
monobooleanfalseNo
namestring-Yes
requiredboolean-No
onChangefunction-No
valuestringonNo
AttributeValue
[data-state]
[data-disabled]Present when disabled

The thumb that is used to visually indicate whether the switch is on or off.

PropTypeDefault ValueRequired
asChildbooleanfalseNo
AttributeValue
[data-state]
[data-disabled]Present when disabled

Instantiate the component within a form context and set an appropriate name attribute, otherwise it won’t be rendered. The name attribute must be unique within the form for proper functionality.

import { Switch } from '@inpulse-ui/switch';
<Form {...useFormProps}>
<Switch name="field" />
</Form>

Use the defaultChecked property to set the default value of the Switch when it is rendered.

By default, the Switch will receive the theme’s primary color when activated. But you can customize this color through CSS classes.

Adopt a monochrome style for the Switch by setting the mono property to true. This style will adapt to the system’s light and dark mode.

A Label applied immediately before or after a Switch, can trigger it.

Use the onChange event to perform an action every time the value of the Switch is changed.

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.