Skip to content

Commit 3b60b76

Browse files
authored
Merge pull request #152 from JunoNgx/touch-event
Implement handling of possible touch event
2 parents c7a5d09 + 7f397c7 commit 3b60b76

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

package/ContextMenuProvider.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ export function ContextMenuProvider({
5252
setData(null);
5353
};
5454

55-
const showContextMenu: ShowContextMenuFunction = (content, options) => (e) => {
55+
const showContextMenu: ShowContextMenuFunction = (content, options) => (e: React.MouseEvent | React.TouchEvent) => {
5656
e.preventDefault();
5757
e.stopPropagation();
58+
59+
const x = "touches" in e
60+
? e.touches[0].clientX
61+
: e.clientX;
62+
const y = "touches" in e
63+
? e.touches[0].clientY
64+
: e.clientY;
65+
5866
setData({
59-
x: e.clientX,
60-
y: e.clientY,
67+
x,
68+
y,
6169
content,
6270
zIndex: options?.zIndex || zIndex,
6371
className: options?.className,

0 commit comments

Comments
 (0)