UNPKG

@primer/react-brand

Version:

Primer Brand is a GitHub's design system for creating React-based marketing websites and digital experiences.

28 lines (27 loc) 792 B
import e from "react"; import { focusTrap as t } from "@primer/behaviors"; //#region src/hooks/useFocusTrap.ts function n(n, r = []) { let i = n?.containerRef, a = n?.initialFocusRef, o = n?.disabled, s = e.useRef(null), c = e.useRef(null); !c.current && !n?.disabled && (c.current = document.activeElement); function l() { s.current?.abort(), n?.restoreFocusOnCleanUp && c.current instanceof HTMLElement && (c.current.focus(), c.current = null); } return e.useEffect(() => { if (i?.current instanceof HTMLElement) if (o) l(); else return s.current = t(i.current, a?.current ?? void 0) ?? null, () => { l(); }; }, [ i, a, o, ...r ]), { containerRef: i, initialFocusRef: a }; } //#endregion export { n as useFocusTrap }; //# sourceMappingURL=useFocusTrap.js.map