@chakra-ui/hooks
Advanced tools
Comparing version 1.1.2 to 1.1.3
# Change Log | ||
## 1.1.3 | ||
### Patch Changes | ||
- [`b572bceed`](https://github.com/chakra-ui/chakra-ui/commit/b572bceedd9fb0c41c65118f0d9ba672791932ca) | ||
Thanks [@segunadebayo](https://github.com/segunadebayo)! - | ||
**useOutsideClick:** | ||
- Update reference to `document.addEventListener` to detect owner document | ||
based on `ref` passed. This would help detect outside click currently from | ||
within an `iframe`. | ||
## 1.1.2 | ||
@@ -4,0 +16,0 @@ |
@@ -6,2 +6,4 @@ "use strict"; | ||
var _utils = require("@chakra-ui/utils"); | ||
var _react = require("react"); | ||
@@ -52,11 +54,12 @@ | ||
document.addEventListener("mousedown", onPointerDown, true); | ||
document.addEventListener("mouseup", onMouseUp, true); | ||
document.addEventListener("touchstart", onPointerDown, true); | ||
document.addEventListener("touchend", onTouchEnd, true); | ||
var doc = (0, _utils.getOwnerDocument)(ref.current); | ||
doc.addEventListener("mousedown", onPointerDown, true); | ||
doc.addEventListener("mouseup", onMouseUp, true); | ||
doc.addEventListener("touchstart", onPointerDown, true); | ||
doc.addEventListener("touchend", onTouchEnd, true); | ||
return function () { | ||
document.removeEventListener("mousedown", onPointerDown, true); | ||
document.removeEventListener("mouseup", onMouseUp, true); | ||
document.removeEventListener("touchstart", onPointerDown, true); | ||
document.removeEventListener("touchend", onTouchEnd, true); | ||
doc.removeEventListener("mousedown", onPointerDown, true); | ||
doc.removeEventListener("mouseup", onMouseUp, true); | ||
doc.removeEventListener("touchstart", onPointerDown, true); | ||
doc.removeEventListener("touchend", onTouchEnd, true); | ||
}; | ||
@@ -67,2 +70,4 @@ }, [handler, ref, savedHandler, state]); | ||
function isValidEvent(event, ref) { | ||
var _ref$current; | ||
var target = event.target; | ||
@@ -72,11 +77,8 @@ if (event.button > 0) return false; // if the event target is no longer in the document | ||
if (target) { | ||
var ownerDocument = target.ownerDocument; | ||
if (!ownerDocument || !ownerDocument.body.contains(target)) { | ||
return false; | ||
} | ||
var doc = (0, _utils.getOwnerDocument)(target); | ||
if (!doc.body.contains(target)) return false; | ||
} | ||
return ref.current && !ref.current.contains(target); | ||
return !((_ref$current = ref.current) != null && _ref$current.contains(target)); | ||
} | ||
//# sourceMappingURL=use-outside-click.js.map |
@@ -0,1 +1,2 @@ | ||
import { getOwnerDocument } from "@chakra-ui/utils"; | ||
import { useEffect, useRef } from "react"; | ||
@@ -47,11 +48,12 @@ import { useCallbackRef } from "./use-callback-ref"; | ||
document.addEventListener("mousedown", onPointerDown, true); | ||
document.addEventListener("mouseup", onMouseUp, true); | ||
document.addEventListener("touchstart", onPointerDown, true); | ||
document.addEventListener("touchend", onTouchEnd, true); | ||
var doc = getOwnerDocument(ref.current); | ||
doc.addEventListener("mousedown", onPointerDown, true); | ||
doc.addEventListener("mouseup", onMouseUp, true); | ||
doc.addEventListener("touchstart", onPointerDown, true); | ||
doc.addEventListener("touchend", onTouchEnd, true); | ||
return () => { | ||
document.removeEventListener("mousedown", onPointerDown, true); | ||
document.removeEventListener("mouseup", onMouseUp, true); | ||
document.removeEventListener("touchstart", onPointerDown, true); | ||
document.removeEventListener("touchend", onTouchEnd, true); | ||
doc.removeEventListener("mousedown", onPointerDown, true); | ||
doc.removeEventListener("mouseup", onMouseUp, true); | ||
doc.removeEventListener("touchstart", onPointerDown, true); | ||
doc.removeEventListener("touchend", onTouchEnd, true); | ||
}; | ||
@@ -62,2 +64,4 @@ }, [handler, ref, savedHandler, state]); | ||
function isValidEvent(event, ref) { | ||
var _ref$current; | ||
var target = event.target; | ||
@@ -67,11 +71,8 @@ if (event.button > 0) return false; // if the event target is no longer in the document | ||
if (target) { | ||
var ownerDocument = target.ownerDocument; | ||
if (!ownerDocument || !ownerDocument.body.contains(target)) { | ||
return false; | ||
} | ||
var doc = getOwnerDocument(target); | ||
if (!doc.body.contains(target)) return false; | ||
} | ||
return ref.current && !ref.current.contains(target); | ||
return !((_ref$current = ref.current) != null && _ref$current.contains(target)); | ||
} | ||
//# sourceMappingURL=use-outside-click.js.map |
{ | ||
"name": "@chakra-ui/hooks", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "React hooks for Chakra components", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
205554
2165