Oddmash UI
All components

Toggle Group

Group toggle buttons for related settings.

Usage

Use single mode for a view choice and multiple mode for independent options. Empty selection is null in single mode and [] in multiple mode. Item values must be unique within each group.

Accessibility

Name the group and icon-only buttons. Tab enters the group once. Use Left and Right in horizontal groups, and Up and Down in vertical groups. Navigation wraps and skips disabled buttons. Home and End move to the edges. Space or Enter toggles the focused button.

PropertyTypeDefault
typesingle | multipleRequired
value / defaultValue (group)string | null (single), readonly string[] (multiple)null / []
onValueChange(value: string | null) => void (single), (value: string[]) => void (multiple)None
orientationhorizontal | verticalhorizontal
disabled (group or item)booleanfalse
value (item)stringRequired
const Example = () => {
  const [view, setView] = useState<string | null>('grid');
  return (
    <>
      <ToggleGroup aria-label="View mode" type="single" value={view} onValueChange={setView}>
        <ToggleGroupItem value="grid">Grid view</ToggleGroupItem>
        <ToggleGroupItem value="compact" disabled>Compact view</ToggleGroupItem>
        <ToggleGroupItem value="list">List view</ToggleGroupItem>
      </ToggleGroup>
      <ToggleGroup aria-label="Text formatting" type="multiple" defaultValue={['bold']}>
        <ToggleGroupItem value="bold">Bold</ToggleGroupItem>
        <ToggleGroupItem value="italic">Italic</ToggleGroupItem>
      </ToggleGroup>
    </>
  );
};

Interactive documentation