Skip to content
Harness Design System

Toggle Group

The ToggleGroup component provides a set of toggle buttons that can be used to switch between different states or options. It is composed of subcomponents such as ToggleGroup.Root and ToggleGroup.Item to offer a structured and customizable interface.

Usage

import { ToggleGroup } from '@harnessio/ui/components'
// ...
return (
<ToggleGroup.Root onValueChange={updateControlledInputValue} value={controlledInputValue} type="single">
<ToggleGroup.Item value="1">Option 1</ToggleGroup.Item>
<ToggleGroup.Item value="2">Option 2</ToggleGroup.Item>
<ToggleGroup.Item value="3">Option 3</ToggleGroup.Item>
</ToggleGroup.Root>
)

Anatomy

All parts of the Toggle Group component can be imported and composed as required.

<ToggleGroup.Root variant="compact">
<ToggleGroup.Item value="1">Option 1</ToggleGroup.Item>
<ToggleGroup.Item value="2">Option 2</ToggleGroup.Item>
<ToggleGroup.Item value="3">Option 3</ToggleGroup.Item>
</ToggleGroup.Root>

API Reference

Root

The Root component serves as the main container for all toggle group elements.

PropRequiredDefaultType
childrentrueReactNode
classNamefalsestring
variantfalsedefault'default' | 'outline' | 'compact'
typetrue'single' | 'multiple'
valuefalsestring | string[]
defaultValuefalsestring | string[]
onValueChangefalse(value: string | string[]) => void
disabledfalsefalseboolean
rovingFocusfalsetrueboolean
loopfalsetrueboolean
orientationfalsehorizontal'horizontal' | 'vertical'

Item

The Item component is used to define each toggle button within the group.

<ToggleGroup.Item value="1">Option 1</ToggleGroup.Item>
PropRequiredDefaultType
childrentrueReactNode
classNamefalsestring
valuetruestring
variantfalsedefault'default' | 'outline' | 'compact'
sizefalsedefault'default' | 'sm' | 'lg' | 'xs'
disabledfalsefalseboolean
pressedfalsefalseboolean
defaultPressedfalsefalseboolean
onPressedChangefalse(pressed: boolean) => void