question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Menu.Items with max height & keyboard navigation

See original GitHub issue

Hello there,

For a bit of context, we’re using the Menu component as a dropdown to list a number of projects for our users to choose from. The number of projects is entirely dynamic and variable, so they might have a choice between 3 projects or 30.

A simple way to tackle this would be to apply a max-height value and an overflow-y: auto to the Menu.Items component. This works very well when using the mouse to navigate the dropdown, I can easily scroll up & down in the container. However, when using the keyboard - ie tabbing to Menu.Button and pressing space or enter to open the dropdown and then using the up/down arrow keys - it turns out that the arrow keys themselves “don’t scroll the container”. So once you reach an item that is below the visible part of the container, you don’t actually see your selection as the scrollbar remains unmoved.

Is this a bug, a “missing” feature or am I abusing the component here a little?

I’ve checked the ListBox component example, which works perfectly with the up/down arrows in constrained height containers.

My gut feeling would be that Menu should work much in the same way in this regard, though I’m of course open to changing my mind if this is a conscious design choice.

Would appreciate your thoughts here.

PS, awesome work on the library guys, thank you for all your hard work. Can’t wait to see even more components. 👍

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
RobinMalfaitcommented, Feb 5, 2021

This should be fixed, and will be available in the next release. You can already try it using npm install @headlessui/react@dev or yarn add @headlessui/react@dev.

0reactions
barnabasmolnarcommented, Feb 5, 2021

Awesome Robin, cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building Accessible Menu Systems - Smashing Magazine
Navigation submenus (or "dropdowns" to some) work well with a mouse or by keyboard, but they're not so hot when it comes to...
Read more >
Accessible and Keyboard-Friendly Hamburger Menu + Slide ...
A live demo and tips on building an accessible hamburger menu that's keyboard-friendly and toggles a slide-out navigation panel.
Read more >
Getting ul height of bootstrap dropdown with max-height set ...
The left-most dropdown has a lot of items, enough to hit to max-height and trigger the scrollbars. The middle dropdown has only 5...
Read more >
Solution For Very Long Dropdown Menus - CSS-Tricks
Set a maximum height to the dropdowns; On hover, reveal the submenu; Calculate a speed multiplier based on the height of the submenu ......
Read more >
Olivero: Focused level-2 nav items should always be ... - Drupal
When navigating level-2 menu items with keyboard navigation, the focused items will not scroll into view as expected.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found