File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,24 +4,6 @@ import EventListener from './utils/EventListener';
44
55// TODO: Merge this logic with dropdown logic once #526 is done.
66
7- /**
8- * Checks whether a node is within
9- * a root nodes tree
10- *
11- * @param {DOMElement } node
12- * @param {DOMElement } root
13- * @returns {boolean }
14- */
15- function isNodeInRoot ( node , root ) {
16- while ( node ) {
17- if ( node === root ) {
18- return true ;
19- }
20- node = node . parentNode ;
21- }
22-
23- return false ;
24- }
257
268export default class RootCloseWrapper extends React . Component {
279 constructor ( props ) {
@@ -44,7 +26,7 @@ export default class RootCloseWrapper extends React.Component {
4426 // If the click originated from within this component, don't do anything.
4527 // e.srcElement is required for IE8 as e.target is undefined
4628 let target = e . target || e . srcElement ;
47- if ( isNodeInRoot ( target , React . findDOMNode ( this ) ) ) {
29+ if ( domUtils . contains ( React . findDOMNode ( this ) , target ) ) {
4830 return ;
4931 }
5032
Original file line number Diff line number Diff line change @@ -113,7 +113,32 @@ function offsetParentFunc(elem) {
113113 return offsetParent || docElem ;
114114}
115115
116+ /**
117+ * Cross browser .contains() polyfill
118+ * @param {HTMLElement } elem
119+ * @param {HTMLElement } inner
120+ * @return {bool }
121+ */
122+ function contains ( elem , inner ) {
123+ function ie8Contains ( root , node ) {
124+ while ( node ) {
125+ if ( node === root ) {
126+ return true ;
127+ }
128+ node = node . parentNode ;
129+ }
130+ return false ;
131+ }
132+
133+ return ( elem && elem . contains )
134+ ? elem . contains ( inner )
135+ : ( elem && elem . compareDocumentPosition )
136+ ? elem === inner || ! ! ( elem . compareDocumentPosition ( inner ) & 16 )
137+ : ie8Contains ( elem , inner ) ;
138+ }
139+
116140export default {
141+ contains,
117142 ownerDocument,
118143 getComputedStyles,
119144 getOffset,
You can’t perform that action at this time.
0 commit comments