Efniv0.1

Components

Toggle group

A set of toggles that share a value. Use single-select for view type, multi-select for orthogonal options like text formatting.

When to usefor 2–5 options where the choice needs to stay visible — view switcher, alignment, density.

Import

import { ToggleGroup, ToggleGroupItem } from "@ravnhq/efni/toggle-group"

Single (view switcher)

const [view, setView] = useState("table");

<ToggleGroup value={view} onValueChange={setView} variant="outline">
  <ToggleGroupItem value="table"><Icon icon={Table} /> Table</ToggleGroupItem>
  <ToggleGroupItem value="board"><Icon icon={LayoutGrid} /> Board</ToggleGroupItem>
  <ToggleGroupItem value="timeline"><Icon icon={Rows} /> Timeline</ToggleGroupItem>
</ToggleGroup>

Multiple (alignment)

<ToggleGroup value={align} onValueChange={setAlign}>
  <ToggleGroupItem value="left"><Icon icon={AlignLeft} /></ToggleGroupItem>
  <ToggleGroupItem value="center"><Icon icon={AlignCenter} /></ToggleGroupItem>
  <ToggleGroupItem value="right"><Icon icon={AlignRight} /></ToggleGroupItem>
</ToggleGroup>

Grouped (no spacing)

<ToggleGroup variant="outline" spacing={0}>…</ToggleGroup>

Accessibility

KeyAction
ArrowLeft / ArrowRightMove between items.
Enter / SpaceToggle the focused item.
TabEnter / leave the group (single tab-stop).
  • For icon-only items, give each an aria-label.
  • Base UI's ToggleGroup exposes a spacing prop; set spacing={0} for the segmented-control look.

Guidelines

Do
  • Reach for single-select when the choices are mutually exclusive — one view at a time.
  • Use multi-select only when the options are orthogonal (bold + italic + underline).
  • Keep 2–5 items; more belongs in a Select or Tabs.
Don't
  • Don't mix icon + label in some items and icon-only in others — pick one shape.
  • Don't use ToggleGroup for form inputs — use Radio group instead.
  • Don't allow zero-selected in single mode; guard onValueChange or pass a defaultValue.

Props

PropTypeDefaultDescription
valuereadonly Value[]—The pressed state of the toggle group represented by an array of the values of all pressed toggle buttons. This is the controlled counterpart of defaultValue.
defaultValuereadonly Value[]—The pressed state of the toggle group represented by an array of the values of all pressed toggle buttons. This is the uncontrolled counterpart of value.
onValueChange((groupValue: Value[], eventDetails: ToggleGroup.ChangeEventDetails) => void)—Callback fired when the pressed states of the toggle group changes.
variant"default" | "outline""default"Visual style.
spacingnumber2Set spacing={0} for a segmented-control look.
ToggleGroupItem.valueValue—A unique string that identifies the toggle when used inside a toggle group.
ToggleGroupItem.disabledbooleanfalseWhether the component should ignore user interaction.
orientation"horizontal" | "vertical""horizontal"Lay the group out in a row or a column.
…propsToggleGroupPrimitive.Props—Everything ToggleGroup passes to the element it renders.