Segmented control
Tabs, filter or nav links on one bordered track, with a sliding pill, a badge note on a segment, an underline variant and an overflow menu.
Installation
pnpm add @heyramzi/ui bits-uiUsage
import { AnimatedTabs, SegmentedFilter } from "@heyramzi/ui/components/segmented";<AnimatedTabs tabs={views} bind:value={tab} ariaLabel="View" />
<SegmentedFilter
options={[
{ value: "all", label: "All" },
{ value: "open", label: "Open", count: 4 },
]}
bind:value={filter}
ariaLabel="Status"
/>Keyboard and accessibility
| Key | Does |
|---|---|
| Arrow Right Arrow Left | Moves to the next or previous segment. AnimatedTabs opens it, SegmentedFilter waits for Space or Enter. |
| Home End | In AnimatedTabs, moves to the first or last segment. |
| Tab | In SegmentedFilter, moves into the strip on the picked segment. The strip is one stop. |
| Space Enter | In SegmentedFilter, picks the focused segment. |
- AnimatedTabs is a tablist with panels. SegmentedFilter is a named group of radio buttons, and the picked one reports checked. SegmentedNav is a nav of links, and the current one reports the page.
- Past the max, the extra segments fold into a More menu. It's a separate Tab stop after the strip, and it takes the picker's keys: arrows, Home, End, Enter and a letter to jump.
- A segment that shows only a mark or icon is named by its label.
- With reduced motion on, the pill fades to the new segment. It doesn't slide.
API reference
AnimatedTabs
tabsrequiredreadonly TabDef<T>[]valuebindableTonValueChange(value: T) => voidplacement"toolbar" | "section" | "inline"- Default
"toolbar" blockboolean- Default
false variant"pill" | "underline"- Default
"pill" ariaLabelstringtoolbarimport("svelte").Snippetleadimport("svelte").SnippetlistWrapperClassstringhideSingleboolean- Default
false maxnumber- Default
SEGMENT_MAX moreLabelstringrefbindableHTMLElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
Tabs.Rootfrombits-uiexceptonValueChange, value
| Prop | Type | Default |
|---|---|---|
tabs required | readonly TabDef<T>[] | |
value bindable | T | |
onValueChange | (value: T) => void | |
placement | "toolbar" | "section" | "inline" | "toolbar" |
block | boolean | false |
variant | "pill" | "underline" | "pill" |
ariaLabel | string | |
toolbar | import("svelte").Snippet | |
lead | import("svelte").Snippet | |
listWrapperClass | string | |
hideSingle | boolean | false |
max | number | SEGMENT_MAX |
moreLabel | string | |
ref bindable | HTMLElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of Tabs.Root from bits-ui except onValueChange, value | |
SegmentedFilter
optionsrequiredreadonly TabDef<T>[]valuerequired bindableTonValueChange(value: T) => voidcountsPartial<Record<T, number>>ariaLabelrequiredstringblockboolean- Default
true - Fill the row rather than sit at its natural width. On for the list-page filter strip, off for a segment sitting in a toolbar beside others.
maxnumber | "none"- Default
SEGMENT_MAX - Objects the row may draw before its tail becomes a menu. See `collapse.ts`. `"none"` never folds.
moreLabelstring- What the menu segment says. Translate at the call site.
iconOnlyboolean- Default
false - An option with an `image` or `icon` draws the mark alone; its label moves to `aria-label` and the title. For a cramped toolbar of well-known brand marks.
classstring
| Prop | Type | Default |
|---|---|---|
options required | readonly TabDef<T>[] | |
value required bindable | T | |
onValueChange | (value: T) => void | |
counts | Partial<Record<T, number>> | |
ariaLabel required | string | |
block Fill the row rather than sit at its natural width. On for the list-page filter strip, off for a segment sitting in a toolbar beside others. | boolean | true |
max Objects the row may draw before its tail becomes a menu. See `collapse.ts`. `"none"` never folds. | number | "none" | SEGMENT_MAX |
moreLabel What the menu segment says. Translate at the call site. | string | |
iconOnly An option with an `image` or `icon` draws the mark alone; its label moves to `aria-label` and the title. For a cramped toolbar of well-known brand marks. | boolean | false |
class | string |
SegmentedTrack
fillboolean- Default
false - Fill the row rather than sit at its natural width.
variant"pill" | "underline"- Default
"pill" - `pill`, a grey track with a white thumb that slides, or `underline`, a travelling rule.
classstringchildrenrequiredSnippetafterSnippet- A last segment that isn't an item: today the overflow trigger. It's inside the track but outside the ARIA container, so a `tablist` owns only tabs.
| Prop | Type | Default |
|---|---|---|
fill Fill the row rather than sit at its natural width. | boolean | false |
variant `pill`, a grey track with a white thumb that slides, or `underline`, a travelling rule. | "pill" | "underline" | "pill" |
class | string | |
children required | Snippet | |
after A last segment that isn't an item: today the overflow trigger. It's inside the track but outside the ARIA container, so a `tablist` owns only tabs. | Snippet |
SectionRuns
striprequiredSectionStripclassstring- The host row's own constraints: order, width, container queries.
| Prop | Type | Default |
|---|---|---|
strip required | SectionStrip | |
class The host row's own constraints: order, width, container queries. | string |
SegmentedNav
itemsrequiredreadonly SegmentedNavItem[]currentrequiredstring- The href that is current. Compared after trailing slashes are dropped.
ariaLabelrequiredstringblockboolean- Default
false - Fill the row rather than sit at its natural width.
classstring
| Prop | Type | Default |
|---|---|---|
items required | readonly SegmentedNavItem[] | |
current required The href that is current. Compared after trailing slashes are dropped. | string | |
ariaLabel required | string | |
block Fill the row rather than sit at its natural width. | boolean | false |
class | string |