Build · New

Content Switcher

Switches at once between 2 to 4 views or filters of the same content, like Day, Week and Month; exactly one option is selected.

Preview

Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.

Installation

SoonInstalling from the registry opens at launch. Until then the command below is what it will be.
npx shadcn@latest add @ritla/content-switcher

Dependencies it brings: @base-ui/react

Usage

import { ContentSwitcher, ContentSwitcherItem } from "@/components/ui/content-switcher";
<ContentSwitcher aria-label="Period" defaultValue="day">
  <ContentSwitcherItem value="day">Day</ContentSwitcherItem>
  <ContentSwitcherItem value="week">Week</ContentSwitcherItem>
  <ContentSwitcherItem value="month">Month</ContentSwitcherItem>
</ContentSwitcher>

Examples

Sizes

sm 32px (the default), md 40px, lg 48px.

Counts and icons

A count after the label, or icons alone with the label kept for screen readers (showLabel={false}).

Disabled

One option that isn't available yet, then the whole switcher.

API reference

ContentSwitcher

PropTypeDefaultDescription
size"sm" | "md" | "lg""sm"Figma's Size: 32, 40 or 48px.
value / defaultValuestringThe selected option (controlled or initial). Figma selects the first.
onValueChange(value: string) => voidCalled when an option is selected.
dividersbooleantrueFigma's Divider: lines between resting options.
disabledbooleanfalseDisables every option.
aria-labelstringThe choice's name for screen readers ("Period").

ContentSwitcherItem

PropTypeDefaultDescription
valuestringThe option's value in the switcher.
childrenReactNodeFigma's Label: one short word; still the option's name when hidden.
showLabelbooleantrueFigma's Show label. Off leaves the icon alone.
iconLeadingIconComponentFigma's Icon: a 16px icon in the label's color.
badgenumber | stringFigma's Badge and its Count: Gray, Brand on the selected option.
disabledbooleanfalseFigma's State = Disabled for this option.

Accessibility

Keyboard

Keys are written for left-to-right. In right-to-left the arrow keys swap: the one pointing toward the reading direction moves forward.

KeyAction
TabEnters the switcher once, on the selected option; the next press leaves it.
ArrowRightArrowLeftMoves the selection to the next or previous option, wrapping at the ends. Flips in Arabic.
SpaceSelects the focused option.

ARIA

  • A role="radiogroup" named by aria-label; each option is a role="radio" with aria-checked.
  • Selection doesn't rely on color alone: the selected option is filled with white text, the others are outlined.
  • For moving between pages use Tabs; for settings that get saved use Radio buttons.

Arabic and RTL notes

Mirrors

  • The first option sits on the right, and the rounded ends follow.
  • The arrows flip: ArrowLeft is next.
  • Each divider sits on the option's end edge: its left in Arabic.

Does not mirror

  • Chart and table icons stay as drawn.
Numerals
Badge counts follow the numerals setting.
Arabic typography
label-14 Medium in the display family, with a minimum height rather than a fixed one: Arabic lines are taller.
Mixed-direction text
Labels never wrap; keep them to one word of similar length.

All components ›