Skip to content

Commit a8b5ccd

Browse files
committed
Merge pull request #101 from LevInteractive/master
fixed isElementSVG state property issue so it does not get overwritte…
2 parents 101d897 + 15a0964 commit a8b5ccd

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/draggable.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,13 @@ module.exports = React.createClass({
504504
onStart: emptyFunction,
505505
onDrag: emptyFunction,
506506
onStop: emptyFunction,
507-
onMouseDown: emptyFunction,
507+
onMouseDown: emptyFunction
508508
};
509509
},
510510

511511
getInitialState: function (props) {
512512
// Handle call from CWRP
513+
var currentState = this.state;
513514
props = props || this.props;
514515
return {
515516
// Whether or not we are currently dragging.
@@ -521,9 +522,10 @@ module.exports = React.createClass({
521522
// Current transform x and y.
522523
clientX: props.start.x, clientY: props.start.y,
523524

524-
// Can only determine if is SVG after mounted
525-
isElementSVG: false
526-
525+
// Determines if the element is an svg or not. Default to false.
526+
isElementSVG: currentState && currentState.isElementSVG !== undefined ?
527+
currentState.isElementSVG :
528+
false
527529
};
528530
},
529531

@@ -682,7 +684,7 @@ module.exports = React.createClass({
682684
// If the item you are dragging already has a transform set, wrap it in a <span> so <Draggable>
683685
// has a clean slate.
684686
var transform = this.state.isElementSVG ? null :
685-
createCSSTransform({
687+
createCSSTransform({
686688
// Set left if horizontal drag is enabled
687689
x: canDragX(this) ?
688690
this.state.clientX :
@@ -695,6 +697,8 @@ module.exports = React.createClass({
695697
});
696698

697699

700+
// This is primarily for IE as it ignores the CSS transform applied above
701+
// and only respects the real transform attribute.
698702
var svgTransform = !this.state.isElementSVG ? null :
699703
createSVGTransform({
700704
// Set left if horizontal drag is enabled

specs/draggable.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('react-draggable', function () {
108108

109109
var style = node.getAttribute('style');
110110
expect(style.indexOf('transform: translate(100px, 100px);')).not.toEqual(-1);
111-
111+
112112
});
113113

114114
it('should detect if an element is instanceof SVGElement and set state.isElementSVG to true', function() {
@@ -150,7 +150,7 @@ describe('react-draggable', function () {
150150

151151
var transform = node.getAttribute('transform');
152152
expect(transform.indexOf('translate(100,100)')).not.toEqual(-1);
153-
153+
154154
});
155155

156156

0 commit comments

Comments
 (0)