Renders a widget based on the WAI-ARIA composite
role, which provides a single tab stop on the page and arrow key navigation
through the focusable descendants.
import { Composite } from '@wordpress/components';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
activeId |
The current active item
| |
defaultActiveId |
The composite item id that should be active by default when the composite
widget is rendered. If | |
setActiveId |
A callback that gets called when the | |
focusLoop | false |
Determines how the focus behaves when the user reaches the end of the composite widget. On one-dimensional composite widgets:
On two-dimensional composite widgets (ie. when using
|
focusWrap | false |
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.
|
focusShift | false |
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. |
virtualFocus | false |
If enabled, the composite element will act as an
In both scenarios, the item in focus will carry the |
orientation | 'both' |
Defines the orientation of the composite widget. If the composite has a
single row or column (one-dimensional), the
It doesn’t have any effect on two-dimensional composites. |
rtl | isRTL() |
Controls how the previous and next items are determined.
If This only affects the composite widget behavior. You still need to set
|
render |
Allows the component to be rendered as a different HTML element or React component. The value can be a React element or a function that takes in the original component props and gives back a React element with the props merged. | |
focusable |
Makes the component a focusable element. When this element gains keyboard
focus, it gets a | |
disabled | false |
Determines if the element is disabled. This sets the This feature can be combined with the Note: For this prop to work, the |
accessibleWhenDisabled |
Indicates whether the element should be focusable even when it is
This is important when discoverability is a concern. For example:
Learn more on Focusability of disabled controls. | |
onFocusVisible |
Custom event handler invoked when the element gains focus through keyboard
interaction or a key press occurs while the element is in focus. This is
the programmatic equivalent of the Note: For this prop to work, the | |
children |
The contents of the component. |
ExamplesPermalink to this section
DefaultPermalink to this section
const Default = () => <Composite>(<>
<Composite.Item>Item one</Composite.Item>
<Composite.Item>Item two</Composite.Item>
<Composite.Item>Item three</Composite.Item>
</>)</Composite>;
GroupsPermalink to this section
const Groups = () => <Composite>(<>
<Composite.Group>
<Composite.GroupLabel>Group one</Composite.GroupLabel>
<Composite.Item>Item 1.1</Composite.Item>
<Composite.Item>Item 1.2</Composite.Item>
</Composite.Group>
<Composite.Group>
<Composite.GroupLabel>Group two</Composite.GroupLabel>
<Composite.Item>Item 2.1</Composite.Item>
<Composite.Item>Item 2.1</Composite.Item>
</Composite.Group>
</>)</Composite>;
GridPermalink to this section
const Grid = () => <Composite role="grid" aria-label="Composite">(<>
<Composite.Row role="row">
<Composite.Item role="gridcell">Item A1</Composite.Item>
<Composite.Item role="gridcell">Item A2</Composite.Item>
<Composite.Item role="gridcell">Item A3</Composite.Item>
</Composite.Row>
<Composite.Row role="row">
<Composite.Item role="gridcell">Item B1</Composite.Item>
<Composite.Item role="gridcell">Item B2</Composite.Item>
<Composite.Item role="gridcell">Item B3</Composite.Item>
</Composite.Row>
<Composite.Row role="row">
<Composite.Item role="gridcell">Item C1</Composite.Item>
<Composite.Item role="gridcell">Item C2</Composite.Item>
<Composite.Item role="gridcell">Item C3</Composite.Item>
</Composite.Row>
</>)</Composite>;
HoverPermalink to this section
const Hover = () => <Composite>(<>
<Composite.Hover render={ <Composite.Item /> }>
Hover item one
</Composite.Hover>
<Composite.Hover render={ <Composite.Item /> }>
Hover item two
</Composite.Hover>
<Composite.Hover render={ <Composite.Item /> }>
Hover item three
</Composite.Hover>
</>)</Composite>;
TypeaheadPermalink to this section
const Typeahead = () => <Composite render={<Composite.Typeahead />}>(<>
<Composite.Item>Apple</Composite.Item>
<Composite.Item>Banana</Composite.Item>
<Composite.Item>Peach</Composite.Item>
</>)</Composite>;
With Slot FillPermalink to this section
const WithSlotFill = () => <Composite>(<>
<Composite.Item>Item one (direct child)</Composite.Item>
<Slot />
<Composite.Item>Item four (direct child)</Composite.Item>
</>)</Composite>;
With TooltipsPermalink to this section
Combining the Tooltip and Composite component has a few caveats. And while there are a few ways to compose these two components, our recommendation is to render Composite.Item as a child of Tooltip.
// 🔴 Does not work
</Tooltip>const WithTooltips = () => <Composite>(<>
<Tooltip text="Tooltip one">
<Composite.Item>Item one</Composite.Item>
</Tooltip>
<Tooltip text="Tooltip two">
<Composite.Item>Item two</Composite.Item>
</Tooltip>
<Tooltip text="Tooltip three">
<Composite.Item>Item three</Composite.Item>
</Tooltip>
</>)</Composite>;