@cerberus-design/react
Version:
The Cerberus Design React component library.
29 lines (28 loc) • 864 B
JavaScript
// src/components/deprecated/aria-helpers/trap-focus.aria.ts
function trapFocus(modalRef) {
const focusableElements = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
const focusable = Array.from(
modalRef.current?.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();
}
}
}
};
}
export {
trapFocus
};
//# sourceMappingURL=chunk-IX7BYPTS.js.map