Skip to content

Commit 960970f

Browse files
committed
Add possibility to specify starting position
1 parent 8d8ed66 commit 960970f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lib/draggable.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,25 @@ module.exports = React.createClass({
143143
*/
144144
grid: React.PropTypes.arrayOf(React.PropTypes.number),
145145

146+
/**
147+
* `start` specifies the x and y that the dragged item should start at
148+
*
149+
* Example:
150+
*
151+
* ```jsx
152+
* var App = React.createClass({
153+
* render: function () {
154+
* return (
155+
* <Draggable start={{x: 25, y: 25}}>
156+
* <div>I start with left: 25px; top: 25px;</div>
157+
* </Draggable>
158+
* );
159+
* }
160+
* });
161+
* ```
162+
*/
163+
start: React.PropTypes.object,
164+
146165
/**
147166
* `zIndex` specifies the zIndex to use while dragging.
148167
*
@@ -235,6 +254,10 @@ module.exports = React.createClass({
235254
handle: null,
236255
cancel: null,
237256
grid: null,
257+
start: {
258+
x: 0,
259+
y: 0
260+
},
238261
zIndex: NaN,
239262
onStart: emptyFunction,
240263
onDrag: emptyFunction,
@@ -254,7 +277,7 @@ module.exports = React.createClass({
254277
offsetX: 0, offsetY: 0,
255278

256279
// Current top/left of this.getDOMNode()
257-
clientX: 0, clientY: 0
280+
clientX: this.props.start.x, clientY: this.props.start.y
258281
};
259282
},
260283

0 commit comments

Comments
 (0)