@wordpress/components
Version:
UI components for WordPress.
73 lines (71 loc) • 2.67 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/components/src/tree-grid/roving-tab-index-item.tsx
var roving_tab_index_item_exports = {};
__export(roving_tab_index_item_exports, {
RovingTabIndexItem: () => RovingTabIndexItem,
default: () => roving_tab_index_item_default
});
module.exports = __toCommonJS(roving_tab_index_item_exports);
var import_element = require("@wordpress/element");
var import_roving_tab_index_context = require("./roving-tab-index-context");
var import_jsx_runtime = require("react/jsx-runtime");
var RovingTabIndexItem = (0, import_element.forwardRef)(function UnforwardedRovingTabIndexItem({
children,
as: Component,
...props
}, forwardedRef) {
const localRef = (0, import_element.useRef)();
const ref = forwardedRef || localRef;
const {
lastFocusedElement,
setLastFocusedElement
} = (0, import_roving_tab_index_context.useRovingTabIndexContext)();
let tabIndex;
if (lastFocusedElement) {
tabIndex = lastFocusedElement === // TODO: The original implementation simply used `ref.current` here, assuming
// that a forwarded ref would always be an object, which is not necessarily true.
// This workaround maintains the original runtime behavior in a type-safe way,
// but should be revisited.
("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, import_jsx_runtime.jsx)(Component, {
...allProps,
children
});
});
var roving_tab_index_item_default = RovingTabIndexItem;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
RovingTabIndexItem
});
//# sourceMappingURL=roving-tab-index-item.js.map