index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var $cnctE$react = require("react");
  2. function $parcel$export(e, n, v, s) {
  3. Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
  4. }
  5. $parcel$export(module.exports, "FocusGuards", () => $71476a6ed7dbbaf3$export$ac5b58043b79449b);
  6. $parcel$export(module.exports, "Root", () => $71476a6ed7dbbaf3$export$be92b6f5f03c0fe9);
  7. $parcel$export(module.exports, "useFocusGuards", () => $71476a6ed7dbbaf3$export$b7ece24a22aeda8c);
  8. /** Number of components which have requested interest to have focus guards */ let $71476a6ed7dbbaf3$var$count = 0;
  9. function $71476a6ed7dbbaf3$export$ac5b58043b79449b(props) {
  10. $71476a6ed7dbbaf3$export$b7ece24a22aeda8c();
  11. return props.children;
  12. }
  13. /**
  14. * Injects a pair of focus guards at the edges of the whole DOM tree
  15. * to ensure `focusin` & `focusout` events can be caught consistently.
  16. */ function $71476a6ed7dbbaf3$export$b7ece24a22aeda8c() {
  17. $cnctE$react.useEffect(()=>{
  18. var _edgeGuards$, _edgeGuards$2;
  19. const edgeGuards = document.querySelectorAll('[data-radix-focus-guard]');
  20. document.body.insertAdjacentElement('afterbegin', (_edgeGuards$ = edgeGuards[0]) !== null && _edgeGuards$ !== void 0 ? _edgeGuards$ : $71476a6ed7dbbaf3$var$createFocusGuard());
  21. document.body.insertAdjacentElement('beforeend', (_edgeGuards$2 = edgeGuards[1]) !== null && _edgeGuards$2 !== void 0 ? _edgeGuards$2 : $71476a6ed7dbbaf3$var$createFocusGuard());
  22. $71476a6ed7dbbaf3$var$count++;
  23. return ()=>{
  24. if ($71476a6ed7dbbaf3$var$count === 1) document.querySelectorAll('[data-radix-focus-guard]').forEach((node)=>node.remove()
  25. );
  26. $71476a6ed7dbbaf3$var$count--;
  27. };
  28. }, []);
  29. }
  30. function $71476a6ed7dbbaf3$var$createFocusGuard() {
  31. const element = document.createElement('span');
  32. element.setAttribute('data-radix-focus-guard', '');
  33. element.tabIndex = 0;
  34. element.style.cssText = 'outline: none; opacity: 0; position: fixed; pointer-events: none';
  35. return element;
  36. }
  37. const $71476a6ed7dbbaf3$export$be92b6f5f03c0fe9 = $71476a6ed7dbbaf3$export$ac5b58043b79449b;
  38. //# sourceMappingURL=index.js.map