React

Switch

A component that allows turning specific settings and states on or off immediately.

Available since@seed-design/react@0.0.1, @seed-design/css@0.0.1

Installation

npx @seed-design/cli@latest add ui:switch

Props

Switch

Prop

Type

inputProps?React.InputHTMLAttributes<HTMLInputElement> | undefined
rootRef?React.Ref<HTMLLabelElement> | undefined
label?React.ReactNode
disabled?boolean | undefined
invalid?boolean | undefined
required?boolean | undefined
checked?boolean | undefined
defaultChecked?boolean | undefined
onCheckedChange?((checked: boolean) => void) | undefined

Switchmark

Prop

Type

Examples

Sizes

Deprecated Props

size="medium" and size="small" are no longer supported. Use size="32" and size="16" instead.

Tones

Brand

Neutral

Long Label

Disabled

Listening to Value Changes

You can detect switch selection state changes using onCheckedChange.

If you need to use events, you can add event handlers directly to the internal <input> element via inputProps.

Use Cases

Using Switchmark

Switchmark is a switch component excluding the label, which can be used for custom layouts.

Scale Feedback

Switch provides feedback where Switchmark shrinks slightly when pressed.

If you apply Scale Feedback directly to the element wrapping Switchmark, the outer element and Switchmark shrink together, causing the shrinking to appear doubled. Setting --seed-switchmark-feedback-scale to 1 on a parent element of Switchmark allows you to disable only Switchmark's shrinking. Since this variable is inherited, you can set it on an element wrapping the entire Switch.

MyRow.css
.my-row {
  --seed-switchmark-feedback-scale: 1;
}

Table of contents