UNPKG

@wordpress/components

Version:
8 lines (7 loc) 2.41 kB
{ "version": 3, "sources": ["../../src/tree-grid/roving-tab-index-item.tsx"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef, forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useRovingTabIndexContext } from './roving-tab-index-context';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nexport const RovingTabIndexItem = forwardRef(function UnforwardedRovingTabIndexItem({\n children,\n as: Component,\n ...props\n}, forwardedRef) {\n const localRef = useRef(null);\n const ref = forwardedRef || localRef;\n // @ts-expect-error - We actually want to throw an error if this is undefined.\n const {\n lastFocusedElement,\n setLastFocusedElement\n } = useRovingTabIndexContext();\n let tabIndex;\n if (lastFocusedElement) {\n tabIndex = lastFocusedElement === (\n // TODO: The original implementation simply used `ref.current` here, assuming\n // that a forwarded ref would always be an object, which is not necessarily true.\n // This workaround maintains the original runtime behavior in a type-safe way,\n // but should be revisited.\n 'current' in ref ? ref.current : undefined) ? 0 : -1;\n }\n const onFocus = event => setLastFocusedElement?.(event.target);\n const allProps = {\n ref,\n tabIndex,\n onFocus,\n ...props\n };\n if (typeof children === 'function') {\n return children(allProps);\n }\n if (!Component) {\n return null;\n }\n return /*#__PURE__*/_jsx(Component, {\n ...allProps,\n children: children\n });\n});\nRovingTabIndexItem.displayName = 'RovingTabIndexItem';\nexport default RovingTabIndexItem;"], "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAmC;AAKnC,sCAAyC;AACzC,yBAA4B;AACrB,IAAM,yBAAqB,2BAAW,SAAS,8BAA8B;AAAA,EAClF;AAAA,EACA,IAAI;AAAA,EACJ,GAAG;AACL,GAAG,cAAc;AACf,QAAM,eAAW,uBAAO,IAAI;AAC5B,QAAM,MAAM,gBAAgB;AAE5B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,EACF,QAAI,0DAAyB;AAC7B,MAAI;AACJ,MAAI,oBAAoB;AACtB,eAAW;AAAA;AAAA;AAAA;AAAA,KAKX,aAAa,MAAM,IAAI,UAAU,UAAa,IAAI;AAAA,EACpD;AACA,QAAM,UAAU,WAAS,wBAAwB,MAAM,MAAM;AAC7D,QAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACA,MAAI,OAAO,aAAa,YAAY;AAClC,WAAO,SAAS,QAAQ;AAAA,EAC1B;AACA,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AACA,SAAoB,uCAAAA,KAAK,WAAW;AAAA,IAClC,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH,CAAC;AACD,mBAAmB,cAAc;AACjC,IAAO,gCAAQ;", "names": ["_jsx"] }