base-ui-svelte

Toggle

A two-state button that can be either on or off.

View as Markdown

Sizes

Toggle group

API Reference

Props mirror Base UI React where applicable, adapted for Svelte 5. Native HTML attributes for the rendered element are also accepted unless noted.

Toggle

Extends button HTML attributes.

PropertyTypeDefaultDescription
pressedboolean | undefinedControlled pressed state.
defaultPressedbooleanUncontrolled initial pressed state.
onPressedChange((pressed: boolean, event: Event) => void) | undefinedEvent handler called when the pressed state changes.
disabledbooleanfalseWhether the control ignores user interaction.
valuestring | undefinedControlled value.
childrenSnippet<[{ pressed: boolean; disabled: boolean }]>Content rendered inside the part.
Data attributeDescription
data-disabledPresent when the part is disabled.
data-pressedPresent when the toggle is pressed.

ToggleGroup

Extends div HTML attributes.

PropertyTypeDefaultDescription
valuestring[] | undefinedControlled value.
defaultValuestring[]Uncontrolled initial value.
onValueChange((value: string[], event: Event) => void) | undefinedEvent handler called when the value changes.
multipleboolean
disabledbooleanfalseWhether the control ignores user interaction.
orientationToggleGroupOrientation'horizontal'
childrenSnippet<[{ value: string[]; disabled: boolean }]>Content rendered inside the part.
Data attributeDescription
data-disabledPresent when the part is disabled.
data-orientationThe orientation of the component.