File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,9 @@ <h1>React Draggable</h1>
135135 < Draggable axis = "y" { ...dragHandlers } >
136136 < div className = "box cursor-y" > I can only be dragged vertically</ div >
137137 </ Draggable >
138+ < Draggable onStart = { ( ) => false } >
139+ < div className = "box" > I don't want to be dragged</ div >
140+ </ Draggable >
138141 < Draggable onDrag = { this . handleDrag } { ...dragHandlers } >
139142 < div className = "box" >
140143 < div > I track my deltas</ div >
Original file line number Diff line number Diff line change @@ -199,10 +199,6 @@ export default class DraggableCore extends React.Component {
199199 this . setState ( { touchIdentifier : e . targetTouches [ 0 ] . identifier } ) ;
200200 }
201201
202- // Add a style to the body to disable user-select. This prevents text from
203- // being selected all over the page.
204- if ( this . props . enableUserSelectHack ) addUserSelectStyles ( ) ;
205-
206202 // Get the current drag point from the event. This is used as the offset.
207203 const { x, y} = getControlPosition ( e , this ) ;
208204
@@ -216,6 +212,9 @@ export default class DraggableCore extends React.Component {
216212 const shouldUpdate = this . props . onStart ( e , coreEvent ) ;
217213 if ( shouldUpdate === false ) return ;
218214
215+ // Add a style to the body to disable user-select. This prevents text from
216+ // being selected all over the page.
217+ if ( this . props . enableUserSelectHack ) addUserSelectStyles ( ) ;
219218
220219 // Initiate dragging. Set the current x and y as offsets
221220 // so we know how much we've moved during the drag. This allows us
Original file line number Diff line number Diff line change @@ -301,6 +301,24 @@ describe('react-draggable', function () {
301301 TestUtils . Simulate . mouseUp ( node ) ;
302302 expect ( document . body . getAttribute ( 'style' ) ) . toEqual ( '' ) ;
303303 } ) ;
304+
305+ it ( 'should not add and remove user-select styles when onStart returns false' , function ( ) {
306+ function onStart ( ) { return false ; }
307+
308+ drag = TestUtils . renderIntoDocument (
309+ < Draggable onStart = { onStart } >
310+ < div />
311+ </ Draggable >
312+ ) ;
313+
314+ var node = ReactDOM . findDOMNode ( drag ) ;
315+
316+ expect ( document . body . getAttribute ( 'style' ) ) . toEqual ( '' ) ;
317+ TestUtils . Simulate . mouseDown ( node , { clientX : 0 , clientY : 0 } ) ;
318+ expect ( document . body . getAttribute ( 'style' ) ) . toEqual ( '' ) ;
319+ TestUtils . Simulate . mouseUp ( node ) ;
320+ expect ( document . body . getAttribute ( 'style' ) ) . toEqual ( '' ) ;
321+ } ) ;
304322 } ) ;
305323
306324 describe ( 'interaction' , function ( ) {
You can’t perform that action at this time.
0 commit comments