Skip to content
GitHub ↗

Navigation / React + CSS

Segmented control

A small set of mutually exclusive choices, with a deliberate selected state.

Live preview
View

A clear picture of your project.

Make it yours

Use for two to four related options. The parent should update the associated view or filter. This is a radio group, not an ARIA tab widget.

  1. Use a React project with CSS Modules support, such as Next.js or Vite.
  2. Save the JSX as SegmentedControl.jsx and the CSS as SegmentedControl.module.css in the same folder.
  3. Import SegmentedControl and connect its props to your application. Controlled components need parent state and change handlers.

No third-party component or animation package is required. Use the theme controls to adjust accent, corners, spacing, and type. Copy the Theme CSS into your stylesheet and wrap your components in <div className="tdp-components">. The theme applies to every component inside that wrapper. TDP defaults work without a theme file.

Props

PropTypeUse
labelstringGroup label, rendered as a legend.
optionsstring[]Unique option labels.
valuestringSelected option.
onChangefunctionReceives the selected string.

Accessibility & behavior

Native radios provide arrow-key movement and one selection per group. Each instance gets its own name through useId, and the legend labels the group.

Visible focus styles and reduced-motion support are included. Check labels, contrast, keyboard behavior, and screen-reader output again after adapting the component to your product.

Keep building