Composite provides a single tab stop on the page and allows navigation through the focusable descendants with arrow keys. This abstract component is based on the WAI-ARIA Composite Role.
Usage
import { Composite } from '@wordpress/components';
<Composite>
<Composite.Group>
<Composite.GroupLabel>Label</Composite.GroupLabel>
<Composite.Item>Item 1</Composite.Item>
<Composite.Item>Item 2</Composite.Item>
</CompositeGroup>
</Composite>
Components
Composite
Renders a composite widget.
Props
activeId: string | null
The current active item id. The active item is the element within the composite widget that has either DOM or virtual focus (in case the virtualFocus prop is enabled).
nullrepresents the base composite element (the one with a composite role). Users will be able to navigate out of it using arrow keys.- If
activeIdis initially set tonull, the base composite element itself will have focus and users will be able to navigate to it using arrow keys. -
Required: no
defaultActiveId: string | null
The composite item id that should be active by default when the composite widget is rendered. If null, the composite element itself will have focus and users will be able to navigate to it using arrow keys. If undefined, the first enabled item will be focused.
- Required: no
setActiveId: ((activeId: string | null | undefined) => void)
A callback that gets called when the activeId state changes.
- Required: no
focusLoop: boolean | ‘horizontal’ | ‘vertical’ | ‘both’
Determines how the focus behaves when the user reaches the end of the composite widget.
On one-dimensional composite widgets:
trueloops from the last item to the first item and vice-versa.horizontalloops only iforientationishorizontalor not set.verticalloops only iforientationisverticalor not set.- If
activeIdis initially set tonull, the composite element will be focused in between the last and first items.
On two-dimensional composite widgets (ie. when using CompositeRow):
trueloops from the last row/column item to the first item in the same row/column and vice-versa. If it’s the last item in the last row, it moves to the first item in the first row and vice-versa.horizontalloops only from the last row item to the first item in the same row.verticalloops only from the last column item to the first item in the column row.- If
activeIdis initially set tonull, vertical loop will have no effect as moving down from the last row or up from the first row will focus on the composite element. - If
focusWrapmatches the value offocusLoop, it’ll wrap between the last item in the last row or column and the first item in the first row or column and vice-versa. -
Required: no
- Default:
false
focusShift: boolean
Works only on two-dimensional composite widgets.
If enabled, moving up or down when there’s no next item or when the next item is disabled will shift to the item right before it.
- Required: no
- Default:
false
focusWrap: boolean
Works only on two-dimensional composite widgets.
If enabled, moving to the next item from the last one in a row or column
will focus on the first item in the next row or column and vice-versa.
truewraps between rows and columns.horizontalwraps only between rows.verticalwraps only between columns.- If
focusLoopmatches the value offocusWrap, it’ll wrap between the
last item in the last row or column and the first item in the first row or
column and vice-versa. -
Required: no
- Default:
false
virtualFocus: boolean
If enabled, the composite element will act as an aria-activedescendant
container instead of roving tabindex. DOM focus will remain on the composite element while its items receive
virtual focus.
In both scenarios, the item in focus will carry the data-active-item attribute.
- Required: no
- Default:
false
orientation: ‘horizontal’ | ‘vertical’ | ‘both’
Defines the orientation of the composite widget. If the composite has a single row or column (one-dimensional), the