Toggle Group
The ToggleGroup component groups a set of toggle buttons for switching between related states or options. It is composed of ToggleGroup.Root and ToggleGroup.Item, and supports single or multiple selection.
Playground
Variations
Controlled and uncontrolled
ToggleGroup.Root can be used as a controlled or uncontrolled component.
- Controlled: pass both
valueand theonChangehandler to fully control the selection from outside. - Uncontrolled with default value: pass
valueto set an initial selection; the component then manages its own state. - Fully uncontrolled: omit
valueand the component manages its state entirely on its own.
With tooltip
Pass tooltipProps on an item to wrap it in a Tooltip. It accepts the title, content, side, and align properties from TooltipProps.
Installation
import { ToggleGroup } from "@harnessio/ui/components";
<ToggleGroup.Root type="multiple" value={["2"]} orientation="vertical" variant="outline" selectedVariant="secondary" onChange={() => {}}> <ToggleGroup.Item value="1" text="Option 1" tooltipProps={{ title: "Title", content: <p>This is a tooltip</p>, }} /> <ToggleGroup.Item value="2" text="Option 2" /> <ToggleGroup.Item value="3" text="Option 3" /></ToggleGroup.Root>;Anatomy
All parts of ToggleGroup can be imported and composed as needed.
<ToggleGroup.Root> <ToggleGroup.Item /></ToggleGroup.Root>ToggleGroup.Rootis the container. It sets the selectiontype, sharedvariant/selectedVariant/size/orientation, and owns the selected value(s).- Each
ToggleGroup.Itemis a pressable button identified by a requiredvalue. It renders an optionalprefixIcon,textlabel, and optionalsuffixIcon. - Selection can be controlled (
value+onChange), seeded (valueonly), or fully uncontrolled.
Best practices
Do
- Use a
ToggleGroupwhen a small set of related options share one context (e.g. view or alignment switches). - Match
typeto intent:singlefor mutually-exclusive choices,multiplewhen several can be active. - Use
unselectablewhen at least one option must always stay selected.
Don’t
- Don’t mix numeric and string item values —
valueis always astring; pass['2'], not[2]. - Don’t overload a group with many items — for long lists use a
Selector menu instead.
Accessibility
Keyboard
- Focus moves between items with the arrow keys (roving tabindex), following the group’s
orientation. Items activate with Space or Enter.
Labeling & semantics
- The group and its items expose their roles and pressed state through the underlying Radix Toggle Group primitive.
- In
iconOnlymode thetextprop becomes each item’saria-label; always provide it so icon-only items have accessible names.
Properties
Root
Prop | Required | Default | Type |
|---|---|---|---|
| children | true | ReactNode | |
| type | false | 'single' | 'single' | 'multiple' |
| value | false | string | string[] | |
| onChange | false | ((value: string) => void) | ((value: string[]) => void) | |
| variant | false | 'outline' | 'outline' | 'ghost' | 'transparent' |
| selectedVariant | false | 'primary' | 'secondary' | |
| size | false | 'md' | 'md' | 'sm' | 'xs' |
| orientation | false | 'horizontal' | 'horizontal' | 'vertical' |
| unselectable | false | false | boolean |
| disabled | false | false | boolean |
| className | false | string |
Item
Prop | Required | Default | Type |
|---|---|---|---|
| value | true | string | |
| text | false | string | |
| iconOnly | false | false | boolean |
| prefixIcon | false | IconName | |
| prefixIconProps | false | Omit<IconPropsV2, 'name'> | |
| suffixIcon | false | IconName | |
| suffixIconProps | false | IconPropsV2 | |
| tooltipProps | false | Pick<TooltipProps, 'title' | 'content' | 'side' | 'align'> | |
| disabled | false | false | boolean |