Skip to content
VenusUI
Get started

Segmented Control

A single-choice switcher with a highlight that slides to the selected option.

Preview

Installation

npx shadcn@latest add @venusui/segmented-control

Run this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.

Files added to your project

Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.

  • @/components/ui/segmented-control.tsx

Usage

The code behind the preview above.

segmented-control-demo.tsx

"use client"

import * as React from "react"

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

export default function SegmentedControlDemo() {
  const [view, setView] = React.useState("preview")
  return (
    <div className="flex flex-col items-center gap-4">
      <SegmentedControl
        label="View"
        value={view}
        onValueChange={setView}
        options={[
          { value: "preview", label: "Preview" },
          { value: "code", label: "Code" },
          { value: "docs", label: "Docs" },
        ]}
      />
      <p className="text-sm text-muted-foreground">Selected: {view}</p>
    </div>
  )
}

API reference

PropTypeDefaultDescription
options{ value: string; label: ReactNode; disabled?: boolean }[]—The choices. Required.
labelstring—Accessible name for the group, e.g. "View". Required.
valuestring—Selected value when controlled.
defaultValuestringfirst optionInitial value when uncontrolled.
onValueChange(value: string) => void—Called when the selection changes.
classNamestring—Classes for the group container.

Only the props above.

Requirements

  • The motion package. The CLI installs it.
  • React 19 and Tailwind CSS v4.

Customization

  • Use it controlled (value + onValueChange) to switch views, filters or billing periods.
  • Put icons in label for icon-only segments, and add aria-label text inside so they stay accessible.

Accessibility

  • Uses radio group semantics: Tab focuses the selected option; arrow keys, Home and End change the selection.
  • Disabled options are skipped by the keyboard.
  • The highlight jumps instead of sliding when the user prefers reduced motion.

Troubleshooting

Two controls on a page animate into each other.
Each control has its own layout group, so this shouldn’t happen. If you copied the indicator elsewhere, give it a unique layoutId.
Unknown registry "@venusui"
Your shadcn CLI couldn’t find the namespace in the shadcn registry index. Use the latest CLI (npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.
No components.json found
Run npx shadcn@latest init in your project first.
Loading preview

Animated Tabs

Navigation

Tabs with a sliding underline and fading panels, following the WAI-ARIA tabs pattern.

Loading preview

Dock

Navigation

A row of icons that magnify as the mouse approaches, like the macOS dock.

Loading preview

A CSS-only cube with six content faces that tumbles slowly and pauses on hover.