Problem/Motivation
When navigating level-2 menu items with keyboard navigation, the focused items will not scroll into view as expected.

See the "tabs with dropdowns" section of this Bootstrap documentation for an example of how this should work. Scroll so the menu toggle is at the bottom of the viewport, then open + tab through the nav items. The page will scroll as needed to make the focused item visible.
Steps to reproduce
Create a level-2 menu with many items, resize the browser so the height is not enough to display all items in that level-2 menu. Using keyboard only, open and tab through the level-2 menu options. Notice that the viewport will not scroll the focused items into view.
Note that in some instances, the first out-of-viewport item did get scrolled into focus, but the ones following it did not. This happens when the sticky header engages (demo in #9).
Proposed resolution
The solution isn't yet clear, but it doesn't seem like something that should require adding code to make it work. Scrolling focused items into view is default browser behavior (and can be seen in the Bootstrap example in Problem/Motivation). I suspect the issue has something to do with positioning related styles applied to the menu/items, which confuses the browser as to where the element is within the viewport.
How to test
- Either visit the tugboat link (https://3190120-menu-focus-syqxciq9xqqmexouh3gwu9elwn8tzxat.tugboat.qa/) or download the patch and create a level two menu with many items
- Make the your browser viewport wide, but short (shorter than the natural height of the level 2 navigation)
- Use keyboard navigation, and tab down into the level 2 navigation.
- Ensure that all of the focused navigation items are visible within the viewport (see animated gif below)

| Comment | File | Size | Author |
|---|---|---|---|
| #62 | interdiff.txt | 4.25 KB | lauriii |
| #56 | Screen Shot 2021-05-07 at 9.47.03 AM.png | 21.97 KB | andy-blum |
| #56 | Screen Recording 2021-05-07 at 9.43.31 AM.mov | 3.39 MB | andy-blum |
| #55 | interdiff-29-55.txt | 8.42 KB | mherchel |
| #55 | 3190120-55.patch | 17.5 KB | mherchel |
Comments
Comment #2
andrewmacpherson commentedGood find. I think we may have noticed this before, but it wasn't captured in an issue.
I replicated it with the demo content at https://lb.cm/olivero. Their are 10 links under "webforms", and you can experience the problem if your viewport is less than approx 750px tall.
An 11-inch Macbook Air from 2017 has 768 CSS pixels height when using the browser full screen, iirc? My old laptop has a 1366x768 screen, so I'll check it on that.
10 links in the submenu is a very reasonable scenario for sites, so this certainly isn't an edge case bug.
Comment #3
andrewmacpherson commentedPromoting to major/blocker. This is certainly a failure of WCAG SC 2.4.7 Focus Visible at level AA, and I think it can easily be classed as a failure of SC 2.1.1 Keyboard at level A.
Comment #4
mherchelGood catch. I've played around in my browser and we can fix this by setting the submenu to something like
max-height: calc(100vh - <header height>; overflow: auto;.Patch coming shortly.
Comment #5
mherchelPatch attached.
Comment #6
djsagar commentedHi @mherchel,
patch is working fine and resolving issue but it's removing the menu level arrow.
Please have a look.
Thanks!
Comment #7
djsagar commentedThis is because of
overflow: auto;Can you have look into this and provide better preview>Thanks!
Comment #8
andrewmacpherson commentedAbout the approach in comments 4 and 5:
I think the approach in #4 might work okay for pointer users and keyboard users, but it could still be awkward for other interaction methods. I'm not sure if overflow containers are easy or hard to use with speech control, so I'll ask in some a11y chat rooms.
It doesn't follow the proposed resolution from @bnjmnm. It's still worth trying other approaches. I think it would be preferable to get the page to scroll, rather than create a scrolling container on the sub-nav list.
Comment #9
andrewmacpherson commentedExpanding on the steps to reproduce:
Yes, I replicated this too! The sticky header feature is, er, implicated. It took a few attempts with different browser window sizes, but I managed to make it happen. I've recorded a demo video, and here are the things to watch for...
The experience may vary in other browsers, because their scrolling behaviour differs when focus crosses the viewport edge. Firefox scrolls the viewport just enough to bring an item into the viewport; other browsers scroll by different amounts.
Comment #10
andrewmacpherson commentedI think it's worth postponing this until we've implemented the new plan in #3186349-9: Major accessibility problems with Olivero header show/hide feature. The sticky header behaviour is partly to blame for the problem here; specifically, the way the sticky behaviour kicks in without the user asking for it.
Feel free to to keep experimenting here though! We'll still need to make this robust enough for the situation when the user has opted-in to a sticky header.
But let's not commit anything here until the other issue has been addressed. Noting this in the issue summary.
Comment #11
mherchel#3186349: Major accessibility problems with Olivero header show/hide feature is now committed. We should be able to actively work on this.
Comment #12
mherchelComment #13
mherchelNew patch attached. I really like my solution here. Movie included.
Tugboat link: coming soon
Comment #14
mherchelHmmm... this solution actually needs some work. We're missing the little carrot.

Comment #15
mherchelComment #16
mherchelFix to carrot is added (I moved it outside of the container).
Video (coming soon)
Tugboat: https://3190120-menu-focus-syqxciq9xqqmexouh3gwu9elwn8tzxat.tugboat.qa/
Comment #17
mherchelDemo video
Comment #18
karingI just navigated my way through the Tugboat demo -> and confirmed I was able to get through the dropdown menu: Webform using key board only. This is really cool.
- scrolling ✅
- carrot ✅
- tab/enter and arrow keys ✅
Comment #19
mherchelComment #20
andyf commentedWorks for me in Chrome 89 and FF 87:
Chrome: https://www.loom.com/share/711bd4896e6444a1a5219d14cb7ba1bb
FF: https://www.loom.com/share/0827807debf44b3e96d59bbd3ac928fa
I did notice that in FF I could select the whole submenu container (see about 20s into the video) which lets me scroll the submenu with the arrow keys, while Chrome just jumps to the first element (but you can still control the submenu scrolling with arrow keys).
Comment #21
baysaa commentedWorks for me on the tugboat link above. Tested on Firefox 86. Setting to RTBC
Comment #22
lauriiiComment #23
pragati_kanade commentedComment #24
pragati_kanade commentedComment #25
pragati_kanade commentedComment #26
kapilv commentedComment #27
kapilv commentedComment #28
mherchelThe git conflict was in one of the generated files (core/themes/olivero/js/second-level-navigation.js), so setting this back to RTBC.
Comment #29
mherchelPatch updated. The JS was failing because of a variable name change in #3208286: Olivero: "topLevelMenuITem" variable should be "topLevelMenuItem"
Comment #31
mherchelPrevious test failure appears to be unrelated. Queuing up another test.
Comment #32
mherchel@lauriii wants some UX people to give a 👍 on this solution before committing.
Comment #33
mherchelComment #34
mherchelFor the UX folks who are reviewing this, you can demo a tugboat preview of this at https://3190120-menu-focus-syqxciq9xqqmexouh3gwu9elwn8tzxat.tugboat.qa/
and a quick explanation movie is attached.
Comment #35
benjifisherI can speak as a member of the Usability team. (This does not mean that I am a UX expert.)
I did a little testing with FireFox/Linux and the patch in #29.
I noticed the same effect that @AndyF (hi!) pointed out in #20: after opening the level-2 menu, the first tab selects the container. This is a little confusing: what is the point of selecting the container?
With the container selected, I can scroll the sub-menu with the cursor keys. Regardless of scrolling, the first tab selects the first menu item and makes it visible.
With the container selected, or with one of the sub-menu items selected, if I hit
<Esc>, then the container closes and nothing has focus. (Or the focused element is not visible?) From here,<Tab>moves focus to the search icon and<S-Tab>shifts focus to the down-caret. When nothing has focus, the up/down cursors have no effect.With the container selected, or with one of the sub-menu items selected, the up/down cursor keys scroll the sub-menu instead of the whole page. I am not sure how serious this problem is. I can tab out of the sub-menu, or
<Esc>followed by<Tab>or<S-Tab>, and then scroll the window. But I cannot scroll the window while the sub-menu is open. (Why would I want to?<shrug />)Once I select an item on the sub-menu, I can scroll the container with the cursor keys, and if I scroll far enough, then the focused item is no longer in view. The same thing happens (scrolling the whole window) with the Bootstrap page mentioned in the issue summary.
Conclusion:
<Esc>looks like a bug. It happens with Chromium, too.On the plus side,
<Esc>has mostly the expected effect. Compare that to the Bootstrap page, where<Esc>does not do anything.If (5) is too hard, then I will be satisfied if you can fix (3). I will be even happier if you can fix (2) and (4) along with (3).
Comment #36
benjifisherI did some more testing with Chromium, and I noticed a problem.
In Firefox, when the container or a sub-menu item has the focus, I can use the up/down keys to scroll the container. When I get to the top or bottom, the key has no effect.
With Chromium, once I scroll to the bottom, the down key makes the page scroll. And then the header menu goes away. I can continue to scroll down, but the up key has no effect. I can get the submenu back with
<Tab>or<S-Tab>or by shifting focus away from Chromium or back again.I guess this is the reason you scroll just the container, not the window.
This problem is serious enough that I am setting the issue back to NW.
Comment #37
mherchelThe behaviors you are describing are the default overflow behaviors of the browser. We can change these, but we one million times should not for both accessibility and performance reasons.
I'll attend the meeting on Friday and can give a little more context.
Comment #38
bnjmnmBenji's feedback in #35-#36 is great. Here's my preference regarding how to proceed.
<Esc>documented in #36. This appears to be a pre-existing problem and not a regression introduced by this issue. Tagging "needs followup" for that. Looks like the menu disclosure button gets focused if the menu is closed via<Esc>, but the outline is not visible.Comment #39
abhijith s commentedApplied patch #29 and it worked fine.Added screen recording.
RTBC +1
Comment #40
mherchelWe ran this by the UX meetup at #3208186: Drupal Usability Meeting 2021-04-23. The consensus was that this solution is good from a UX perspective.
Opened followup issue #3210434: Olivero: Header menu should not close if menu item has focus
Comment #41
bnjmnmA followup is needed for the esc behavior in #35.3 as well. That's a stable blocker as it violates Focus Visible. It shouldn't be too difficult as the correct element gets focused, it's just the outline doesn't seem to show up if it was focused as a result of escaping out of the dropdown.
Comment #42
mherchelFollowup opened #3210443: Olivero: Focus after submenu close via ESC key.
Note that the body element gets focus, so it's not a violation as I understand it. We can discuss further in the issue.
Comment #43
katannshaw commentedI checked the Tugboat site at https://3190120-menu-focus-syqxciq9xqqmexouh3gwu9elwn8tzxat.tugboat.qa and it worked fine. I recorded the following video screencasts:
RTBC +2
Comment #44
gauravvvv commentedNow focused items are in the viewport. Adding after-patch screen recording for reference.
Moving to RTBC.
Comment #45
mherchelStill need to get sign off from @bnjmnm (or another core accessibility maintainer)
Comment #46
benjifisherI am adding an issue tag for #45.
This issue already has a tag for a follow-up issue. That was added in #38, and two issues were cited in #40 and #42. I think we can remove the tag now, but I hope someone else will confirm.
Comment #47
mherchelI'm confused. Do you want an accessibility review from another accessibility maintainer?
Do we need to open up any additional followup issues?
Comment #48
benjifisher@mherchel:
The "Needs accessibility review" issue tag is just a way of indicating what you said in #45:
At least, that is how we use the "Needs usability review" tag.
One practical reason for adding the issue tag: now that the issue is RTBC, it is on the queue for the core committers. They will quickly see the tag and decide whether to start reviewing the issue. If we just mention it in Comment #45, then they will not know that until they get to that comment.
I did not add the "Needs followup" tag, I just brought attention to it. If you are confident that we have all the follow-ups we need, then you can remove the tag. If you are not confident, then maybe @bnjmnm can check, since he is the one who added it.
Comment #49
mherchelMakes sense. Thanks for the followup :D
Comment #50
bnjmnmRemoving the accessibility review tag as a maintainer. This addresses the focus visible problem, as well as the risk of some menu items not being available to any users on low-height viewports.
While the ideal solution would be having the dropdowns work with focus/scroll position the same way it would with a select element, this is an acceptable solution as:
Comment #51
bnjmnmUpdated the IS for followup #3210443: Olivero: Focus after submenu close via ESC key and added as a stable blocker
Comment #54
mhercheltest failures are unrelated. Setting back to RTBC.
Comment #55
mherchelSpelled "carrot" like the vegetable as opposed to the character.
Comment #56
andy-blumPatch works. Caret is present and items scroll into view as they're tabbed to.
Screenshot/cast attached, moving to RTBC.
Comment #57
benjifisherIf I load the interdiff from #55 in my web browser, I see
Looking at the patch in a text editor, I see
From the comment, I thought it was going to replace "carrot" with "caret", but it looks like the patch replaces "carrot" with an emoji.
Comment #58
mherchelyeah, the emoji reduces the need to know how to spell carrot vs caret (I didn't personally know this).
Emoji's in selectors are 100% valid (including IE11).
Its honestly just a little levity being added to the theme :)
Comment #61
mherchelTugboat URL for the #55 patch: https://3190120-menu-focus-2-mlnvidzs0qvqjkg5gsceuuuxu14f2h0v.tugboat.qa/
Comment #62
lauriiiFixed few code style nit picks. Interdiff attached here.
Committed 11af82a and pushed to 9.3.x and 9.2.x. Thanks!