@@ -386,6 +386,13 @@ module.exports = React.createClass({
386
386
y : React . PropTypes . number
387
387
} ) ,
388
388
389
+ /**
390
+ * `moveOnStartChange`, if true (default false) will move the element if the `start`
391
+ * property changes.
392
+ */
393
+ moveOnStartChange : React . PropTypes . bool ,
394
+
395
+
389
396
/**
390
397
* `zIndex` specifies the zIndex to use while dragging.
391
398
*
@@ -474,6 +481,14 @@ module.exports = React.createClass({
474
481
onMouseDown : React . PropTypes . func ,
475
482
} ,
476
483
484
+ componentWillReceiveProps : function ( newProps ) {
485
+ // React to changes in the 'start' param.
486
+ if ( newProps . moveOnStartChange && newProps . start &&
487
+ ( newProps . start . x !== this . state . initialStart . x || newProps . start . y !== this . state . initialStart . y ) ) {
488
+ this . setState ( this . getInitialState ( newProps ) ) ;
489
+ }
490
+ } ,
491
+
477
492
componentWillUnmount : function ( ) {
478
493
// Remove any leftover event handlers
479
494
removeEvent ( window , dragEventFor [ 'move' ] , this . handleDrag ) ;
@@ -488,6 +503,7 @@ module.exports = React.createClass({
488
503
handle : null ,
489
504
cancel : null ,
490
505
grid : null ,
506
+ moveOnStartChange : false ,
491
507
start : { x : 0 , y : 0 } ,
492
508
zIndex : NaN ,
493
509
enableUserSelectHack : true ,
@@ -498,7 +514,9 @@ module.exports = React.createClass({
498
514
} ;
499
515
} ,
500
516
501
- getInitialState : function ( ) {
517
+ getInitialState : function ( props ) {
518
+ // Handle call from CWRP
519
+ props = props || this . props ;
502
520
return {
503
521
// Whether or not we are currently dragging.
504
522
dragging : false ,
@@ -507,7 +525,9 @@ module.exports = React.createClass({
507
525
offsetX : 0 , offsetY : 0 ,
508
526
509
527
// Current transform x and y.
510
- clientX : this . props . start . x , clientY : this . props . start . y
528
+ clientX : props . start . x , clientY : props . start . y ,
529
+
530
+ initialStart : props . start
511
531
} ;
512
532
} ,
513
533
0 commit comments