Problem/Motivation
This is something I initially brought up in #3180086: It should not be possible to have two dropdown menus appear at the same time within Olivero, but moving this to a separate issue as it does not need to obstruct the bug fix that is currently there.
This is what I reported:
With this solution the non-mouse user needs to explicitly close an expanded navigation item (or open a different navigation item) before advancing further if they don't want content to be obscured by the menu. Mouse users are not subjected to this step.
I'd recommend an approach similar to Drupal's dropbutton: add a blur event listener on all elements in that section of the menu. The handler will close the menu after a this.timerId = setTimeout(etc...) but that timeout will be cancelled if the next item that receives focs is also with that menu section. The focus listener would begin with something like window.clearTimeout(this.timerID); The focus/blur handlers can also be the mouseover/mouseout handlers, and the timeout delay provides a user-friendly "grace period" for pointers that inadvertently moved outside the mouseover area for a moment. An existing use of this pattern can be referenced in core/misc/dropbutton/dropbutton.es6.js
In a response, it was argued that this isn't an accessibility concern: #3180086: It should not be possible to have two dropdown menus appear at the same time within Olivero, and it's hard to objectively prove otherwise so this won't get tagged "accessibility". The impacts to UX and Drupal-sentiment still justify this being worked on. Closing secondary menus on blur is a popular enough pattern (I couldn't find a site without this pattern) that users come to expect it. While it's not particularly difficult for a user to adapt, every new micro-confusion unique to Drupal contributes to people souring on it.
Currently setting as stable blocker, but would be fine removing if this is brought to the UX meeting and they feel it is fine as-is.
Testing instructions
- Use the tab key to tab over to a menu parent item
- Open the menu parent by hitting enter on the button next to the menu item.
- Use tab to tab through the menu until you get to the next parent menu item.
- The previous menu should now close (this is the new behavior).
- Do the same thing again, but after tabbing down into the menu, start hitting SHIFT+TAB to tab backwards.
- Tab backwards to the previous menu parent. The menu that was open should now close.
Comment | File | Size | Author |
---|---|---|---|
#17 | interdiff-15-17.txt | 1.25 KB | mherchel |
#17 | 3191692-17-test-only-FAIL.patch | 1.1 KB | mherchel |
#17 | 3191692-17.patch | 6.12 KB | mherchel |
#15 | 3191692-15-test-only-FAIL.patch | 1.14 KB | mherchel |
#15 | 3191692-15.patch | 6.17 KB | mherchel |
Comments
Comment #2
mherchelBrought this to the Drupal UX meeting on Apr 2, 2021. They agreed that this should remain a stable blocker
Comment #3
mherchelThis is hopefully good to go!
The way that I implemented this:
Note that I also had to create a core polyfill for element.closest()
Tugboat URL: https://3191692-close-menu-blur-zvrn1odblbhsbnvlmbx2e6mh2mveyg2m.tugboat...
Comment #4
mherchelPolyfill is failing ESLint.
Also, I discovered that the blur event is occurring at mobile widths, too. This only needs to be at wide widths.
Comment #5
mherchelFixed the issues. The polyfill is now excluded from ESLint, and the blur event listener will check to see if it's in desktop nav state.
Tugboat URL stays the same: https://3191692-close-menu-blur-zvrn1odblbhsbnvlmbx2e6mh2mveyg2m.tugboat...
Comment #6
BhumikaVarshney CreditAttribution: BhumikaVarshney as a volunteer and at OpenSense Labs commentedApplied patch #5 and its working fine, the blur event is not occurring now.
Thanks.
Comment #7
mherchel@BhumikaVarshney No need to include screenshots of the patch applying. Drupal's automated tests will fail if the patch doesn't apply.
Also, it appears that you tested hover events as opposed to the blur event. Below is instructions for testing (and I'll update the issue description)
Comment #8
Gauravvvv CreditAttribution: Gauravvvv at OpenSense Labs commentedI have added before and after patch behavior screen recordings.
Now menu item gets closed when we move to the next menu item. I have tested this on live preview https://3191692-close-menu-blur-zvrn1odblbhsbnvlmbx2e6mh2mveyg2m.tugboat...
Moving to RTBC.
Comment #9
Gauravvvv CreditAttribution: Gauravvvv at OpenSense Labs commentedComment #10
lauriiiNow that we have some JS test coverage for the menus, could we add tests for this too?
Comment #11
mherchelTests added!
Comment #12
mherchelSome errors from prettier. Fixed, should work now.
Comment #13
mherchelTests are passing on my local, but not on Drupal CI :(
Comment #14
mherchelLets see if DrupalCI likes these tests better.
Comment #15
mherchelDarnit. Forgot to run prettier. New patches attached.
Comment #17
mherchelIf this doesn't work, I'm gonna flip my desk.
Comment #18
katannshaw CreditAttribution: katannshaw at Lullabot commentedI went through the "Testing instructions" listed in the OP on the Tugboat site and everything worked as expected as seen in this video:
Monosnap video: https://monosnap.com/direct/gGzK35KlSE1LdP30WJCwqrpdFQ13oG
Marking this RTBC.
Comment #19
lauriiiWe still need to open change record for the new polyfill similar to https://www.drupal.org/node/3159731 ✌️
Comment #20
mherchelChange record located at https://www.drupal.org/node/3211146
Comment #21
lauriiiCommitted 67e7662 and pushed to 9.2.x. Thanks!