Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (workingNode) {
const workingArea = [
workingNode,
...shards.map(extractRef).filter(Boolean),
];
if (!activeElement || focusWhitelisted(activeElement)) {
if (
(persistentFocus || focusWasOutsideWindow)
|| !isFreeFocus()
|| (!lastActiveFocus && autoFocus)
) {
if (
workingNode
&& !(
focusInside(workingArea)
|| focusIsPortaledPair(activeElement, workingNode)
)
) {
if (document && !lastActiveFocus && activeElement && !autoFocus) {
activeElement.blur();
document.body.focus();
} else {
result = moveFocusInside(workingArea, lastActiveFocus);
lastPortaledElement = {};
}
}
focusWasOutsideWindow = false;
lastActiveFocus = document && document.activeElement;
}
}
const activateTrap = () => {
let result = false;
if (lastActiveTrap) {
const observed = lastActiveTrap;
if(!isFreeFocus()) {
if (observed && !focusInside(observed)) {
result = moveFocusInside(observed, lastActiveFocus);
}
lastActiveFocus = document.activeElement;
}
}
return result;
};