From 8e2b43031cb9f81957fd9245b971606faa4979dd Mon Sep 17 00:00:00 2001 From: Segun Adebayo Date: Wed, 8 Nov 2023 19:35:23 +0000 Subject: [PATCH] fix(menu): menu link items not clicking on mobile --- .changeset/dull-berries-remember.md | 5 +++++ .../machines/combobox/src/combobox.connect.ts | 5 ----- packages/machines/menu/src/menu.connect.ts | 17 ++++------------- 3 files changed, 9 insertions(+), 18 deletions(-) create mode 100644 .changeset/dull-berries-remember.md diff --git a/.changeset/dull-berries-remember.md b/.changeset/dull-berries-remember.md new file mode 100644 index 0000000000..e8509193bf --- /dev/null +++ b/.changeset/dull-berries-remember.md @@ -0,0 +1,5 @@ +--- +"@zag-js/menu": patch +--- + +Fix issue issue where link is not clickable on mobile diff --git a/packages/machines/combobox/src/combobox.connect.ts b/packages/machines/combobox/src/combobox.connect.ts index 97a0bc6894..ed8d620bf5 100644 --- a/packages/machines/combobox/src/combobox.connect.ts +++ b/packages/machines/combobox/src/combobox.connect.ts @@ -309,11 +309,6 @@ export function connect( if (itemState.isDisabled || isContextMenuEvent(event)) return send({ type: "ITEM.CLICK", src: "pointerup", value }) }, - onAuxClick(event) { - if (itemState.isDisabled || isContextMenuEvent(event)) return - event.preventDefault() - send({ type: "ITEM.CLICK", src: "auxclick", value }) - }, }) }, diff --git a/packages/machines/menu/src/menu.connect.ts b/packages/machines/menu/src/menu.connect.ts index bfcbe8d9b4..3d21f95e29 100644 --- a/packages/machines/menu/src/menu.connect.ts +++ b/packages/machines/menu/src/menu.connect.ts @@ -88,12 +88,10 @@ export function connect(state: State, send: Send, normalize if (!isLeftClick(evt) || itemState.isDisabled) return const target = event.currentTarget send({ type: "ITEM_CLICK", src: "pointerup", target, id, closeOnSelect }) - }, - onAuxClick(event) { - if (itemState.isDisabled) return - event.preventDefault() - const target = event.currentTarget - send({ type: "ITEM_CLICK", src: "auxclick", target, id, closeOnSelect }) + // Fix issue where links don't get clicked in pointerup on touch devices + if (target.matches("a[href]") && event.pointerType === "touch") { + target.click() + } }, }) } @@ -375,13 +373,6 @@ export function connect(state: State, send: Send, normalize send({ type: "ITEM_CLICK", src: "pointerup", target, option, closeOnSelect }) onCheckedChange?.(!itemState.isChecked) }, - onAuxClick(event) { - if (disabled) return - event.preventDefault() - const target = event.currentTarget - send({ type: "ITEM_CLICK", src: "auxclick", target, option, closeOnSelect }) - onCheckedChange?.(!itemState.isChecked) - }, }), ) },