koval-ui
Version:
React components collection with minimalistic design. Supports theming, layout, and input validation.
3 lines (2 loc) • 852 B
JavaScript
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),n=require("./useEventListener.cjs"),y=(c,t,s=!0)=>{const u=r.useRef(null),[l,o]=r.useState([]);r.useEffect(()=>{if(s&&t){u.current=c==null?void 0:c.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');const e=u.current?u.current[0]:null,a=u.current?u.current[u.current.length-1]:null;o([e,a])}},[t,c,s]),r.useEffect(()=>{var e;s&&t&&((e=l[0])==null||e.focus())},[s,l,t]);const b=r.useCallback(e=>{const[a,f]=l;s&&t&&e.key==="Tab"&&(e.shiftKey&&document.activeElement===a?(e.preventDefault(),f.focus()):!e.shiftKey&&document.activeElement===f&&(e.preventDefault(),a.focus()))},[s,l,t]);n.useEventListener(n.EventType.keydown,b)};exports.useFocusTrap=y;
//# sourceMappingURL=useFocusTrap.cjs.map