Segmented
Headless Segmented; covers Adobe React Aria SegmentedControl, shadcn/ui ToggleGroup, Reka UI.
| Package | @vizejs/ui/segmented |
| Maturity | stable |
| Quality gates | behavior contract, mounted dom, type inference, tree shaking, bundle size, ssr, hydration, dom compile, ssr compile, vapor compile |
| Bundle budget | 6,000 B JS gzip / 0 B CSS gzip |
| Own the source | vize lib pull segmented |
| Requires | — |
| Aliases | segmented control, radio group, exclusive toggle |
| Covers | Adobe React Aria SegmentedControl, shadcn/ui ToggleGroup, Reka UI |
Minimal setup
Use a Vue 3.5+ project with Vue SFC compilation configured (see Vite+ integration).
vp install @vizejs/ui
Add the public import below to <script setup lang="ts">. Components provide behavior without styles; the preview uses optional Paper styles.
import { Segmented, SegmentedItem } from "@vizejs/ui/segmented";
Or copy the source into your project with vize lib pull segmented (see Source Distribution).
Try it
This is the basic example maintained with the component source, using the public package imports. The preview adds the optional Paper styles.
Open the interactive example · Styling these components
Copy the example
<!-- Billing period as an exclusive segmented radiogroup. -->
<script setup lang="ts">
import { ref } from "vue";
import { Segmented, SegmentedItem } from "@vizejs/ui/segmented";
const period = ref("day");
</script>
<template>
<div>
<Segmented v-model="period" label="Billing">
<SegmentedItem value="day">Day</SegmentedItem>
<SegmentedItem value="week">Week</SegmentedItem>
<SegmentedItem value="month">Month</SegmentedItem>
</Segmented>
<output>{{ period }}</output>
</div>
</template>
One choice, with keys that wrap
Segmented is an exclusive radiogroup. Items are buttons with role="radio"
and a roving tabindex, so arrow keys work even when the platform does not move
between radios. Left, right, up, and down all move, and the list wraps. Home
and End jump to the enabled ends. A disabled item is skipped.
<script setup lang="ts">
import { ref } from "vue";
import { Segmented, SegmentedItem } from "@vizejs/ui/segmented";
const period = ref("day");
</script>
<template>
<Segmented v-model="period" label="Billing">
<SegmentedItem value="day">Day</SegmentedItem>
<SegmentedItem value="week">Week</SegmentedItem>
<SegmentedItem value="month">Month</SegmentedItem>
</Segmented>
</template>
orientation is a styling hook. It does not change which arrows work.
API
Segmented
Source: src/components/segmented/segmented.vue
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue |
string |
"" |
Selected value. An empty string selects nothing. |
label (required) |
string |
— | Accessible name of the group. |
disabled |
boolean |
false |
Disable every item. |
orientation |
SegmentedOrientation |
"horizontal" |
Visual axis. Keyboard movement does not depend on it. |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue |
[value: string] |
Fired when an item is chosen from a click or a roving key. Carries the item value. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default |
— | Renders SegmentedItem options. |
SegmentedItem
Source: src/components/segmented/segmented-item.vue
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value (required) |
string |
— | Value selected when this item is activated. |
disabled |
boolean |
false |
Skip this item for selection and roving focus. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default |
— | Renders the option label. |
Behavior
Normative state × input → outcome table for src/components/segmented/segmented.vue
and src/components/segmented/segmented-item.vue.
Arrow keys move through enabled radios on both axes and wrap.
Every row is proven by src/components/segmented/tests/behavior.test.ts.
| # | State | Input | Outcome | Proven by |
|---|---|---|---|---|
| G1 | value day | render | radiogroup; day is checked and tabbable; the others are not | checks the selected radio and roves the tab stop |
| G2 | value day | ArrowRight | selects the next item and moves focus | moves and wraps with the arrow keys |
| G3 | value month | ArrowRight | wraps to the first item | moves and wraps with the arrow keys |
| G4 | middle item disabled | ArrowRight from the first | skips the disabled item | skips disabled items |
| G5 | group disabled | ArrowRight | no selection change | a disabled group ignores selection |
| G6 | keyboard helper | Home, End, arrows | indexes wrap inside the enabled list | resolves roving indexes for both axes |