Toggle Group
Choose one or more pressed buttons from a group.
Demos
Size
Variant
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Single selection moves one shared pressed indicator between items, including vertical groups. Multiple selection keeps a separate pressed fill on each selected item. Reduced motion disables sliding.
Installation
Complete the shared installation. Copy ToggleGroup.vue and index.ts into app/components/ui/toggle-group/.
app/components/ui/toggle-group/ToggleGroup.vue
<script setup lang="ts">
import { Meter as Primitive } from 'akaza-ui'
import { computed, useAttrs } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import { meterVariants, resolveMeterVariants, type MeterProps, type MeterSlots } from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<MeterProps>(), {
min: undefined,
max: undefined,
low: undefined,
high: undefined,
optimum: undefined,
label: undefined,
ariaLabel: undefined,
ariaLabelledby: undefined,
ariaValueText: undefined,
locale: undefined,
formatOptions: undefined,
getAriaValueText: undefined,
getValueLabel: undefined,
ui: undefined,
})
defineSlots<MeterSlots>()
const attrs = useAttrs()
const styles = computed(() => meterVariants(resolveMeterVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'root' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, size: _size, ...native } = props
return native
})
</script>
<template>
<component :is="Primitive" v-bind="{ ...primitiveProps, ...attrs }" :ui="mergedUi">
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof MeterSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
variant | soft, outline | soft |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | ToggleGroupOption[] | required | Toggle items. |
type | "single" | "multiple" | "single" | Selection mode. |
valueKey | string | — | Object key used as item value. Falls back to value, then label. |
labelKey | string | "label" | Object key used as item label. |
descriptionKey | string | "description" | Object key used as item description. |
disabledKey | string | "disabled" | Object key used as item disabled state. |
disabled | boolean | false | Disabled state for the whole group. |
required | boolean | false | Prevents clearing the last selected value. |
name | string | — | Hidden form input name. Multiple mode renders one hidden input per selected value. |
orientation | "horizontal" | "vertical" | "horizontal" | Roving focus direction. |
loop | boolean | true | Arrow navigation wraps. |
rovingFocus | boolean | true | Enables arrow-key roving focus. |
allowEmpty | boolean | true | Allows single mode to clear selected item. |
ariaLabel | string | — | Accessible group label. |
ariaLabelledby | string | — | Accessible group label id. |
ui | ToggleGroupUi | — | Classes for structural parts. |
Slots
| Slot | Props | Description |
|---|---|---|
item | option, value, label, description, isPressed, isDisabled, select | Custom item content. |
Events
| Event | Payload | Description |
|---|---|---|
value-change | (value, details) | Fired before model updates. details.cancel() prevents the update. |
Keyboard
| Key | Behavior |
|---|---|
Enter / Space | Toggle focused item. |
| Arrow keys | Move focus by orientation. |
Home / End | Move focus to first/last enabled item. |