@@ -386,6 +386,13 @@ module.exports = React.createClass({
386386 y : React . PropTypes . number
387387 } ) ,
388388
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+
389396 /**
390397 * `zIndex` specifies the zIndex to use while dragging.
391398 *
@@ -474,6 +481,14 @@ module.exports = React.createClass({
474481 onMouseDown : React . PropTypes . func ,
475482 } ,
476483
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+
477492 componentWillUnmount : function ( ) {
478493 // Remove any leftover event handlers
479494 removeEvent ( window , dragEventFor [ 'move' ] , this . handleDrag ) ;
@@ -488,6 +503,7 @@ module.exports = React.createClass({
488503 handle : null ,
489504 cancel : null ,
490505 grid : null ,
506+ moveOnStartChange : false ,
491507 start : { x : 0 , y : 0 } ,
492508 zIndex : NaN ,
493509 enableUserSelectHack : true ,
@@ -498,7 +514,9 @@ module.exports = React.createClass({
498514 } ;
499515 } ,
500516
501- getInitialState : function ( ) {
517+ getInitialState : function ( props ) {
518+ // Handle call from CWRP
519+ props = props || this . props ;
502520 return {
503521 // Whether or not we are currently dragging.
504522 dragging : false ,
@@ -507,7 +525,9 @@ module.exports = React.createClass({
507525 offsetX : 0 , offsetY : 0 ,
508526
509527 // 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
511531 } ;
512532 } ,
513533
0 commit comments