UNPKG

@guruhotel/aura-hooks

Version:

🪝 Hooks library designed by the Guruhotel team for Aura UI

1 lines 582 B
exports.__esModule=!0,exports.useFocusReturn=function({opened:u,shouldReturnFocus:n=!0}){const r=(0,e.useRef)(),o=()=>{var e;r.current&&"focus"in r.current&&"function"==typeof r.current.focus&&(null==(e=r.current)||e.focus())};return(0,t.useDidUpdate)((()=>{let e=-1;const t=t=>{"Tab"===t.key&&window.clearTimeout(e)};return document.addEventListener("keydown",t),u?r.current=document.activeElement:n&&(e=window.setTimeout(o,10)),()=>{window.clearTimeout(e),document.removeEventListener("keydown",t)}}),[u,n]),o};var e=require("react"),t=require("../use-did-update/use-did-update");