From 7f397c76062784c6422fb2af4cbb04a055cc8034 Mon Sep 17 00:00:00 2001 From: Juno Nguyen Date: Sat, 30 Mar 2024 17:15:58 +0800 Subject: [PATCH] Implement handling of possible touch event --- package/ContextMenuProvider.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/package/ContextMenuProvider.tsx b/package/ContextMenuProvider.tsx index b635e95..d40d66f 100644 --- a/package/ContextMenuProvider.tsx +++ b/package/ContextMenuProvider.tsx @@ -52,12 +52,20 @@ export function ContextMenuProvider({ setData(null); }; - const showContextMenu: ShowContextMenuFunction = (content, options) => (e) => { + const showContextMenu: ShowContextMenuFunction = (content, options) => (e: React.MouseEvent | React.TouchEvent) => { e.preventDefault(); e.stopPropagation(); + + const x = "touches" in e + ? e.touches[0].clientX + : e.clientX; + const y = "touches" in e + ? e.touches[0].clientY + : e.clientY; + setData({ - x: e.clientX, - y: e.clientY, + x, + y, content, zIndex: options?.zIndex || zIndex, className: options?.className,