Tally UI
Primitives

ToggleGroup

A group of toggle buttons where one or multiple can be active.

Import

import { ToggleGroup } from '@tallyui/primitives';

Usage

<ToggleGroup.Root type="single" value={alignment} onValueChange={setAlignment}>
  <ToggleGroup.Item value="left"><AlignLeftIcon /></ToggleGroup.Item>
  <ToggleGroup.Item value="center"><AlignCenterIcon /></ToggleGroup.Item>
  <ToggleGroup.Item value="right"><AlignRightIcon /></ToggleGroup.Item>
</ToggleGroup.Root>

Components

ToggleGroup.Root

Container that manages which items are active. The type prop determines single or multiple selection.

Single mode:

PropTypeDefaultDescription
type'single'requiredOnly one item active at a time
valuestringControlled active value
defaultValuestringInitial value (uncontrolled)
onValueChange(value: string) => voidCalled when value changes
disabledbooleanfalseDisables all items
asChildbooleanfalseMerge props onto child instead of rendering

Multiple mode:

PropTypeDefaultDescription
type'multiple'requiredMultiple items can be active
valuestring[]Controlled active values
defaultValuestring[]Initial values (uncontrolled)
onValueChange(value: string[]) => voidCalled when values change
disabledbooleanfalseDisables all items
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native ViewProps.

ToggleGroup.Item

A pressable toggle within the group.

PropTypeDefaultDescription
valuestringrequiredThe value this item represents
disabledbooleanfalseDisables this item
asChildbooleanfalseMerge props onto child instead of rendering

Plus all React Native PressableProps.

Accessibility

  • Role: group on Root, button on each Item
  • ARIA: aria-pressed on each item, aria-disabled

Examples

Multiple selection

function TextFormatting() {
  const [formats, setFormats] = React.useState<string[]>([]);

  return (
    <ToggleGroup.Root type="multiple" value={formats} onValueChange={setFormats}>
      <ToggleGroup.Item value="bold"><BoldIcon /></ToggleGroup.Item>
      <ToggleGroup.Item value="italic"><ItalicIcon /></ToggleGroup.Item>
      <ToggleGroup.Item value="underline"><UnderlineIcon /></ToggleGroup.Item>
    </ToggleGroup.Root>
  );
}

On this page