Dashral Pro is on the wayGet 30% off at launch

Dashral

Segmented Control

A row of options where one is picked, like a view switcher. The highlight slides to the choice.

$ pnpm dlx shadcn@latest add https://dashral.com/r/segmented-control.json

Installation

$ pnpm dlx shadcn@latest add https://dashral.com/r/segmented-control.json

Adds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:

components.json
{
  "registries": {
    "@dashral": "https://dashral.com/r/{name}.json"
  }
}

Then add components by name:

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

Usage

example.tsx
import { SegmentedControl } from "@/components/dashral/segmented-control"

<SegmentedControl
  aria-label="Calendar view"
  defaultValue="week"
  options={[
    { value: "day", label: "Day" },
    { value: "week", label: "Week" },
    { value: "month", label: "Month" },
  ]}
/>

Examples

With icons

An option can carry an icon; an icon-only one needs an aria-label.

API reference

SegmentedControl

Also takes every prop of Radix Radio Group(opens in a new tab).

PropTypeDefault
value / defaultValuestring—
onValueChange(value: string) => void

Called with the new value.

—
options(string | { value; label?; icon?; disabled?; "aria-label"? })[]

The segments. An icon-only one needs an aria-label.

—
labelReactNode

Shown above, linked to the control.

—
descriptionReactNode

A hint under the control.

—
errorboolean | ReactNode

true shows the error style; a message also shows under the control.

—
labelActionReactNode

At the end of the label's row, e.g. a “Forgot password?” link or the current value.

—
withAsteriskboolean

Marks the label with an asterisk, e.g. alongside required.

false
classNames{ root, label, description, error, group, item }

Classes for each part.

—
aria-labelstring

Without a label: names the choice, e.g. “Calendar view”.

—

Keyboard

KeysAction
TabMove into the control
←or→Move and pick

Accessibility

  • A radio group, so screen readers say “2 of 4, selected”; label names it through aria-labelledby. For switching panels of content, use Tabs.

Motion

  • The highlight glides to the picked option (--duration-considered, --ease-standard); it just moves with reduced motion.