Ballmac UI home

Segmented Control

A macOS segmented control: mutually exclusive options with a selected pill that springs between segments and hairline dividers between unselected ones. A Radix radio group underneath.

Calendar

Sep 27 – Oct 3

Appearance

Follow the system or pick one.

View

How files are listed.

Sidebar icon size

Installation

$ pnpm dlx shadcn@latest add @ballmac/segmented-control

Usage

import { SegmentedControl, SegmentedControlItem } from "@/components/ballmac/segmented-control"

The full example is in the Code tab above.

API reference

PropTypeDefault
value

Selected value (controlled).

string—
defaultValue

Initially selected value when uncontrolled. Defaults to the first item.

string—
onValueChange

Called with the newly selected value.

(value: string) => void—
fullWidth

Stretch to the container width with equal segments.

booleanfalse
size"sm" | "default" | "lg""default"

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
TabFocuses the selected segment (one tab stop)
ArrowLeft / ArrowRightMoves to and selects the previous or next segment, wrapping
SpaceSelects the focused segment

Use with AI

<SegmentedControl aria-label value|defaultValue onValueChange size><SegmentedControlItem value>Label</SegmentedControlItem>…</SegmentedControl>. Exactly one segment is always selected. Icon-only items need aria-label; fullWidth stretches segments equally. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Segmented Control (@ballmac/segmented-control) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Switching a view mode or range (Day / Week / Month, List / Grid)
  • A short, always-visible choice in settings (Light / Dark / Auto)
  • Filtering one list by a few exclusive categories

Not for

  • Switching between panels of content with their own semantics (use tabs)
  • More than about five options or long labels (use select)
  • Options that can be combined (use checkboxes or a toggle group)

Registry JSON: https://ui.ballmac.com/r/segmented-control.json

Credits

Free to use in personal and commercial projects.