Skip to content

Switch

Toggle one persistent setting with an immediate state change.

Usage

Notifications

Toggle deployment notifications with one immediate action.

Toggle deployment notifications with one immediate action.

On

Start on and expose the active state without changing the control label.

Start on and expose the active state without changing the control label.

Controlled

Let the parent own the current value and apply accepted changes back to the component.

Let the parent own the current value and apply accepted changes back to the component.

API

Vue package: @sectile/vue/switch

Components
  • SwitchRoot
  • SwitchThumb

Props

SwitchRootProps

as

Element or component rendered for this part.

asChild

Whether to merge this part into its single child instead of rendering a wrapper.

defaultValue

Initial value used when the component owns its state.

disabled

Whether interaction is unavailable.

form

ID of the native form associated with the control.

modelValue

Current value when state is controlled by the parent.

name

Name used for native form submission.

readonly

Whether the value can be inspected but not changed.

required

Whether the control must contain a valid value before submission.

value

Current value exposed by this contract.

SwitchThumbProps

as

Element or component rendered for this part.

asChild

Whether to merge this part into its single child instead of rendering a wrapper.

Slots

SwitchSlotProps

checked

Whether the control is checked.

disabled

Whether interaction is unavailable.

readonly

Whether the value can be inspected but not changed.

Events

SwitchRoot

update:modelValue

Emitted when the component requests a new controlled value.

Other types

SwitchValueChangeHandler

ts
type SwitchValueChangeHandler = (value: boolean) => void

Parts

Shared scope: [data-scope="switch"]. Combine it with a part selector to keep styles local to this component.

PartSelectorRoleExtra attributes
root[data-part="root"]Defines the component boundary and owns its composed parts.
thumb[data-part="thumb"]Controls one value along the track.

Keyboard interaction

KeyBehavior
SpaceToggle the current value.
TabMove through the normal document focus order.

Accessibility

The root exposes switch semantics and keeps checked, disabled, and readonly states distinct.

See the corresponding WAI-ARIA pattern for the host accessibility contract.

Released under the MIT License.