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.
import {ToggleButtonGroup, ToggleButton} from './ToggleButtonGroup';
<ToggleButtonGroup>
<ToggleButton id="left">Left</ToggleButton>
<ToggleButton id="center">Center</ToggleButton>
<ToggleButton id="right">Right</ToggleButton>
</ToggleButtonGroup>
API
<ToggleButtonGroup>
<ToggleButton>
<SelectionIndicator />
</ToggleButton>
</ToggleButtonGroup>
useToggleGroupState (props: ToggleGroupProps ): ToggleGroupStateuseToggleButtonGroup(
props: AriaToggleButtonGroupProps,
state: ToggleGroupState,
ref: RefObject <HTMLElement | null >
): ToggleButtonGroupAriauseToggleButtonGroupItem(
props: AriaToggleButtonGroupItemOptions <ElementType >,
state: ToggleGroupState,
ref: RefObject <any >
): ToggleButtonAria <HTMLAttributes <any > >ToggleGroupState
Properties
| Name | Type | |
|---|---|---|
isDisabled | boolean | |
Whether all items are disabled. | ||
selectionMode | 'single' | 'multiple' | |
Whether single or multiple selection is enabled. | ||
selectedKeys | Set | |
A set of keys for items that are selected. | ||
Methods
toggleKey | ||
| Toggles the selected state for an item by its key. | ||
setSelected | ||
| Sets whether the given key is selected. | ||
setSelectedKeys | ||
| Replaces the set of selected keys. | ||
AriaToggleButtonGroupProps
| Name | Type | Default |
|---|---|---|
orientation | Orientation | Default: 'horizontal'
|
The orientation of the the toggle button group. | ||
isDisabled | boolean | Default: — |
Whether all items are disabled. | ||
selectionMode | 'single' | 'multiple' | Default: 'single'
|
Whether single or multiple selection is enabled. | ||
selectedKeys | Iterable | Default: — |
The currently selected keys in the collection (controlled). | ||
defaultSelectedKeys | Iterable | Default: — |
The initial selected keys in the collection (uncontrolled). | ||
onSelectionChange | | Default: — |
Handler that is called when the selection changes. | ||
disallowEmptySelection | boolean | Default: — |
Whether the collection allows empty selection. | ||
ToggleButtonGroupAria
| Name | Type | |
|---|---|---|
groupProps | DOMAttributes | |
Props for the toggle button group container. | ||
AriaToggleButtonGroupItemProps
| Name | Type | Default |
|---|---|---|
id | Key | Default: — |
An identifier for the item in the | ||
isDisabled | boolean | Default: — |
Whether the button is disabled. | ||
children | ReactNode | Default: — |
The content to display in the button. | ||
elementType | ElementType | JSXElementConstructor | Default: 'button'
|
The HTML element or React element used to render the button, e.g. 'div', 'a', or | ||