Switch

A control that indicates whether a setting is on or off.

API reference

Import the component and assemble its parts:

Anatomy

Root

Represents the switch itself. Renders a <button> element and a hidden <input> beside.

PropTypeDefault
name

string

undefined

defaultChecked

boolean

false

checked

boolean

undefined

onCheckedChange

(checked, event) => void

undefined

disabled

boolean

false

readOnly

boolean

false

required

boolean

false

inputRef

React.Ref

undefined

className

string | (state) => string

undefined

render

| React.ReactElement
| (props, state) => React.ReactElement

undefined

Attribute
Description
data-checked
data-unchecked
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused

Thumb

The movable part of the switch that indicates whether the switch is on or off. Renders a <span>.

PropTypeDefault
className

string | (state) => string

undefined

render

| React.ReactElement
| (props, state) => React.ReactElement

undefined

Attribute
Description
data-checked
data-unchecked
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused