useToggleButtonGroup

Provides the behavior and accessibility implementation for a toggle button group component. Toggle button groups allow users to select one or more options from a group.

Example
ToggleButtonGroup.tsx
ToggleButtonGroup.css
ToggleButton.css
import {ToggleButtonGroup, ToggleButton} from './ToggleButtonGroup';

<ToggleButtonGroup>
  <ToggleButton id="left">Left</ToggleButton>
  <ToggleButton id="center">Center</ToggleButton>
  <ToggleButton id="right">Right</ToggleButton>
</ToggleButtonGroup>

API

ListGridGroupToggle button
<ToggleButtonGroup>
  <ToggleButton>
    <SelectionIndicator />
  </ToggleButton>
</ToggleButtonGroup>
useToggleGroupState(props: ): useToggleButtonGroup( props: , state: , ref: <HTMLElementnull> ): useToggleButtonGroupItem( props: <ElementType>, state: , ref: <any> ): <HTMLAttributes<any>>

ToggleGroupState

Properties

NameType
isDisabledboolean

Whether all items are disabled.

selectionMode'single''multiple'

Whether single or multiple selection is enabled.

selectedKeysSet<Key>

A set of keys for items that are selected.

Methods

toggleKey(key: Key): void
Toggles the selected state for an item by its key.
setSelected(key: Key, isSelected: boolean): void
Sets whether the given key is selected.
setSelectedKeys(keys: Set<Key>): void
Replaces the set of selected keys.

AriaToggleButtonGroupProps

NameTypeDefault
orientationDefault: 'horizontal'

The orientation of the the toggle button group.

isDisabledbooleanDefault:

Whether all items are disabled.

selectionMode'single''multiple'Default: 'single'

Whether single or multiple selection is enabled.

selectedKeysIterable<Key>Default:

The currently selected keys in the collection (controlled).

defaultSelectedKeysIterable<Key>Default:

The initial selected keys in the collection (uncontrolled).

onSelectionChange(keys: Set<Key>) => voidDefault:

Handler that is called when the selection changes.

disallowEmptySelectionbooleanDefault:

Whether the collection allows empty selection.

ToggleButtonGroupAria

NameType
groupPropsDOMAttributes

Props for the toggle button group container.

AriaToggleButtonGroupItemProps

NameTypeDefault
idKeyDefault:

An identifier for the item in the selectedKeys of a ToggleButtonGroup.

isDisabledbooleanDefault:

Whether the button is disabled.

childrenReactNodeDefault:

The content to display in the button.

elementTypeElementTypeJSXElementConstructor<any>Default: 'button'

The HTML element or React element used to render the button, e.g. 'div', 'a', or RouterLink.