@@ -219,6 +219,9 @@ function createCSSTransform(style) {
219
219
return out ;
220
220
}
221
221
222
+ function createSVGTransform ( args ) {
223
+ return 'translate(' + args . x + ',' + args . y + ')' ;
224
+ }
222
225
223
226
//
224
227
// End Helpers.
@@ -463,7 +466,7 @@ module.exports = React.createClass({
463
466
* A workaround option which can be passed if onMouseDown needs to be accessed,
464
467
* since it'll always be blocked (due to that there's internal use of onMouseDown)
465
468
*/
466
- onMouseDown : React . PropTypes . func
469
+ onMouseDown : React . PropTypes . func ,
467
470
} ,
468
471
469
472
componentWillReceiveProps : function ( newProps ) {
@@ -473,6 +476,13 @@ module.exports = React.createClass({
473
476
}
474
477
} ,
475
478
479
+ componentDidMount : function ( ) {
480
+ // Check to see if the element passed is an instanceof SVGElement
481
+ if ( React . findDOMNode ( this ) instanceof SVGElement ) {
482
+ this . setState ( { isElementSVG : true } ) ;
483
+ }
484
+ } ,
485
+
476
486
componentWillUnmount : function ( ) {
477
487
// Remove any leftover event handlers
478
488
removeEvent ( document , dragEventFor . move , this . handleDrag ) ;
@@ -494,7 +504,7 @@ module.exports = React.createClass({
494
504
onStart : emptyFunction ,
495
505
onDrag : emptyFunction ,
496
506
onStop : emptyFunction ,
497
- onMouseDown : emptyFunction
507
+ onMouseDown : emptyFunction ,
498
508
} ;
499
509
} ,
500
510
@@ -509,7 +519,11 @@ module.exports = React.createClass({
509
519
offsetX : 0 , offsetY : 0 ,
510
520
511
521
// Current transform x and y.
512
- clientX : props . start . x , clientY : props . start . y
522
+ clientX : props . start . x , clientY : props . start . y ,
523
+
524
+ // Can only determine if is SVG after mounted
525
+ isElementSVG : false
526
+
513
527
} ;
514
528
} ,
515
529
@@ -667,17 +681,33 @@ module.exports = React.createClass({
667
681
// without worrying about whether or not it is relatively or absolutely positioned.
668
682
// If the item you are dragging already has a transform set, wrap it in a <span> so <Draggable>
669
683
// has a clean slate.
670
- var transform = createCSSTransform ( {
671
- // Set left if horizontal drag is enabled
672
- x : canDragX ( this ) ?
673
- this . state . clientX :
674
- this . props . start . x ,
675
-
676
- // Set top if vertical drag is enabled
677
- y : canDragY ( this ) ?
678
- this . state . clientY :
679
- this . props . start . y
680
- } ) ;
684
+ var transform = this . state . isElementSVG ? null :
685
+ createCSSTransform ( {
686
+ // Set left if horizontal drag is enabled
687
+ x : canDragX ( this ) ?
688
+ this . state . clientX :
689
+ this . props . start . x ,
690
+
691
+ // Set top if vertical drag is enabled
692
+ y : canDragY ( this ) ?
693
+ this . state . clientY :
694
+ this . props . start . y
695
+ } ) ;
696
+
697
+
698
+ var svgTransform = ! this . state . isElementSVG ? null :
699
+ createSVGTransform ( {
700
+ // Set left if horizontal drag is enabled
701
+ x : canDragX ( this ) ?
702
+ this . state . clientX :
703
+ this . props . start . x ,
704
+
705
+ // Set top if vertical drag is enabled
706
+ y : canDragY ( this ) ?
707
+ this . state . clientY :
708
+ this . props . start . y
709
+ } ) ;
710
+
681
711
682
712
// Workaround IE pointer events; see #51
683
713
// https://github.com/mzabriskie/react-draggable/issues/51#issuecomment-103488278
@@ -701,6 +731,7 @@ module.exports = React.createClass({
701
731
// This makes it flexible to use whatever element is wanted (div, ul, etc)
702
732
return React . cloneElement ( React . Children . only ( this . props . children ) , {
703
733
style : style ,
734
+ transform : svgTransform ,
704
735
className : className ,
705
736
706
737
onMouseDown : this . onMouseDown ,
0 commit comments