humanonlyweb/ui

Switch

An on/off toggle.

Markdown

Examples

Basic

Copy code

Hint

Like other fields, hint and error show under the label and are read as its description.

A summary every Monday morning.

Copy code

API

PropTypeDefault
disabled

Disables the switch.

booleanfalse
label

Text next to the switch. The default slot overrides it.

string—
size

Size hook, exposed as data-switch-size.

"medium" | "small""medium"
hint

Help text under the switch, announced as its description.

string—
error

true marks it invalid; a string also shows it as the message, replacing the hint.

string | boolean—
name

Form field name: while on, a native form submits value under it.

string—
value

What a native form submits while on, as a checkbox would.

string"on"
id

Id for the switch; generated with useId() when omitted.

string—
modelValue

On or off.

booleanfalse
EventPayload
update:modelValue

v-model:modelValue update.

[value: boolean]
SlotProps
default

Label content, replacing label.

—

Styling

Parts
switchswitch-trackswitch-thumbswitch-labelfield-message
States
data-switch-sizedata-switch-checkeddata-switch-errordata-field-namedata-field-tone

Keyboard

KeysAction
Space / EnterToggle