Skip to Content
NarakUI

Toggle Group

A set of two-state buttons that can be toggled on or off, typically used for filtering or switching between different views or options.

Basic

With type="single", one item is on at a time and a sliding indicator marks it.

Multiple selection

With type="multiple", several items can be on at once. The sliding indicator only shows in single mode, so selected items are marked by their text color.

Sizes

Set size on the root: regular (the default) or small. The heights match the Button scale.

Small
Regular

With icons

Use iconStart or iconEnd for icons. Keep children reserved for the item label; icon-only items must provide an accessible label.

Controlled

Pass value and onValueChange to control the selection. In single mode, clicking the selected item passes an empty string; ignore it to keep one item selected.

Showing the last 30 days

Disabled

Set disabled on an item to make it unavailable. Arrow-key navigation skips it.

Installation

pnpm dlx shadcn@latest add @narakui/toggle-group

Add "@narakui": "https://ui.narakcode.dev/r/{name}.json" to components.json, or install directly from https://ui.narakcode.dev/r/toggle-group.json.

Usage

import { ToggleGroup } from '@/components/ui/toggle-group';

// Basic usage
<ToggleGroup.Root defaultValue="option1" aria-label="Toggle group" type="single">
  <ToggleGroup.Item value="option1" aria-label="Option 1">
    Option 1
  </ToggleGroup.Item>
  <ToggleGroup.Item value="option2" aria-label="Option 2">
    Option 2
  </ToggleGroup.Item>
</ToggleGroup.Root>

// Multiple selection
<ToggleGroup.Root defaultValue={['option1']} aria-label="Multiple toggle group" type="multiple">
  <ToggleGroup.Item value="option1" aria-label="Option 1">
    Option 1
  </ToggleGroup.Item>
  <ToggleGroup.Item value="option2" aria-label="Option 2">
    Option 2
  </ToggleGroup.Item>
</ToggleGroup.Root>

// Controlled state
const [value, setValue] = useState('option1');

<ToggleGroup.Root
  value={value}
  onValueChange={setValue}
  aria-label="Controlled toggle group"
  type="single"
>
  <ToggleGroup.Item value="option1" aria-label="Option 1">
    Option 1
  </ToggleGroup.Item>
  <ToggleGroup.Item value="option2" aria-label="Option 2">
    Option 2
  </ToggleGroup.Item>
</ToggleGroup.Root>

ToggleGroup.Root Properties

PropTypeDefaultDescription
type'single' | 'multiple'RequiredThe type of toggle group — single or multiple selection
valuestring | string[]—The current value(s) of the toggle group (controlled)
defaultValuestring | string[]—The default value(s) of the toggle group (uncontrolled)
onValueChange(value: string | string[]) => void—Callback fired when the value changes
size'regular' | 'small''regular'Control height and item typography. Matches the Button scale
orientation'horizontal' | 'vertical''horizontal'Lays the items out in a row or a column
disabledbooleanfalseWhether the toggle group is disabled
aria-labelstring—Accessible label for the toggle group
classNamestring—Additional CSS classes to apply to the toggle group
indicatorClassNamestring—Additional CSS classes for the sliding active indicator

ToggleGroup.Item Properties

PropTypeDefaultDescription
valuestringRequiredThe value of the toggle item
childrenReactNode—Label displayed by the toggle item
aria-labelstring—Accessible label for the toggle item. Required when the item has no children
iconStartToggleGroupIconValue—Icon displayed before the label
iconEndToggleGroupIconValue—Icon displayed after the label
disabledbooleanfalseWhether the toggle item is disabled
classNamestring—Additional CSS classes to apply to the toggle item
labelClassNamestring—Additional CSS classes for the label slot
iconStartClassNamestring—Additional CSS classes for the start icon slot
iconEndClassNamestring—Additional CSS classes for the end icon slot