All components
Chewypixel component

Segmented Control

Mutually exclusive options with a highlight that slides to the selected one.

1,284 gumdrops sold this week

Installation

npx shadcn@latest add https://chewypixel.io/r/segmented-control.json

Usage

"use client";

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

export function RangePicker() {
  const [range, setRange] = useState("week");

  return (
    <SegmentedControl
      value={range}
      onChange={setRange}
      aria-label="Range"
      options={[
        { value: "day", label: "Day" },
        { value: "week", label: "Week" },
        { value: "month", label: "Month" },
      ]}
    />
  );
}

Props

value

The selected value.

string

options

The options in display order. Icon-only options need an ariaLabel.

{ value, label, ariaLabel? }[]

onChange

Called with the new value when the selection changes.

(value) => void

size

The height: 28px for sm, 36px for default.

"sm" | "default" = "sm"

Released under the MIT License.

More components

See them in a real app

These components come from Mochi, our admin dashboard template built with Next.js, shadcn/ui and Motion.