This commit is contained in:
NoryiE
2025-02-10 06:00:28 +00:00
parent b0a4a6da9c
commit 71a1fce096
2428 changed files with 0 additions and 1005324 deletions

View File

@@ -1,34 +0,0 @@
import React from 'react';
export function useTrapFocus(_ref) {
var container = _ref.container;
React.useEffect(function () {
if (!container) {
return undefined;
}
var focusableElements = container.querySelectorAll('a[href]:not([disabled]), button:not([disabled]), input:not([disabled])');
var firstElement = focusableElements[0];
var lastElement = focusableElements[focusableElements.length - 1];
function trapFocus(event) {
if (event.key !== 'Tab') {
return;
}
if (event.shiftKey) {
if (document.activeElement === firstElement) {
event.preventDefault();
lastElement.focus();
}
} else if (document.activeElement === lastElement) {
event.preventDefault();
firstElement.focus();
}
}
container.addEventListener('keydown', trapFocus);
return function () {
container.removeEventListener('keydown', trapFocus);
};
}, [container]);
}