@@ -10,15 +10,20 @@ import _ from 'lodash'
10
10
* @returns {boolean }
11
11
*/
12
12
const doesNodeContainClick = ( node , e ) => {
13
- if ( _ . some ( [ e , node ] , _ . isNil ) ) return false
13
+ if ( _ . some ( [ e , node ] , _ . isNil ) ) {
14
+ return false
15
+ }
14
16
15
17
// if there is an e.target and it is in the document, use a simple node.contains() check
16
18
if ( e . target ) {
17
19
_ . invoke ( e . target , 'setAttribute' , 'data-suir-click-target' , true )
18
20
19
21
if ( document . querySelector ( '[data-suir-click-target=true]' ) ) {
20
22
_ . invoke ( e . target , 'removeAttribute' , 'data-suir-click-target' )
21
- return node . contains ( e . target )
23
+
24
+ if ( typeof node . contains === 'function' ) {
25
+ return node . contains ( e . target )
26
+ }
22
27
}
23
28
}
24
29
@@ -29,18 +34,31 @@ const doesNodeContainClick = (node, e) => {
29
34
// return early if the event properties aren't available
30
35
// prevent measuring the node and repainting if we don't need to
31
36
const { clientX, clientY } = e
32
- if ( _ . some ( [ clientX , clientY ] , _ . isNil ) ) return false
37
+
38
+ if ( _ . some ( [ clientX , clientY ] , _ . isNil ) ) {
39
+ return false
40
+ }
41
+
42
+ if ( typeof node . getClientRects !== 'function' ) {
43
+ return false
44
+ }
33
45
34
46
// false if the node is not visible
35
47
const clientRects = node . getClientRects ( )
48
+
36
49
// Heads Up!
37
50
// getClientRects returns a DOMRectList, not an array nor a plain object
38
51
// We explicitly avoid _.isEmpty and check .length to cover all possible shapes
39
- if ( ! node . offsetWidth || ! node . offsetHeight || ! clientRects || ! clientRects . length ) return false
52
+ if ( ! node . offsetWidth || ! node . offsetHeight || ! clientRects || ! clientRects . length ) {
53
+ return false
54
+ }
40
55
41
56
// false if the node doesn't have a valid bounding rect
42
57
const { top, bottom, left, right } = _ . first ( clientRects )
43
- if ( _ . some ( [ top , bottom , left , right ] , _ . isNil ) ) return false
58
+
59
+ if ( _ . some ( [ top , bottom , left , right ] , _ . isNil ) ) {
60
+ return false
61
+ }
44
62
45
63
// we add a small decimal to the upper bound just to make it inclusive
46
64
// don't add an whole pixel (1) as the event/node values may be decimal sensitive
0 commit comments