Skip to content
synccn

Toggle Group

Segmented control with a sliding indicator, single or multiple.

Installation

$ pnpm dlx shadcn@latest add @synccn/toggle-group

First time in this project? Connect synccn with one command.

Usage

import { ToggleGroup } from "@/components/ui/toggle-group";<ToggleGroup options={ranges} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

ToggleGroup

Segmented control. type "single" -> value is a string, type "multiple" -> value is an array. options: [{ value, label?, icon?, "aria-label"? }]

  • type
    "single" | "multiple"

    Default "single"

    One choice (string value) or several (array value).

  • value
    string | string[]

    Controlled value: a string, or string[] when type is multiple.

  • defaultValue
    string | string[]

    Initial value when uncontrolled.

  • onValueChange
    ((value: string) => void) | ((value: string[]) => void)

    Called with the new value.

  • optionsrequired
    ToggleGroupOption[]

    Segments.

  • size
    "sm" | "default"

    Default "default"

    Segment height.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseControllable (works controlled or uncontrolled)

npm packages

Keyboard

  • TabMove between segments
  • SpaceorEnterChoose the focused segment

Accessibility

  • Icon-only segments need an aria-label in their option.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: type
  • ARIA attributes: aria-checked, aria-label, aria-pressed
  • Shows a visible focus ring for keyboard users