Toggle Group
A set of two-state buttons that can be toggled on or off.
Preview
Installation
npx sigma-ui@latest add toggle-groupUsage
<script setup lang="ts">
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';
</script>
<template>
<ToggleGroup type="single">
<ToggleGroupItem value="a">
A
</ToggleGroupItem>
<ToggleGroupItem value="b">
B
</ToggleGroupItem>
<ToggleGroupItem value="c">
C
</ToggleGroupItem>
</ToggleGroup>
</template>- With
type="single", one item can be pressed at a time andv-modelis astring. - With
type="multiple", several items can be pressed andv-modelis astring[]. - Set
variantandsizeonToggleGroupto style every item.
Examples
Default
Outline
Single
Small
Large
Disabled
API Reference
ToggleGroup
Props
| Prop | Type | Default |
|---|---|---|
rovingFocusWhen | boolean | - |
disabledWhen | boolean | - |
orientationThe orientation of the component, which determines how focus moves: | DataOrientation | - |
dirThe reading direction of the combobox when applicable. <br> If omitted, inherits globally from | Direction | - |
loopWhen | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
typeDetermines whether a "single" or "multiple" items can be selected at a time. This prop will overwrite the inferred type from | SingleOrMultipleType | - |
modelValueThe controlled value of the active item(s). Use this when you need to control the state of the items. Can be binded with | AcceptableValue | AcceptableValue[] | - |
defaultValueThe default active value of the item(s). Use when you do not need to control the state of the item(s). | AcceptableValue | AcceptableValue[] | - |
variantVisual style applied to every item in the group. | "default" | "outline" | null | - |
sizeSize applied to every item in the group. | "default" | "sm" | "lg" | null | - |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called when the value changes. | [payload: AcceptableValue | AcceptableValue[]] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ToggleGroupItem
Props
| Prop | Type | Default |
|---|---|---|
valuerequiredA string value for the toggle group item. All items within a toggle group should use a unique value. | AcceptableValue | - |
disabledWhen | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
variantVisual style of the item; ignored when the parent group sets a variant. | "default" | "outline" | null | - |
sizeSize of the item; ignored when the parent group sets a size. | "default" | "sm" | "lg" | null | - |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
Reka UI renders each item as a toggle button with aria-pressed and uses a roving tabindex to move focus between the items.
| Key | Description |
|---|---|
| Tab | Moves focus to the pressed item, or to the first item when none is pressed. |
| Space | Toggles the focused item. |
| Enter | Toggles the focused item. |
| ArrowDown | Moves focus to the next item. |
| ArrowRight | Moves focus to the next item. |
| ArrowUp | Moves focus to the previous item. |
| ArrowLeft | Moves focus to the previous item. |
| Home | Moves focus to the first item. |
| End | Moves focus to the last item. |