Skip to content

Commit

Permalink
fix(reset-drag): resetState and then dragging positions wrong
Browse files Browse the repository at this point in the history
When using `resetState` and then dragging the position was off.
  • Loading branch information
idanen committed Dec 2, 2019
1 parent 2887e8e commit 3aae4a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/Draggable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export function useDraggable({

const resetState = useCallback(() => {
setDelta({ x: 0, y: 0 });
}, [setDelta]);
setPrev({ x: 0, y: 0 });
}, [setDelta, setPrev]);

return { targetRef, handleRef, getTargetProps, dragging, delta, resetState };
}
Expand Down
12 changes: 12 additions & 0 deletions src/lib/draggable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ describe('draggable', () => {
'translate(0px, 0px)'
);
});

describe('after reset', () => {
it('should start dragging from the original position', () => {
const { getByText, getByTestId, drag } = utils;
drag({ start: { clientX: 3, clientY: 5 }, delta: { x: 15, y: 20 } });
fireEvent.click(getByText(/reset/i));
drag({ start: { clientX: 3, clientY: 5 }, delta: { x: 15, y: 20 } });
expect(getByTestId('main').style.transform).to.equal(
'translate(15px, 20px)'
);
});
});
});

function Consumer(props) {
Expand Down

0 comments on commit 3aae4a9

Please sign in to comment.