Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent focus behavior of the MenuItems component #3488

Open
lukejagodzinski opened this issue Sep 25, 2024 · 0 comments
Open

Inconsistent focus behavior of the MenuItems component #3488

lukejagodzinski opened this issue Sep 25, 2024 · 0 comments

Comments

@lukejagodzinski
Copy link

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

v2.1.8

What browser are you using?

Chrome Version 129.0.6668.58 (Official Build) (arm64)

Reproduction URL

https://codesandbox.io/p/devbox/5g77y7

Describe your issue

When opening (using keyboard) dropdown menu for the first and second time there is inconsistent focus behavior. After opening menu for the first time, neither of the items is focused. However, when I open it for the second time the first element gets focused.

I've included CodeSandBox reproduction but also pasting code and reproduction steps here.

<div className="flex flex-row w-full gap-2 justify-center items-center">
  <Button autoFocus className="border p-2 bg-gray-100">
    Before
  </Button>
  <Menu>
    <MenuButton className="border p-2 bg-gray-100">My account</MenuButton>
    <MenuItems anchor="bottom" className="bg-gray-100 border">
      <MenuItem className="data-[focus]:bg-gray-600 data-[focus]:text-white p-2">
        <div>Settings</div>
      </MenuItem>
      <MenuItem className="data-[focus]:bg-gray-600 data-[focus]:text-white p-2">
        <div>Support</div>
      </MenuItem>
      <MenuItem className="data-[focus]:bg-gray-600 data-[focus]:text-white p-2">
        <div>License</div>
      </MenuItem>
    </MenuItems>
  </Menu>
  <button className="border p-2 bg-gray-100">After</button>
</div>

Steps to reproduce:

  • Press TAB key
  • Press SPACE key to open menu (the first menu item not focused)
  • Press SPACE key to close menu
  • Press SPACE key to open menu (the first menu item focused)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant