Skip to content

Toggle Button

Keep one action pressed until the same action is invoked again.

Usage

Formatting

Keep a formatting action pressed until the same action is invoked again.

Keep a formatting action pressed until the same action is invoked again.

Alert

Keep an alert-watching action active until the user turns it off.

Keep an alert-watching action active until the user turns it off.

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/toggle-button

Components
  • ToggleButton

Props

ToggleButtonProps

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.

modelValue

Current value when state is controlled by the parent.

readonly

Whether the value can be inspected but not changed.

Slots

ToggleButtonSlotProps

disabled

Whether interaction is unavailable.

pressed

Whether the toggle is pressed.

readonly

Whether the value can be inspected but not changed.

Events

ToggleButton

update:modelValue

Emitted when the component requests a new controlled value.

Other types

ToggleButtonValueChangeHandler

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

Parts

Shared scope: [data-scope="toggle-button"]. 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.

Keyboard interaction

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

Accessibility

The button exposes pressed state and keeps disabled and readonly behavior distinct.

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

Released under the MIT License.