Skip to content

Commit 035dd1e

Browse files
committed
fix(Interaction): resolve positioning issue in interaction calculation.
1 parent 019d99e commit 035dd1e

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

packages/drag-event-interactive/src/utils.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,19 @@ export interface Interaction {
3636
y: number;
3737
}
3838

39-
// // Returns a relative position of the pointer inside the node's bounding box
40-
// export const getRelativePosition = (node: HTMLDivElement, event: MouseEvent | TouchEvent): Interaction => {
41-
// const rect = node.getBoundingClientRect();
42-
43-
// // Get user's pointer position from `touches` array if it's a `TouchEvent`
44-
// const pointer = isTouch(event) ? event.touches[0] : (event as MouseEvent);
45-
46-
// return {
47-
// left: clamp((pointer.pageX - (rect.left + window.pageXOffset)) / rect.width),
48-
// top: clamp((pointer.pageY - (rect.top + window.pageYOffset)) / rect.height),
49-
// width: rect.width,
50-
// height: rect.height,
51-
// x: pointer.pageX - (rect.left + window.pageXOffset),
52-
// y: pointer.pageY - (rect.top + window.pageYOffset),
53-
// };
54-
// };
55-
5639
// Returns a relative position of the pointer inside the node's bounding box
5740
export const getRelativePosition = (node: HTMLDivElement, event: MouseEvent | TouchEvent): Interaction => {
5841
const rect = node.getBoundingClientRect();
59-
const pointer = isTouch(event) ? event.touches[0] : (event as MouseEvent);
6042

61-
const x = clamp(pointer.pageX - (rect.left + window.pageXOffset), 0, rect.width);
62-
const y = clamp(pointer.pageY - (rect.top + window.pageYOffset), 0, rect.height);
43+
// Get user's pointer position from `touches` array if it's a `TouchEvent`
44+
const pointer = isTouch(event) ? event.touches[0] : (event as MouseEvent);
6345

6446
return {
65-
left: x / rect.width,
66-
top: y / rect.height,
47+
left: clamp((pointer.pageX - (rect.left + window.pageXOffset)) / rect.width),
48+
top: clamp((pointer.pageY - (rect.top + window.pageYOffset)) / rect.height),
6749
width: rect.width,
6850
height: rect.height,
69-
x,
70-
y,
51+
x: pointer.pageX - (rect.left + window.pageXOffset),
52+
y: pointer.pageY - (rect.top + window.pageYOffset),
7153
};
7254
};

test/wheel.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ it('Wheel color=hsvaColor ', async () => {
4444
expect(handleChange).toHaveReturnedWith('#e6c300');
4545
});
4646

47-
it('Wheel mousedown onChange', async () => {
47+
it('Wheel mousedown onChange 2', async () => {
4848
const handleChange = jest.fn((color) => color.hex);
4949
const {
5050
container: { firstChild },

0 commit comments

Comments
 (0)