@@ -276,6 +276,7 @@ module.exports = React.createClass({
276
276
277
277
/**
278
278
* Called when dragging starts.
279
+ * If this function returns the boolean false, dragging will be canceled.
279
280
*
280
281
* Example:
281
282
*
@@ -296,6 +297,7 @@ module.exports = React.createClass({
296
297
297
298
/**
298
299
* Called while dragging.
300
+ * If this function returns the boolean false, dragging will be canceled.
299
301
*
300
302
* Example:
301
303
*
@@ -393,12 +395,16 @@ module.exports = React.createClass({
393
395
return ;
394
396
}
395
397
398
+ // Call event handler. If it returns explicit false, cancel.
399
+ var shouldStart = this . props . onStart ( e , createUIEvent ( this ) ) ;
400
+ if ( shouldStart === false ) return ;
401
+
402
+ var dragPoint = getControlPosition ( e ) ;
403
+
396
404
// Add a style to the body to disable user-select. This prevents text from
397
405
// being selected all over the page.
398
406
addUserSelectStyles ( this ) ;
399
407
400
- var dragPoint = getControlPosition ( e ) ;
401
-
402
408
// Initiate dragging. Set the current x and y as offsets
403
409
// so we know how much we've moved during the drag. This allows us
404
410
// to drag elements around even if they have been moved, without issue.
@@ -408,8 +414,6 @@ module.exports = React.createClass({
408
414
offsetY : dragPoint . clientY - this . state . clientY
409
415
} ) ;
410
416
411
- // Call event handler
412
- this . props . onStart ( e , createUIEvent ( this ) ) ;
413
417
414
418
// Add event handlers
415
419
addEvent ( window , dragEventFor [ 'move' ] , this . handleDrag ) ;
@@ -450,14 +454,15 @@ module.exports = React.createClass({
450
454
clientX = coords [ 0 ] , clientY = coords [ 1 ] ;
451
455
}
452
456
457
+ // Call event handler. If it returns explicit false, cancel.
458
+ var shouldUpdate = this . props . onDrag ( e , createUIEvent ( this ) ) ;
459
+ if ( shouldUpdate === false ) return this . handleDragEnd ( ) ;
460
+
453
461
// Update transform
454
462
this . setState ( {
455
463
clientX : clientX ,
456
464
clientY : clientY
457
465
} ) ;
458
-
459
- // Call event handler
460
- this . props . onDrag ( e , createUIEvent ( this ) ) ;
461
466
} ,
462
467
463
468
render : function ( ) {
0 commit comments