@loke/ui
Version:
2 lines (1 loc) • 851 B
JavaScript
import{useEffect}from"react";var count=0;function FocusGuards(props){return useFocusGuards(),props.children}function useFocusGuards(){useEffect(()=>{let edgeGuards=document.querySelectorAll("[data-loke-focus-guard]");return document.body.insertAdjacentElement("afterbegin",edgeGuards[0]??createFocusGuard()),document.body.insertAdjacentElement("beforeend",edgeGuards[1]??createFocusGuard()),count++,()=>{if(count===1)for(let node of document.querySelectorAll("[data-loke-focus-guard]"))node.remove();count--}},[])}function createFocusGuard(){let element=document.createElement("span");return element.setAttribute("data-loke-focus-guard",""),element.tabIndex=0,element.style.outline="none",element.style.opacity="0",element.style.position="fixed",element.style.pointerEvents="none",element}var Root=FocusGuards;export{useFocusGuards,Root,FocusGuards};