Fragiola

API: components

ToggleGroup

Toggles sharing one value, one pressed or several, one tab stop moved through with the arrows, in each framework.

A set of Toggles that share one value: one pressed at a time, or several with multiple (Base UI's ToggleGroup, with the WAI-ARIA APG toolbar pattern's keys: one tab stop, the arrows move between the toggles). ToggleGroup is one component, not a namespace; its toggles come from /toggle.

Text alignment
Gallery

Behaviour

  • Value: the values of the pressed toggles, an array of strings in every mode. Without multiple, a press replaces the value and pressing the pressed toggle empties it; with it, a press adds or removes the toggle's value. Every change reports reason none.
  • Focus: one tab stop (a roving tabindex): the toggle that last had focus while it is enabled, else the first enabled one. The arrows of the orientation (mirrored in RTL when horizontal), Home and End move the focus only, never the value; they skip disabled toggles and wrap with loopFocus.
  • In a Toolbar: the group has no focus of its own. Its toggles are the toolbar's items, the toolbar stays one tab stop, and the group's orientation and loopFocus are the toolbar's.
  • Name: the group is a role="group"; name it with aria-label or aria-labelledby.

Anatomy

partelementdata-primitives-partrole
ToggleGroupdivtoggle-group-rootthe group; holds the value

Its items are Toggles, each with a value.

Usage

import { Toggle } from "@fragiola/primitives-react/toggle";
import { ToggleGroup } from "@fragiola/primitives-react/toggle-group";

<ToggleGroup aria-label="Alignment" defaultValue={["left"]} onValueChange={(value) => console.log(value)}>
    <Toggle value="left">Left</Toggle>
    <Toggle value="center">Center</Toggle>
    <Toggle value="right">Right</Toggle>
</ToggleGroup>;

Props

It also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. Vue binds them as v-model:value and @value-change; Angular as [(value)] and (valueChangeDetails).

ToggleGroup

proptypedefaultdescription
valuestring[]the pressed toggles' values, controlled
defaultValuestring[][]the initial values, uncontrolled
onValueChange(value: string[], details: { reason }) => voidevery change (reason none)
multiplebooleanfalseseveral toggles may be pressed
disabledbooleanfalseevery toggle is disabled
orientation"horizontal" | "vertical""horizontal"which arrow keys move between the toggles; a Toolbar's inside one
loopFocusbooleantruewhether the arrow keys wrap around; a Toolbar's inside one

State and part attributes

partattributes
ToggleGrouprole="group", data-orientation (its own, or its Toolbar's), data-multiple, data-disabled

Its toggles' attributes are on the Toggle page, with the group's roving tabindex.

Keyboard

keyhorizontalvertical
Tabenters at the tab stop; Tab again leaves the groupthe same
next toggleArrowRight (ArrowLeft in RTL)ArrowDown
previous toggleArrowLeft (ArrowRight in RTL)ArrowUp
Home, Endthe first, the last enabled togglethe same
Enter, Spacepresses or releases the focused togglethe same

Exports

entryexports
@fragiola/primitives-react/toggle-groupChangeDetails, ChangeReason, RenderProp, RovingOrientation, ToggleGroup, ToggleGroupProps, ToggleGroupState
@fragiola/primitives-vue/toggle-groupChangeDetails, ChangeReason, RenderSlotProps, RovingOrientation, ToggleGroup, ToggleGroupEmits, ToggleGroupProps, ToggleGroupState
@fragiola/primitives-angular/toggle-groupChangeDetails, ChangeReason, RovingOrientation, ToggleGroup, ToggleGroupState, ValueChangeEvent