简体   繁体   English

无头 UI 和 React 下拉菜单在单击时更改 position

[英]Headless UI & React Dropdown menu changing position when clicked

I want to create a dropdown menu, for which I'm using HeadlessUI on React with Tailwind.我想创建一个下拉菜单,为此我在 React with Tailwind 上使用 HeadlessUI。

The menu is working fine, except that when clicked on, the position of the menu changes, as in instead of dropping down perfectly from the menu button it overlays it (I don't know how to describe it exactly).菜单工作正常,除了单击时,菜单的 position 会发生变化,而不是从菜单按钮完全下拉,而是覆盖它(我不知道如何准确描述它)。

Here's a before and after, hope you can make out what I'm trying to say:这是之前和之后,希望你能明白我想说什么:

Before button is clicked After the button is clicked单击按钮前 单击按钮

The code for the dropdown menu:下拉菜单的代码:

function HomeMenu(props) {
return (
<Menu>
  <Menu.Button>{props.name}</Menu.Button>
  
  <Transition
    enter="transition duration-100 ease-out"
    enterFrom="transform scale-95 opacity-0"
    enterTo="transform scale-100 opacity-100"
    leave="transition duration-75 ease-out"
    leaveFrom="transform scale-100 opacity-100"
    leaveTo="transform scale-95 opacity-0"
  ></Transition>


  <Menu.Items>
    <Menu.Item>
      {({ active }) => (
        <a href="/account-settings">
          Account settings
        </a>
      )}
    </Menu.Item>
    <Menu.Item>
      {({ active }) => (
        <a href="/account-settings">
          Logout
        </a>
      )}
    </Menu.Item>
  </Menu.Items>
</Menu>
  )
  }

The div in which the menu is used:使用菜单的 div:

<div className="flex items-center justify-center p-6">
      <h1 className="text-6xl px-3 rounded-md shadow-lg py-1 bg-lmgray">
          NEW STREET JOURNAL
      </h1>
      <div className="absolute right-20 mt-2 px-5 rounded-md border-2 border-gray shadow-lg py-1 bg-lmgray" >
        <HomeMenu name={props.name}/>
      </div>

    </div>
<div className="absolute right-20 mt-2 px-5 rounded-md border-2 border-gray shadow-lg py-1 bg-lmgray" >
        <HomeMenu name={props.name}/>
      </div>

try to remove the classname absolute and try again尝试删除绝对类名并重试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM