Skip to content

Commit f36b2b9

Browse files
committed
Move to React.cloneElement from React.addons.cloneWithProps.
This requires we import object-assign to merge styles.
1 parent efe3ab1 commit f36b2b9

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

lib/draggable.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var React = require('react');
44
var emptyFunction = function(){};
5-
var cloneWithProps = require('react/lib/cloneWithProps');
5+
var assign = require('object-assign');
66

77
function createUIEvent(draggable) {
88
return {
@@ -24,7 +24,7 @@ function canDragX(draggable) {
2424
}
2525

2626
function isFunction(func) {
27-
return typeof func === 'function' || Object.prototype.toString.call(func) === '[object Function]'
27+
return typeof func === 'function' || Object.prototype.toString.call(func) === '[object Function]';
2828
}
2929

3030
// @credits https://gist.github.com/rogozhnikoff/a43cfed27c41e4e68cdc
@@ -92,7 +92,7 @@ function getControlPosition(e) {
9292
return {
9393
clientX: position.clientX,
9494
clientY: position.clientY
95-
}
95+
};
9696
}
9797

9898
function addEvent(el, event, handler) {
@@ -446,15 +446,15 @@ module.exports = React.createClass({
446446
style.zIndex = this.props.zIndex;
447447
}
448448

449-
var className = 'react-draggable';
449+
var className = (this.props.children.props.className || '') + ' react-draggable';
450450
if (this.state.dragging) {
451451
className += ' react-draggable-dragging';
452452
}
453453

454454
// Reuse the child provided
455455
// This makes it flexible to use whatever element is wanted (div, ul, etc)
456-
return cloneWithProps(React.Children.only(this.props.children), {
457-
style: style,
456+
return React.cloneElement(React.Children.only(this.props.children), {
457+
style: assign({}, this.props.children.props.style || {}, style),
458458
className: className,
459459

460460
onMouseDown: this.handleDragStart,

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@
3434
"uglify-js": "^2.4.15",
3535
"webpack": "^1.3.2-beta8",
3636
"webpack-dev-server": "^1.4.7"
37+
},
38+
"dependencies": {
39+
"object-assign": "^2.0.0"
3740
}
3841
}

specs/draggable.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ describe('react-draggable', function () {
1616
expect(typeof drag.props.onStop).toEqual('function');
1717
});
1818

19+
it('should pass style and className properly from child', function () {
20+
var el = <Draggable><div className="foo" style={{color: 'black'}}/></Draggable>;
21+
var renderer = TestUtils.createRenderer();
22+
renderer.render(el);
23+
var output = renderer.getRenderOutput();
24+
25+
expect(output.props.className).toEqual('foo react-draggable');
26+
expect(output.props.style).toEqual({top: 0, left: 0, color: 'black'});
27+
});
28+
1929
it('should honor props', function () {
2030
function handleStart() {}
2131
function handleDrag() {}

0 commit comments

Comments
 (0)