38646.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. exports.id = 38646;
  3. exports.ids = [38646];
  4. exports.modules = {
  5. /***/ 38646:
  6. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  7. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  8. /* harmony export */ "Z": () => (__WEBPACK_DEFAULT_EXPORT__)
  9. /* harmony export */ });
  10. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(16689);
  11. /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
  12. /**
  13. * A hook that detects clicking outside an element.
  14. *
  15. * @param {React.RefObject<HTMLElement>} ref
  16. * @param {()=> void} onClickOutsideDetected
  17. * @param {boolean} enableDetection
  18. */ const useOutsideClickDetector = (ref, onClickOutsideDetected, enableDetection)=>{
  19. (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(()=>{
  20. const handleClickOutside = (event)=>{
  21. // if we click on an element inside the document that is not an inclusive descendant of the ref node.
  22. if (ref.current && !ref.current.contains(event.target)) {
  23. onClickOutsideDetected();
  24. }
  25. };
  26. // no need to attach the listener if the parent component's visibility is controlled.
  27. if (enableDetection) {
  28. // Bind the event listener
  29. document.addEventListener("mousedown", handleClickOutside);
  30. }
  31. return ()=>{
  32. // Unbind the event listener on clean up
  33. document.removeEventListener("mousedown", handleClickOutside);
  34. };
  35. }, [
  36. ref,
  37. onClickOutsideDetected,
  38. enableDetection
  39. ]);
  40. };
  41. /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (useOutsideClickDetector);
  42. /***/ })
  43. };
  44. ;
  45. //# sourceMappingURL=38646.js.map