Emphasis sets the track at rest, as on Toggle, where pressed steps up to strong. normal has a bordered track and subtle a tinted one, each with a solid pill. subtler is the only one without a track, for dense toolbars. Its pill is a soft fill with no border, and the pressed item's icon or label turns strong. The subtler selected state relies on the fill and the icon together and doesn't meet 3:1 on the fill alone, so it's for quiet controls. Use subtle or normal when the state must stand out. The height is the same at every emphasis.
Stretch the track and the segments share the space equally.
<ToggleGroupclassName='w-full'aria-label='Delivery'defaultValue={['mobile']}><ToggleGroup.Itemvalue='mobile'>Mobile ticket</ToggleGroup.Item><ToggleGroup.Itemvalue='print'>Print at home</ToggleGroup.Item></ToggleGroup>
Controlled dashboard range
value is always an array. In single mode it holds one item.
functionSalesRange(){const[range, setRange]=useState(['30d'])const days ={'7d':7,'30d':30,'90d':90}[range[0]]return(<divclassName='grid gap-3'><divclassName='flex flex-wrap items-center justify-between gap-3'><h3className='text-display-ui-5 text-strong'>Tickets sold</h3><ToggleGroupsize='sm'aria-label='Date range'value={range}onValueChange={setRange}><ToggleGroup.Itemvalue='7d'>7 days</ToggleGroup.Item><ToggleGroup.Itemvalue='30d'>30 days</ToggleGroup.Item><ToggleGroup.Itemvalue='90d'>90 days</ToggleGroup.Item></ToggleGroup></div><pclassName='text-sm text-subtle'>Showing the last {days} days at The Paper Lantern, Fitzroy.</p></div>)}render(<SalesRange/>)
Guidelines
Tabs switch panels; a toggle group sets a value. Use Tabs when each choice shows its own content below. Use a toggle group when the choice changes how the same content is filtered or shown, such as a date range or a list or grid view.
It is as tall as a Button of the same size, so it lines up beside buttons in a toolbar or a dashboard header.
Use subtler in a dense toolbar. It has no track, so it sits quietly beside other controls.
Keep it to two to five short options. For more, or for long labels, use Select or RadioGroup.
A single-choice group can't be emptied. Clicking the pressed item leaves it pressed, so a chart always has a range. Set defaultValue so something is chosen from the start.
Use multiple for independent switches such as text styles. For a single on and off switch, use Toggle.
Label the group. Give the root an aria-label, or point aria-labelledby at a visible heading.
Accessibility
Renders role='group'. Each item is a <button> with aria-pressed, so screen readers read which items are on.
Keyboard:Tab moves into the group, onto the pressed item, and out again. Arrow keys move between items (ArrowLeft and ArrowRight, or ArrowUp and ArrowDown when vertical), and Home and End jump to the ends. Space and Enter press the focused item.
A disabled item is skipped by the arrow keys.
Reduced motion: under prefers-reduced-motion: reduce the pill moves without sliding.
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`.
CSS class applied to the element, or a function that
returns a class based on the component's state.
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`.
disabledboolean
Whether the toggle group should ignore user interaction.
Callback fired when the pressed states of the toggle group changes.
loopFocusboolean
Whether to loop keyboard focus back to the first item
when the end of the list is reached while using the arrow keys.
Defaults to true.
multipleboolean
When `false` only one item in the group can be pressed. If any item in
the group becomes pressed, the others will become unpressed.
When `true` multiple items can be pressed.
Sets the colour palette. Inherits from the surrounding intent when unset.
size"sm" | "md" | "lg"
Item size. The whole control matches the height of a Button of the
same size.
Defaults to 'md'.
emphasis"normal" | "subtle" | "subtler"
The track at rest, as on Toggle. `normal` is bordered and `subtle` is
tinted, each with a solid pressed pill. `subtler` has no track and a
soft pill and a strong
label.
Defaults to 'normal'.
direction"horizontal" | "vertical"
Lays the items out in a row or a column. Arrow keys follow it.
Whether the component renders a native `<button>` element when replacing it
via the `render` prop.
Set to `false` if the rendered element is not a button (for example, `<div>`).