Skip to content

Commit fa92acd

Browse files
authored
Merge pull request #52 from autifyhq/hiroki/fix-dragndrop-mouseevent
Drag and drop using MouseEventadd (Add clientX and clientY to the mousedown event)
2 parents 44e64d1 + 5481159 commit fa92acd

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

content/en/snippets/mouse/drag_and_drop_by_mouse_event.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,28 @@ if (!dropArea) {
2929
throw new Error("Element not found by selector:", dropAreaSelector);
3030
}
3131

32-
var coords = getCoordinates(dropArea);
32+
var dragCoords = getCoordinates(dragTarget)
33+
var dropCoords = getCoordinates(dropArea);
3334

34-
dragTarget.dispatchEvent(new MouseEvent("mousedown", { bubbles: true }));
35+
dragTarget.dispatchEvent(
36+
new MouseEvent("mousedown", {
37+
bubbles: true,
38+
clientX: dragCoords.x,
39+
clientY: dragCoords.y
40+
})
41+
);
3542
dragTarget.dispatchEvent(
3643
new MouseEvent("mousemove", {
3744
bubbles: true,
38-
clientX: coords.x,
39-
clientY: coords.y,
45+
clientX: dropCoords.x,
46+
clientY: dropCoords.y
4047
})
4148
);
4249
dragTarget.dispatchEvent(
4350
new MouseEvent("mouseup", {
4451
bubbles: true,
45-
clientX: coords.x,
46-
clientY: coords.y,
52+
clientX: dropCoords.x,
53+
clientY: dropCoords.y
4754
})
4855
);
4956

content/ja/snippets/mouse/drag_and_drop_by_mouse_event.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,28 @@ if (!dropArea) {
2929
throw new Error("Element not found by selector:", dropAreaSelector);
3030
}
3131

32-
var coords = getCoordinates(dropArea);
32+
var dragCoords = getCoordinates(dragTarget)
33+
var dropCoords = getCoordinates(dropArea);
3334

34-
dragTarget.dispatchEvent(new MouseEvent("mousedown", { bubbles: true }));
35+
dragTarget.dispatchEvent(
36+
new MouseEvent("mousedown", {
37+
bubbles: true,
38+
clientX: dragCoords.x,
39+
clientY: dragCoords.y
40+
})
41+
);
3542
dragTarget.dispatchEvent(
3643
new MouseEvent("mousemove", {
3744
bubbles: true,
38-
clientX: coords.x,
39-
clientY: coords.y,
45+
clientX: dropCoords.x,
46+
clientY: dropCoords.y
4047
})
4148
);
4249
dragTarget.dispatchEvent(
4350
new MouseEvent("mouseup", {
4451
bubbles: true,
45-
clientX: coords.x,
46-
clientY: coords.y,
52+
clientX: dropCoords.x,
53+
clientY: dropCoords.y
4754
})
4855
);
4956

0 commit comments

Comments
 (0)