@@ -171,10 +171,11 @@ export default class DraggableCore extends React.Component {
171
171
componentWillUnmount ( ) {
172
172
// Remove any leftover event handlers. Remove both touch and mouse handlers in case
173
173
// some browser quirk caused a touch event to fire during a mouse move, or vice versa.
174
- removeEvent ( document , eventsFor . mouse . move , this . handleDrag ) ;
175
- removeEvent ( document , eventsFor . touch . move , this . handleDrag ) ;
176
- removeEvent ( document , eventsFor . mouse . stop , this . handleDragStop ) ;
177
- removeEvent ( document , eventsFor . touch . stop , this . handleDragStop ) ;
174
+ const { ownerDocument} = ReactDOM . findDOMNode ( this ) ;
175
+ removeEvent ( ownerDocument , eventsFor . mouse . move , this . handleDrag ) ;
176
+ removeEvent ( ownerDocument , eventsFor . touch . move , this . handleDrag ) ;
177
+ removeEvent ( ownerDocument , eventsFor . mouse . stop , this . handleDragStop ) ;
178
+ removeEvent ( ownerDocument , eventsFor . touch . stop , this . handleDragStop ) ;
178
179
if ( this . props . enableUserSelectHack ) removeUserSelectStyles ( ) ;
179
180
}
180
181
@@ -185,11 +186,12 @@ export default class DraggableCore extends React.Component {
185
186
// Only accept left-clicks.
186
187
if ( ! this . props . allowAnyClick && typeof e . button === 'number' && e . button !== 0 ) return false ;
187
188
189
+ const domNode = ReactDOM . findDOMNode ( this ) ;
188
190
// Short circuit if handle or cancel prop was provided and selector doesn't match.
189
191
if ( this . props . disabled ||
190
- ( ! ( e . target instanceof Node ) ) ||
191
- ( this . props . handle && ! matchesSelectorAndParentsTo ( e . target , this . props . handle , ReactDOM . findDOMNode ( this ) ) ) ||
192
- ( this . props . cancel && matchesSelectorAndParentsTo ( e . target , this . props . cancel , ReactDOM . findDOMNode ( this ) ) ) ) {
192
+ ( ! ( e . target instanceof domNode . ownerDocument . defaultView . Node ) ) ||
193
+ ( this . props . handle && ! matchesSelectorAndParentsTo ( e . target , this . props . handle , domNode ) ) ||
194
+ ( this . props . cancel && matchesSelectorAndParentsTo ( e . target , this . props . cancel , domNode ) ) ) {
193
195
return ;
194
196
}
195
197
@@ -231,8 +233,8 @@ export default class DraggableCore extends React.Component {
231
233
// Add events to the document directly so we catch when the user's mouse/touch moves outside of
232
234
// this element. We use different events depending on whether or not we have detected that this
233
235
// is a touch-capable device.
234
- addEvent ( document , dragEventFor . move , this . handleDrag ) ;
235
- addEvent ( document , dragEventFor . stop , this . handleDragStop ) ;
236
+ addEvent ( domNode . ownerDocument , dragEventFor . move , this . handleDrag ) ;
237
+ addEvent ( domNode . ownerDocument , dragEventFor . stop , this . handleDragStop ) ;
236
238
} ;
237
239
238
240
handleDrag : EventHandler < MouseEvent > = ( e ) => {
@@ -302,9 +304,10 @@ export default class DraggableCore extends React.Component {
302
304
this . props . onStop ( e , coreEvent ) ;
303
305
304
306
// Remove event handlers
307
+ const { ownerDocument} = ReactDOM . findDOMNode ( this ) ;
305
308
log ( 'DraggableCore: Removing handlers' ) ;
306
- removeEvent ( document , dragEventFor . move , this . handleDrag ) ;
307
- removeEvent ( document , dragEventFor . stop , this . handleDragStop ) ;
309
+ removeEvent ( ownerDocument , dragEventFor . move , this . handleDrag ) ;
310
+ removeEvent ( ownerDocument , dragEventFor . stop , this . handleDragStop ) ;
308
311
} ;
309
312
310
313
onMouseDown : EventHandler < MouseEvent > = ( e ) => {
0 commit comments