Skip to content

Toggle ​

Switches between a few ways of showing the same content, such as the list's view mode.

base-basetogglegroup--defaultOpen in Storybook ↗

When to use ​

  • Choosing one of a few views of the same results: List view, Grid view, Table view.
  • Choosing one display option that applies straight away, such as the card size of the grid view: Large or Compact.

When not to use ​

  • An option that is saved with a form: use a checkbox.
  • Many options, or options with long labels: use a dropdown.
  • An action: use a button. A toggle segment never runs anything; it only changes what is shown.

Anatomy ​

  1. Group: one capsule with a --color-border-default border, --radius-input corners and a --color-surface fill. The segments sit side by side without gaps.
  2. Segment: a button --view-switch-size high. An icon segment is square; a text segment has --view-switch-text-pad on each side and a bold --text-ui label.
  3. Active segment: --color-accent-wash fill with --color-accent-ink icon or text. Inactive segments use --color-text-secondary.
  4. Tooltip (icon segments): the segment's label, shown under it on hover and focus.

Variants ​

VariantWhereSegment content
Icon segmentsthe view-mode switch in the list toolbaran icon, named by its label (Grid view)
Text segmentsthe card-size switch next to it, in grid viewa short visible label (Large, Compact)
Single icon toggle—one square icon button that swaps its icon when on
base-basetogglegroup--text-segmentsOpen in Storybook ↗

Exactly one segment of a group is on. Turning a segment on turns the others off. If the page sets none, the first segment turns on. The view-mode switch only shows the views the entity type allows, in the configured order.

States ​

StateWhat you seeTrigger
Offno fill, secondary ink—
Hover (off)--color-surface-row-hover fill; icon segments show their tooltippointer
Onaccent wash fill, accent inkclick, Enter or Space
Focus--focus-ring-width ring in --color-focus-ring on the segmentkeyboard
base-basetogglegroup--statesOpen in Storybook ↗

Segments have no disabled state.

Keyboard & accessibility ​

KeyAction
Tab / Shift+Tabmoves to the next or previous segment; each segment is its own stop
Enter / Spaceturns the focused segment on
  • The group is a role="group" with an aria-label: View for the view mode switch, Card size for the card-size switch.
  • Each segment is a native <button> with aria-pressed, so the segment that is on is announced as pressed.
  • Icon segments need a label: it becomes the segment's aria-label and its tooltip.
  • Arrow keys do not move between segments.
  • The focus ring is cut off at the top and bottom edge of the group, so only its sides show.
  • The single icon toggle is not a button: Tab does not reach it and it has no accessible name. Use a group or a button instead.

Content ​

  • Label each segment with what it shows, in sentence case: Grid view, Compact.
  • Text segments hold one short word; longer choices belong in a dropdown.
  • Name the group after the choice, not the control: Card size, not Size toggle.
  • Translation keys: library.view-mode, library.view-modes.* and library.grid-size.*.

Button · Checkbox · Tooltip · Icons · Accessibility

Powered by Elody - Open Source Semantic Data Platform