HeadlessUI 弹出框在移动设备上无法点击。

huangapple go评论83阅读模式
英文:

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:

&lt;Popover className=&quot;z-5 relative&quot;&gt;
  {({ open }) =&gt; (
    &lt;&gt;
      &lt;div className=&quot;relative z-10&quot;&gt;
        &lt;Popover.Button
          aria-label=&quot;Main menu&quot;
          className=&quot;text-stone-500 focus:outline-none&quot;
        &gt;
          &lt;div className=&quot;w-12 h-12&quot;&gt;
            &lt;Bars3Icon /&gt;
          &lt;/div&gt;
        &lt;/Popover.Button&gt;
      &lt;/div&gt;

      &lt;Transition
        as={Fragment}
        enter=&quot;transition ease-out duration-200&quot;
        enterFrom=&quot;opacity-0 -translate-y-1&quot;
        enterTo=&quot;opacity-100 translate-y-0&quot;
        leave=&quot;transition ease-in duration-150&quot;
        leaveFrom=&quot;opacity-100 translate-y-0&quot;
        leaveTo=&quot;opacity-0 -translate-y-1&quot;
      &gt;
        &lt;Popover.Panel className=&quot;absolute right-0 z-10 mt-2 w-[250px] transform drop-shadow-2xl md:w-[600px] bg-white&quot;&gt;
          Popup Menu
        &lt;/Popover.Panel&gt;
      &lt;/Transition&gt;
    &lt;/&gt;
  )}
&lt;/Popover&gt;

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: &quot;none&quot; }} to the div surrounding the menu icon, it started working again.

huangapple
  • 本文由 发表于 2023年5月30日 12:22:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76361610.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定