UNPKG

@cerberus-design/react

Version:

The Cerberus Design React component library.

54 lines (53 loc) 1.94 kB
"use strict"; 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); // src/components/deprecated/aria-helpers/trap-focus.aria.ts var trap_focus_aria_exports = {}; __export(trap_focus_aria_exports, { trapFocus: () => trapFocus }); module.exports = __toCommonJS(trap_focus_aria_exports); function trapFocus(modalRef) { var _a; const focusableElements = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'; const focusable = Array.from( ((_a = modalRef.current) == null ? void 0 : _a.querySelectorAll(focusableElements)) ?? [] ); const firstFocusable = focusable[0]; const lastFocusable = focusable[focusable.length - 1]; return function handleKeyDown(event) { if (event.key === "Tab") { if (event.shiftKey) { if (document.activeElement === firstFocusable) { lastFocusable.focus(); event.preventDefault(); } } else { if (document.activeElement === lastFocusable) { firstFocusable.focus(); event.preventDefault(); } } } }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { trapFocus }); //# sourceMappingURL=trap-focus.aria.cjs.map