@wordpress/components
Version:
UI components for WordPress.
36 lines (35 loc) • 1.51 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_element = require("@wordpress/element");
let __roving_tab_index_context_ts = require("./roving-tab-index-context.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/components/src/tree-grid/roving-tab-index-item.tsx
const RovingTabIndexItem = (0, _wordpress_element.forwardRef)(function UnforwardedRovingTabIndexItem({ children, as: Component, ...props }, forwardedRef) {
const localRef = (0, _wordpress_element.useRef)(null);
const ref = forwardedRef || localRef;
const context = (0, __roving_tab_index_context_ts.useRovingTabIndexContext)();
if (!context) throw new Error("TreeGridItem can only be rendered inside a TreeGrid component.");
const { lastFocusedElement, setLastFocusedElement } = context;
let tabIndex;
if (lastFocusedElement) tabIndex = lastFocusedElement === ("current" in ref ? ref.current : void 0) ? 0 : -1;
const onFocus = (event) => setLastFocusedElement?.(event.target);
const allProps = {
ref,
tabIndex,
onFocus,
...props
};
if (typeof children === "function") return children(allProps);
if (!Component) return null;
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
...allProps,
children
});
});
RovingTabIndexItem.displayName = "RovingTabIndexItem";
exports.RovingTabIndexItem = RovingTabIndexItem;
exports.default = RovingTabIndexItem;
//# sourceMappingURL=roving-tab-index-item.cjs.map