This commit is contained in:
Robert Jelic
2025-02-16 18:04:24 +01:00
parent 41e6149828
commit 31787b0e9b
2670 changed files with 1037781 additions and 0 deletions

34
node_modules/@docsearch/react/dist/esm/useTrapFocus.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
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]);
}