Skip to content

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 value and the onChange handler to fully control the selection from outside.
  • Uncontrolled with default value: pass value to set an initial selection; the component then manages its own state.
  • Fully uncontrolled: omit value and 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>;