@@ -7,7 +7,7 @@ import {createCSSTransform, createSVGTransform} from './utils/domFns';
7
7
import { canDragX , canDragY , createDraggableData , getBoundPosition } from './utils/positionFns' ;
8
8
import { dontSetMe } from './utils/shims' ;
9
9
import DraggableCore from './DraggableCore' ;
10
- import type { ControlPosition , DraggableBounds , DraggableCoreProps } from './DraggableCore' ;
10
+ import type { ControlPosition , DefaultControlPosition , DraggableBounds , DraggableCoreProps } from './DraggableCore' ;
11
11
import log from './utils/log' ;
12
12
import type { DraggableEventHandler } from './utils/types' ;
13
13
import type { Element as ReactElement } from 'react' ;
@@ -27,7 +27,7 @@ export type DraggableProps = {
27
27
defaultClassName : string ,
28
28
defaultClassNameDragging : string ,
29
29
defaultClassNameDragged : string ,
30
- defaultPosition : ControlPosition ,
30
+ defaultPosition : DefaultControlPosition ,
31
31
position : ControlPosition ,
32
32
scale : number
33
33
} ;
@@ -118,8 +118,8 @@ export default class Draggable extends React.Component<DraggableProps, Draggable
118
118
* ```
119
119
*/
120
120
defaultPosition : PropTypes . shape ( {
121
- x : PropTypes . number ,
122
- y : PropTypes . number
121
+ x : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ,
122
+ y : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] )
123
123
} ) ,
124
124
125
125
/**
@@ -178,8 +178,8 @@ export default class Draggable extends React.Component<DraggableProps, Draggable
178
178
dragged : false ,
179
179
180
180
// Current transform x and y.
181
- x : props . position ? props . position . x : props . defaultPosition . x ,
182
- y : props . position ? props . position . y : props . defaultPosition . y ,
181
+ x : props . position ? props . position . x : 0 ,
182
+ y : props . position ? props . position . y : 0 ,
183
183
184
184
// Used for compensating for out-of-bounds drags
185
185
slackX : 0 , slackY : 0 ,
@@ -311,7 +311,7 @@ export default class Draggable extends React.Component<DraggableProps, Draggable
311
311
const controlled = Boolean ( this . props . position ) ;
312
312
const draggable = ! controlled || this . state . dragging ;
313
313
314
- const position = this . props . position || this . props . defaultPosition ;
314
+ const position = this . props . position || { x : 0 , y : 0 } ;
315
315
const transformOpts = {
316
316
// Set left if horizontal drag is enabled
317
317
x : canDragX ( this ) && draggable ?
@@ -326,13 +326,13 @@ export default class Draggable extends React.Component<DraggableProps, Draggable
326
326
327
327
// If this element was SVG, we use the `transform` attribute.
328
328
if ( this . state . isElementSVG ) {
329
- svgTransform = createSVGTransform ( transformOpts ) ;
329
+ svgTransform = createSVGTransform ( transformOpts , this . props . defaultPosition ) ;
330
330
} else {
331
331
// Add a CSS transform to move the element around. This allows us to move the element around
332
332
// without worrying about whether or not it is relatively or absolutely positioned.
333
333
// If the item you are dragging already has a transform set, wrap it in a <span> so <Draggable>
334
334
// has a clean slate.
335
- style = createCSSTransform ( transformOpts ) ;
335
+ style = createCSSTransform ( transformOpts , this . props . defaultPosition ) ;
336
336
}
337
337
338
338
const {
0 commit comments