UNPKG

@wordpress/components

Version:
1 lines • 1.28 kB
{"version":3,"file":"roving-tab-index.mjs","names":[],"sources":["../../src/tree-grid/roving-tab-index.tsx"],"sourcesContent":["import { useState, useMemo } from '@wordpress/element';\nimport { RovingTabIndexProvider } from './roving-tab-index-context';\n\n/**\n * Provider for adding roving tab index behaviors to tree grid structures.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/components/src/tree-grid/README.md\n */\nexport default function RovingTabIndex( {\n\tchildren,\n}: {\n\tchildren: React.ReactNode;\n} ) {\n\tconst [ lastFocusedElement, setLastFocusedElement ] =\n\t\tuseState< HTMLElement >();\n\n\t// Use `useMemo` to avoid creation of a new object for the providerValue\n\t// on every render. Only create a new object when the `lastFocusedElement`\n\t// value changes.\n\tconst providerValue = useMemo(\n\t\t() => ( { lastFocusedElement, setLastFocusedElement } ),\n\t\t[ lastFocusedElement ]\n\t);\n\n\treturn (\n\t\t<RovingTabIndexProvider value={ providerValue }>\n\t\t\t{ children }\n\t\t</RovingTabIndexProvider>\n\t);\n}\n"],"mappings":";;;;;;;;;AAQA,SAAwB,eAAgB,EACvC,YAGG;CACH,MAAM,CAAE,oBAAoB,yBAC3B,SAAwB;CAKzB,MAAM,gBAAgB,eACb;EAAE;EAAoB;CAAsB,IACpD,CAAE,kBAAmB,CACtB;CAEA,OACC,oBAAC,wBAAD;EAAwB,OAAQ;EAC7B;CACqB,CAAA;AAE1B"}