Skip to Content
zjkm-ui
Components

Segmented Control

Options in a bar with a sliding highlight.

Props
<SegmentedControl label="View" options={["Day", "Week", "Month"]} />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/segmented-control.json
import { SegmentedControl } from "@/components/segmented-control"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

A bar of options with a highlight that slides to the chosen one. Native radios underneath, so arrow keys move the choice.

import { SegmentedControl } from "@/components/segmented-control";

export function ViewPicker() {
  return <SegmentedControl label="View" options={["Day", "Week", "Month"]} onChange={(v) => console.log(v)} />;
}

Props

PropTypeDefaultDescription
labelstringAccessible name.
optionsstring[]The choices.
defaultValuestringthe firstStarting choice.
onChange(value: string) => voidCalled when the choice changes.
classNamestringClasses for the wrapper.

With reduced motion, the highlight jumps instead of sliding.

On this page