Segmented Control

One choice from a few, as joined segments: Day · Week · Month. Built on ui-sdk's SegmentedControl, a radio group underneath: Tab reaches the chosen segment and the arrow keys move the choice. For switching between views with icons, use ViewSwitch.

BetaReady to use. Its API can still change in a minor release; the changelog says when.

import { SegmentedControl, SegmentedControlItem } from "@leap-crm/design-system";

Playground

Change a prop and the component follows. Its code is under Props.

Props

size
disabled

Best practices

When to use it, and the rules that apply in particular places.

GuidancePractice
DoUse it for one choice from a few short options seen side by side, like Day, Week and Month on a calendar, or a range on a report.
DoName it with aria-label, like Range. Tab reaches the chosen segment and the arrow keys move the choice.
DoUse md in forms and dialogs, sm in toolbars and xs in section headers.
DoPut a count after a segment's label as a child when it helps the choice, like open tasks per status.
Don'tUse it to switch between views of the same data, like an opportunities list and board. Use ViewSwitch, which shows the views as icons.
Don'tUse it for more options than fit on one line at narrow widths. Segments don't wrap or shrink; use Select.

Props

SegmentedControl also takes ui-sdk's value, defaultValue, onValueChange, disabled, readOnly, required, name, form, loop and orientation. SegmentedControlItem takes value and disabled.

SegmentedControl

PropTypeDefaultDescription
size"xs" | "sm" | "md""md"md 36 (forms, dialogs) by default · sm 32 (toolbars) · xs 28 (section headers).
classNamestring—Classes added to the root element, merged with its own. Tokens only.

SegmentedControlItem

PropTypeDefaultDescription
childrenReactNode—What it shows inside.
iconReactNode—A leading icon: 16 px at md, 14 px at sm and xs.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

Code

What the playground shows, ready to copy.

import {
  SegmentedControl,
  SegmentedControlItem,
} from "@leap-crm/design-system";

<SegmentedControl defaultValue="Week" aria-label="Range">
  <SegmentedControlItem value="Day">Day</SegmentedControlItem>
  <SegmentedControlItem value="Week">Week</SegmentedControlItem>
  <SegmentedControlItem value="Month">Month</SegmentedControlItem>
</SegmentedControl>

With icons

An icon leads the label: 16 px at md, 14 px at sm and xs.

What the examples share

The imports and the scaffolding the examples above call. The scaffolding lives in this page, not in the library.

import { Calendar, CalendarDays, CalendarRange } from "lucide-react";

import { Fragment } from "react";

import { SegmentedControl, SegmentedControlItem } from "@leap-crm/design-system";

const sizes = ["md", "sm", "xs"] as const;

const ranges = ["Day", "Week", "Month"] as const;

Keyboard

The keys it answers to. Tab moves between components, arrows move within them.

KeysWhat they do
TabLands on the checked item, and the next Tab leaves.
Arrow keysCheck the next item, skipping disabled ones and wrapping.