@@ -182,11 +182,12 @@ export default class DraggableCore extends React.Component {
182182 componentWillUnmount ( ) {
183183 // Remove any leftover event handlers. Remove both touch and mouse handlers in case
184184 // some browser quirk caused a touch event to fire during a mouse move, or vice versa.
185- removeEvent ( document , eventsFor . mouse . move , this . handleDrag ) ;
186- removeEvent ( document , eventsFor . touch . move , this . handleDrag ) ;
187- removeEvent ( document , eventsFor . mouse . stop , this . handleDragStop ) ;
188- removeEvent ( document , eventsFor . touch . stop , this . handleDragStop ) ;
189- if ( this . props . enableUserSelectHack ) removeUserSelectStyles ( ) ;
185+ const { ownerDocument} = ReactDOM . findDOMNode ( this ) ;
186+ removeEvent ( ownerDocument , eventsFor . mouse . move , this . handleDrag ) ;
187+ removeEvent ( ownerDocument , eventsFor . touch . move , this . handleDrag ) ;
188+ removeEvent ( ownerDocument , eventsFor . mouse . stop , this . handleDragStop ) ;
189+ removeEvent ( ownerDocument , eventsFor . touch . stop , this . handleDragStop ) ;
190+ if ( this . props . enableUserSelectHack ) removeUserSelectStyles ( ownerDocument . body ) ;
190191 }
191192
192193 handleDragStart : EventHandler < MouseEvent > = ( e ) => {
@@ -196,11 +197,15 @@ export default class DraggableCore extends React.Component {
196197 // Only accept left-clicks.
197198 if ( ! this . props . allowAnyClick && typeof e . button === 'number' && e . button !== 0 ) return false ;
198199
200+ // Get nodes. Be sure to grab relative document (could be iframed)
201+ const domNode = ReactDOM . findDOMNode ( this ) ;
202+ const { ownerDocument} = domNode ;
203+
199204 // Short circuit if handle or cancel prop was provided and selector doesn't match.
200205 if ( this . props . disabled ||
201- ( ! ( e . target instanceof Node ) ) ||
202- ( this . props . handle && ! matchesSelectorAndParentsTo ( e . target , this . props . handle , ReactDOM . findDOMNode ( this ) ) ) ||
203- ( this . props . cancel && matchesSelectorAndParentsTo ( e . target , this . props . cancel , ReactDOM . findDOMNode ( this ) ) ) ) {
206+ ( ! ( e . target instanceof ownerDocument . defaultView . Node ) ) ||
207+ ( this . props . handle && ! matchesSelectorAndParentsTo ( e . target , this . props . handle , domNode ) ) ||
208+ ( this . props . cancel && matchesSelectorAndParentsTo ( e . target , this . props . cancel , domNode ) ) ) {
204209 return ;
205210 }
206211
@@ -227,7 +232,7 @@ export default class DraggableCore extends React.Component {
227232
228233 // Add a style to the body to disable user-select. This prevents text from
229234 // being selected all over the page.
230- if ( this . props . enableUserSelectHack ) addUserSelectStyles ( ) ;
235+ if ( this . props . enableUserSelectHack ) addUserSelectStyles ( ownerDocument . body ) ;
231236
232237 // Initiate dragging. Set the current x and y as offsets
233238 // so we know how much we've moved during the drag. This allows us
@@ -242,8 +247,8 @@ export default class DraggableCore extends React.Component {
242247 // Add events to the document directly so we catch when the user's mouse/touch moves outside of
243248 // this element. We use different events depending on whether or not we have detected that this
244249 // is a touch-capable device.
245- addEvent ( document , dragEventFor . move , this . handleDrag ) ;
246- addEvent ( document , dragEventFor . stop , this . handleDragStop ) ;
250+ addEvent ( ownerDocument , dragEventFor . move , this . handleDrag ) ;
251+ addEvent ( ownerDocument , dragEventFor . stop , this . handleDragStop ) ;
247252 } ;
248253
249254 handleDrag : EventHandler < MouseEvent > = ( e ) => {
@@ -298,7 +303,7 @@ export default class DraggableCore extends React.Component {
298303 const coreEvent = createCoreData ( this , x , y ) ;
299304
300305 // Remove user-select hack
301- if ( this . props . enableUserSelectHack ) removeUserSelectStyles ( ) ;
306+ if ( this . props . enableUserSelectHack ) removeUserSelectStyles ( ReactDOM . findDOMNode ( this ) . ownerDocument . body ) ;
302307
303308 log ( 'DraggableCore: handleDragStop: %j' , coreEvent ) ;
304309
@@ -313,9 +318,10 @@ export default class DraggableCore extends React.Component {
313318 this . props . onStop ( e , coreEvent ) ;
314319
315320 // Remove event handlers
321+ const { ownerDocument} = ReactDOM . findDOMNode ( this ) ;
316322 log ( 'DraggableCore: Removing handlers' ) ;
317- removeEvent ( document , dragEventFor . move , this . handleDrag ) ;
318- removeEvent ( document , dragEventFor . stop , this . handleDragStop ) ;
323+ removeEvent ( ownerDocument , dragEventFor . move , this . handleDrag ) ;
324+ removeEvent ( ownerDocument , dragEventFor . stop , this . handleDragStop ) ;
319325 } ;
320326
321327 onMouseDown : EventHandler < MouseEvent > = ( e ) => {
0 commit comments