英文:
HeadlessUI popover not tappable on mobile devices
问题
我在尝试使用移动设备或在Chrome设备工具栏中查看页面时,尝试点击HeadlessUI弹出菜单时遇到问题。在常规桌面浏览器模式下似乎可以正常工作。我花了几个小时来测试和简化代码,将其简化为在代码沙箱中的最简形式,可以在此处查看和演示:
https://codesandbox.io/s/react-tailwind-rive-animation-tap-issue-bxlt95?file=/src/App.js
以下是代码的相关部分:
<Popover className="z-5 relative">
{({ open }) => (
<>
<div className="relative z-10">
<Popover.Button
aria-label="Main menu"
className="text-stone-500 focus:outline-none"
>
<div className="w-12 h-12">
<Bars3Icon />
</div>
</Popover.Button>
</div>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0 -translate-y-1"
enterTo="opacity-100 translate-y-0"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 -translate-y-1"
>
<Popover.Panel className="absolute right-0 z-10 mt-2 w-[250px] transform drop-shadow-2xl md:w-[600px] bg-white">
Popup Menu
</Popover.Panel>
</Transition>
</>
)}
</Popover>
我正在尝试弄清楚是什么阻止菜单在点击时弹出,就像在浏览器中通常情况下一样。提前感谢您的帮助。
英文:
I'm having a problem trying to tap on a HeadlessUI popover menu when using a mobile device or when viewing a page in the Chrome device toolbar. It seems to work fine in regular desktop browser mode. I've spent several hours testing and distilling the code into its simplest form inside a code sandbox, which can be viewed and demonstrated here:
https://codesandbox.io/s/react-tailwind-rive-animation-tap-issue-bxlt95?file=/src/App.js
Here is the relevant portion of the code:
<Popover className="z-5 relative">
{({ open }) => (
<>
<div className="relative z-10">
<Popover.Button
aria-label="Main menu"
className="text-stone-500 focus:outline-none"
>
<div className="w-12 h-12">
<Bars3Icon />
</div>
</Popover.Button>
</div>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0 -translate-y-1"
enterTo="opacity-100 translate-y-0"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 -translate-y-1"
>
<Popover.Panel className="absolute right-0 z-10 mt-2 w-[250px] transform drop-shadow-2xl md:w-[600px] bg-white">
Popup Menu
</Popover.Panel>
</Transition>
</>
)}
</Popover>
I'm trying to figure out what is preventing the menu from popping up when tapped as it usually does in the browser. Thanks in advance for your help.
答案1
得分: 0
有人在另一个论坛上先前回答了我的问题。问题是我的 div 元素捕获了触摸事件,而没有将其传递给动画。通过将 style={{ pointerEvents: "none" }}
添加到围绕菜单图标的 div 元素中,它重新开始正常工作。
英文:
Someone answered my question earlier in another forum. The problem was that my div was capturing the tap and not passing it down to the animation. By adding style={{ pointerEvents: "none" }}
to the div surrounding the menu icon, it started working again.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论