3.2.0 Breaking Change: Drag Callbacks
See original GitHub issueIt appears there was an inadvertent breaking change in 3.2.0 relating to https://github.com/mzabriskie/react-draggable/pull/361.
Prior to 3.2.0, if a defaultPosition were present, it became the x
and y
present in the callback on the initial drag and subsequent to that.
In 3.2.0, the x
and y
received in the callback is relative to the defaultPosition already passed. So if you pass a defaultPosition
of x: 100, y:100
and initiateonDragStart
, the callback will contain {x: 0, y: 0}
in the data. This makes sense if you considerdefaultPosition
to be something more likeinitialOffset
, and is required if your offset is something like, for example, {x: '10%', y: '10%'}
.
Ref: https://github.com/bokuweb/react-rnd/issues/437 and a broken build at https://circleci.com/gh/bokuweb/react-rnd/1340.
Next Steps
Our choices:
- Is there a way to keep the old “absolute” offsets in callbacks from <= 3.1.1?
- Percentage offsets will make this very difficult
- Release a major version instead?
- Drop the feature? A percentage-based default position can also be achieved by wrapping the
<Draggable>
in a div with atransform: translate(10%, 10%)
.
Ping @tnrich.
I’ve pulled 3.2.0 from npm and will be releasing a 3.2.1 with just the TS export fix.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
I think a new param works, perhaps
positionOffset
- makes it clear that you’re not pre-setting thestate
to something like{x: 100, y: 100}
, you’re offsetting the whole thing by some number or percentage and it doesn’t actually affect the internal state and doesn’t show up in callbacks.I’ve PR’d a first pass at doing this: https://github.com/mzabriskie/react-draggable/pull/393