[BUG] Box moves when resizing it
Overview of the problem
I'm using react-rnd version [10.1.3] (I've noticed that issue doesn't exist in 10.0.0 and starts happening in 10.1.0)
My browser is:
Chrome (79.0.3945.88) on macOS 10.14.6
Firefox (71.0)
Safari (13.0.4)
I am sure this issue is not a duplicate. Similar issue was fixed recently in #618, maybe its related, but its still reproducible in 10.1.3 Also, this issue was mentioned in last comment in this closed issue #526 but there was no update.
Reproduced project
https://codesandbox.io/s/elated-hypatia-bpvdh
Description

When resizing a box from left side (or top), entire box moves (only visually). It always happens every second resize. Temporary solution is to downgrade library to 10.0.0 but then I'm getting a bunch of warnings regarding deprecation of "componentWillMount". It doesn't trigger any drag event (so internally its still on old position, but visually it moved), and when you try to drag it - it moves back to original position instead
Steps to Reproduce
- Open codesanbox url
- Drag the box using left handle
- ???
- Profit
Expected behavior
Box should resize without changing its position
Actual behavior
Box moved
If you delete bounds prop, it works correctly !
Yes it does, but its not the solution the problem because I need bounds prop.
@turshija @yakupteke Thanks for your report. This issue has fixed. Please try latest version.
https://codesandbox.io/s/adoring-sea-vmogo
Try this will help you. Dont use onResizeStop to set the positions
<Rnd
bounds="window"
size={{ width: position.width, height: position.height }}
position={{ x: position.x, y: position.y }}
minWidth={minWidthDialog}
minHeight={minHeightDialog}
dragHandleClassName="draggable-title"
enableUserSelectHack={false}
onDragStop={onDragStop}
onResize={onResize}
>
onResize :
const onResize: RndResizeCallback = (_e, _direction, ref) => {
const { x, y } = ref.getBoundingClientRect();
const onResizePosition = {
x,
y,
width: ref.clientWidth,
height: ref.clientHeight,
};
setPosition(onResizePosition);
};
onDragStop :
const onDragStop: RndDragCallback = (_e, d) => {
setPosition(previous => ({ ...previous, x: d.x, y: d.y }));
};
@noffy-tech solution is what worked for me