UNPKG

@wordpress/components

Version:
34 lines (30 loc) 1.01 kB
import { createElement } from "@wordpress/element"; /** * WordPress dependencies */ import { useState, useMemo } from '@wordpress/element'; /** * Internal dependencies */ import { RovingTabIndexProvider } from './roving-tab-index-context'; /** * Provider for adding roving tab index behaviors to tree grid structures. * * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/components/src/tree-grid/README.md */ export default function RovingTabIndex(_ref) { let { children } = _ref; const [lastFocusedElement, setLastFocusedElement] = useState(); // Use `useMemo` to avoid creation of a new object for the providerValue // on every render. Only create a new object when the `lastFocusedElement` // value changes. const providerValue = useMemo(() => ({ lastFocusedElement, setLastFocusedElement }), [lastFocusedElement]); return createElement(RovingTabIndexProvider, { value: providerValue }, children); } //# sourceMappingURL=roving-tab-index.js.map