Skip to content
Klarhimmel UI

Toggle group

npx shadcn add @klarhimmel/toggle-group

Examples

  • Single

  • Multiple

  • View

DetailsAbout, usage, props and more

A row of toggles that belong together: pick one, or any number.

When to use

  • Use for

    View switches, alignment and formatting tools that belong together.

  • Not for

    Moving between pages or panels. Use Tabs.

  • Pairs with

    Icons, Tooltip.

Preview

Aligned left

toggle-group.tsx
import { AlignCenter, AlignLeft } from 'lucide-react';
import { Theme } from '@/components/klarhimmel/theme/style';
import { ToggleGroup, ToggleGroupItem } from '@/components/klarhimmel/ui/toggle-group';

export default function Example() {
  return (
    <Theme theme="brand">
      <ToggleGroup label="Text alignment" type="single" defaultValue="left">
        <ToggleGroupItem value="left" aria-label="Left"><AlignLeft aria-hidden /></ToggleGroupItem>
        <ToggleGroupItem value="center" aria-label="Centre"><AlignCenter aria-hidden /></ToggleGroupItem>
      </ToggleGroup>
    </Theme>
  );
}

Import

Import

import { ToggleGroup, ToggleGroupItem } from '@/components/klarhimmel/ui/toggle-group';
Files
toggle-group.tsx, in components/klarhimmel/ui/. With it: theme, toggle, utils.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

Props

PropTypeDefaultDescription
ToggleGroup.type'single'requiredRequired. Single is a radio group (press the chosen one again to clear it); multiple is a group of pressed buttons.
ToggleGroup.valuestring-A string when single, a list when multiple.
ToggleGroup.defaultValuestring-A string when single, a list when multiple.
ToggleGroup.onValueChange(value: string) => void-A string when single, a list when multiple.
ToggleGroup.labelstringrequiredRequired: names the group ("Text alignment").
ToggleGroup.variant'segmented' | 'chips'-'segmented' (default): buttons on one quiet track, for a view or an alignment. 'chips': separate pills that wrap, for a filter or a set of options (room type, amenities); an on chip is the soft accent with an accent ring, in light and dark alike.
ToggleGroup.classNamestring-Extra classes, merged after the component's own.
ToggleGroup.childrenReactNoderequired
ToggleGroupItem.valuestringrequiredA string when single, a list when multiple.
ToggleGroupItem.disabledboolean-
ToggleGroupItem.childrenReactNoderequired
ToggleGroupItem.classNamestring-Extra classes, merged after the component's own.
ToggleGroupItem.aria-labelstring-

Accessibility

KeyDoes
TabEnters and leaves the group as one stop (single mode)
Right / LeftMoves focus to the next or previous button, wrapping
Home / EndFirst or last button
Enter / SpacePresses the focused button

Single is a radio group; pressing the chosen button again clears it. Multiple is a group of pressed buttons.

Accessibility