NavigableContainer
Props
These are the props that NavigableMenu and TabbableContainer. Any props which are specific to one component are labelled appropriately.
cycle: boolean
A boolean which tells the component whether or not to cycle from the end back to the beginning and vice versa.
- Required: No
- default:
true
eventToOffset: ( event: KeyboardEvent ) => -1 | 0 | 1 | undefined
(TabbableContainer only)
Gets an offset, given an event.
- Required: No
onKeyDown: ( event: KeyboardEvent ) => void
A callback invoked on the keydown event.
- Required: No
onNavigate: ( index: number, focusable: HTMLElement ) => void
A callback invoked when the menu navigates to one of its children passing the index and child as an argument
- Required: No
orientation: 'vertical' | 'horizontal' | 'both'
- Required: No
- Default:
"vertical"
Components
NavigableMenu
TabbableContainer
This component is deprecated. For focus trapping, consider the useConstrainedTabbing hook from @wordpress/compose.
A TabbableContainer will only be navigated using the tab key. Every intended tabstop must have a tabIndex 0.
Usage
import {
NavigableMenu,
TabbableContainer,
Button,
} from '@wordpress/components';
function onNavigate( index, target ) {
console.log( `Navigates to ${ index }`, target );
}
const MyNavigableContainer = () => (
<div>
<span>Navigable Menu:</span>
<NavigableMenu onNavigate={ onNavigate } orientation="horizontal">
<Button variant="secondary">Item 1</Button>
<Button variant="secondary">Item 2</Button>
<Button variant="secondary">Item 3</Button>
</NavigableMenu>
<span>Tabbable Container:</span>
<TabbableContainer onNavigate={ onNavigate }>
<Button variant="secondary" tabIndex="0">
Section 1
</Button>
<Button variant="secondary" tabIndex="0">
Section 2
</Button>
<Button variant="secondary" tabIndex="0">
Section 3
</Button>
<Button variant="secondary" tabIndex="0">
Section 4
</Button>
</TabbableContainer>
</div>
);
这篇文档对你有帮助吗?
谢谢你的反馈!