Problem/Motivation
In #3427659: Implement drawer functionality the initial work to have the drawer working has implemented the basic functionality. This issue is to verify it works with keyboard and otherwise work on the remaining tasks.
Key Points:
- Arrow Keys. inner menu items
- Tab/Shift Tab
- Escape
- Home / End
https://www.w3.org/WAI/ARIA/apg/patterns/menubar/examples/menubar-naviga...
Note: extended scope: 'character'.
| Key | Function |
|---|---|
| Space Enter |
|
| Down Arrow |
|
| Up Arrow |
|
| Right Arrow | Opens submenu and moves focus to first item in the submenu. |
| Left Arrow | Opens submenu and moves focus to last item in the submenu. |
| Home | Moves focus to first item in the menubar. |
| End | Moves focus to last item in the menubar. |
| Character |
|
| Key | Function |
|---|---|
| Space Enter |
|
| Escape |
|
| Right Arrow |
|
| Left Arrow |
|
| Down Arrow |
|
| Up Arrow |
|
| Home | Moves focus to the first item in the submenu. |
| End | Moves focus to the last item in the submenu. |
| Character |
|
WCAG success criteria
Proposed resolution
TBD
Remaining tasks
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #55 | Screenshot 2024-04-15 at 3.51.14 PM.png | 132.82 KB | bronzehedwick |
| #43 | stuck.mp4 | 849.18 KB | rkoller |
| #36 | safari.mp4 | 193.83 KB | rkoller |
| #9 | Navigation_expanded.mp4 | 445.69 KB | ahsannazir |
| #9 | Navigation_collapsed.mp4 | 236.05 KB | ahsannazir |
Issue fork navigation-3436130
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ckrinaI forgot to postpone it.
Comment #3
ckrinaUn-postponing since #3427659: Implement drawer functionality has been merged in. This is ready to start the work.
Comment #4
bronzehedwickComment #7
bronzehedwickComment #8
bronzehedwickComment #9
ahsannazir commentedThe Keyboard navigation is working as expected. Attaching the screen capture for the reference
Comment #10
rkollerOne detail in the context of keyboard navigation i wonder if it would make sense to add is the ability to close the drawer by pressing the esc key. at the moment you have to tab through the entire sub menu, the configuration sub menu requires quite a few tabs to get out.
On a side note not directly related to keyboard navigation but i've noticed while testing that several menu items miss focus outlines. without any patches applied to the 1.x-dev branch of the navigation module the logo, sub sub menus (for example the menu items underneath configuration -> system), and the sub menu items (view profile, edit profile and log out) for the logged in user are not visible. the username isnt tab-able at all, only clickable by mouse.
the navigation itself, except the aforementioned menu item for the user name is correctly tab-able and all sub menus and sub-sub menus are expandable and collapsible by space and return as well as VO-space with voiceover active (with collapsed as well as expanded sidebar).
Comment #11
bronzehedwick@rkoller Agreed on Esc. I'm following the W3C guidelines, which also includes patterns for arrow key navigation, Home and End.
Regarding the items that are not keyboard navigable, thanks for spotting! I'll look into that.
Comment #13
silviu s. commentedI added ESC to close the sub-menu.
Comment #14
silviu s. commentedComment #15
bronzehedwickThanks for the suggestion @silviu-s. As mentioned previously in the comment thread, I am working on this, and will open an MR to review with everything listed. As a point of process, an issue should not transition to "Needs Review" until all aspects of the scope are addressed.
Comment #16
skaughtI think we need some clear guide for when Arrow Keys Vs Tabbing & Escape should be working as the collection of actions that need to be this ticket.
Comment #17
skaughtComment #18
skaughtComment #19
skaughtComment #20
skaughtComment #21
skaughtComment #22
bronzehedwickThanks for adding that @skaught! That table is what I'm going on.
Comment #23
bronzehedwickOne change from the table above I think should be made is reversing the Up/Down and Left/Right arrow functions. The W3C example is a horizontal menu, and this is a vertical menu.
Comment #25
bronzehedwickI added code to handle keyboard navigation, patterned off the W3C guidelines outlined in the ticket description.
Comment #26
rkollerComment #27
rkollerbased on #23 i've updated the issue summary
Menu bar:
space/enter :
works
down arrow:
fails - the down arrow jumps not to the next top level menu item instead it jumps to the next top level menu item that has a submenu and is expandable. if you tab to a top level menu item that has no sub menu item the down button has no effect and is unresponsive
works - if i reach the
usernameat the bottom and press the down key another time theshortcutstop level menu item is in focus nextup arrow:
fails - the up arrow jumps not to the next top level menu items instead it jumps to the next top level menu item that has a submenu and is expandable. if you tab to a top level menu item that has no sub menu item the up button has no effect and is unresponsive
works - if i reach
shortcutsat the top and press the up key another time theusernametop level menu item is in focus nextright arrow:
fail - the drawer expands but the first sub menu item is not getting into focus
fail - in addition try the following. get the
reportstop level menu item into focus, press space, the drawer forreportsexpands, press now the up key andconfigurationgets into focus, press now the right arrow, theconfigurationdrawer opens underneath the still open reports drawerleft arrow
fail(?) - if the top level menu item is collapsed and you press the left arrow nothing happens, while if the drawer is expanded and you press left the drawer closes. but the desired "if you press the left arrow and the drawer opens and you get the last sub menu item into focus" doesnt happen here.
home
works -
ctrl fn leftjumps toshortscutson the macend
works -
ctrl fn rightjumps to theusernameon the maccharacter
fails - i have content in focus and press
mas well asM, no reaction. ahhhh just noticed. it has the same problem like the up and down button the character applies only to top level menu items that have a submenu. thereformhad no effect. if i typesi first jump toshortcutsif i press is another time i jump tostructure.Submenu:
Space/Enter:
fails - if you press space or return on a parent the focus remains on the parent instead of moving to the first item in the submenu
works - pressing space or return on menu items without a submenu forwards to the linked page
esc
works - closes drawer and moves focus to the parent top level menu item that opened the collapsed drawer
Right arrow:
fails - within the
configurationsubmenu for example when the focus is on system and you press the right button nothing happensfails - if you are in the
structuresubmenu and you have themedia typesmenu item in focus and press the right button nothing happensLeft arrow:
works (?): if the
block typesmenu item is in focus understructureand you press the left buttonstructuregets into focus but the focus isnt moving to the previous top level menu item in the menu barfail (?) if a sub sub menu item is in focus and you press the left key not the parent sub menu item gets into focus but the parent top level menu item
down arrow:
fail - it only works for the
configurationsubmenu, which is the only that consists of menu items with sub menus. that way i am able to move down and afterworkflowi get back up topeopleup arrow
fail - it only work for the
configurationsubmenu, which is the only that consists of menu items with sub menus. that way i am able to move up and afterpeoplei get back down toworkflowhome
works -
ctrl fn leftjumps toshortscutson the macend
works -
ctrl fn rightjumps to theusernameon the maccharacter
fails - in submenus characters dont work at all not even for sub menu items that contain another submenu
a few more details i've noticed:
the menu item for
shorcutsin the drawer is not reachable by keyboard but only by the mouse cursor. same for theusernamemenu item in theusernamedrawer, plusview profile,edit profile, andlogoutare missing the focus outline there. same for the sub sub menu items in general, they are all also missing the focus outline.addendum: just one detail to add, while testing i thought the focus outline for 3rd level menu items was already added in one of the previous commits in this issue, but then wondered why all of a sudden it was gone again in my last tests of the day (tested this issue on different instances over the day). but when reading #3437696: Claro, Olivero and Umami hover/focus styles leak into the navigation now i realized that that https://www.drupal.org/files/issues/2024-04-02/umami-active.png was what i saw, which is a hover style leaking into the navigation on focus in my case (the instance i ran into this is using demo_umami).
Comment #28
rkollerComment #29
rkollerComment #30
mgiffordJust tagging it here.
Comment #31
bronzehedwickComment #32
bronzehedwickThanks for the review @rkoller. I pushed an update that should address the following.
There's some issues left, below.
Since this MR does improve the keyboard navigation, and fixing the issues above won't be insignificant, I propose we split the remaining items into a new ticket.
Comment #33
bronzehedwickComment #34
bronzehedwickHere's the follow up ticket https://www.drupal.org/project/navigation/issues/3440047
Comment #35
skaughtHave manually tested this. Is certainly worthy proof of concept and introduces needed javascript work that would be great for continued work around in beta phase, and for other to be able to also continue related work around in the active dev line!
note: some oddness in 3rd level menus between 'what i think i should be doing' between switching between needing to tab into 3rd item. This maybe what you are describing in 'leftover issue point1'.
Comment #36
rkollerthank you! I've quickly tested against the four points that got fixed in #32. in "general" they work but i've found some odd behavior:
1&2) yes in it general it works but the problems are:
3) for top level menu items moving by character works for sub menus it does now
4) works - the only odd thing pattern wise, similar to the mix of hover for top level menu items and click for sub menus is the fact that with left and right you are able to collapse and expand the drawer but within a drawer left and right have no effect and you have to press space on a sub menu.
update: oh @skaught already set it to rtbc while i was writing up my comment. due to the active trail shown in the video i would set it back to needs work. if you would move the work on that newly introduce behavior to the follow up as well then put the status back to rtbc.
Comment #37
skaughtno worry. pardon my excitement!
Comment #38
ckrinaThanks all for the reviews! We discussed yesterday in the call (that's why @SKAUGHT jumped in to help,- thanks!-) to try to get something here in soon and open issues for follow-ups, otherwise this MR will take too much time to get in. Reason 1: this is quite too big of a big change to have while we have the MR opened for core (hopefully tomorrow), and 2. this MR changes are already better than having nothing. So let's try to move from the classic Drupal mindset "things get in when they are perfect" and not try to solve all the things in this issue: any idea of which feedback could be moved into a follow-up? :)
Comment #39
bronzehedwickComment #40
bronzehedwickI pushed a fix for this. I think the issue is pressing right arrow on menu items that don't have popovers, which pushes focus to a hidden element, preventing other arrow movement until left arrow is pressed.
Comment #41
finnsky commentedGonna review now
Comment #42
rkollerthank you for the update @bronzehedwick. i've applied the latest changes but somehow i am still able to reproduce being stuck. somehow i am able to trigger the behavior faster when i hover and or click a top level menu so a drawer expands and collapses and after that i go on navigating up and down through the top level menu items. for the video i've activated the keyboard viewer so you are able to see my keyboard input. and in addition i see the following type error in the console:
hope that helps.
Comment #43
rkollerforgot to add the video. apologies :/
Comment #44
bronzehedwickLooks like the problem here is the hover. The hover effect is controlled in JavaScript, and has a delay on toggling (by design). The hover off is triggered when you hover over another menu item. That means that if you quickly hover over a few items, then move your mouse outside the menu drawer, the hovered items will stay hovered. This blocks arrow movement, unless you press arrow left to "dismiss" the (hidden) popover.
I haven't been able to reproduce the JS error @rkoller and @finnsky are seeing yet.
This is an architectural issue, and will probably require some larger refactoring to resolve.
I think this and the other remaining issues should be moved into the follow up ticket, to reduce churn while the core MR is being made. Does that make sense with what you are thinking @ckrina?
Comment #45
bronzehedwickPushed a fix for the inaccessible Shortcuts menu via arrow keys. Simple oversight, just needed to add
tabindex.Comment #46
ckrinaIt doesn't have to be all at the same issue, but yeah we'll open the MR to core hopefully today and if we don't get this in before it'll be a nightmare to try to solve the conflicts later on and we might have to pause it for 2 weeks. :)
Comment #47
bronzehedwickComment #48
bronzehedwickComment #49
bronzehedwickMoving to NR, given @ckrina's guidance, above. The follow up issues are below.
Comment #50
finnsky commentedI added an approach that, in my opinion, fits better here. Some problems that I tried to solve:
1. All keyboard events are controlled in one place. They are bubble so we can control them at the sidebar level using the current target.
2. I used https://www.npmjs.com/package/tabbable which is part of the Drupal library
3. I used the https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inert attribute to hide the submenu from focus
4. I used data-index-text in twig to reduce client calculation and search time
5. All menus at all levels use the same logic. Branching occurs only where it is necessary.
6. The logo and bottom button are also part of keyboard navigation, even if they are not part of the menu.
Currently we need to add a description of how the arrows behave when the third menu level has focus. Now the focus falls into a trap from which you can escape only to the first level
Comment #52
bronzehedwickHey @finnsky, thanks for this! Some things I noticed.
I would expect pressing arrow left (and maybe arrow right?) or Space to collapse the accordion, moving focus back to the top level of the accordion.
Comment #53
bronzehedwickComment #54
finnsky commented@bronzehedwick
Thank you for review! You are right!
I've managed initially how it requested in ticket. But seems logic which is fair for horizontal menu not really obvious here.
Now i added more realistic and obvious logic.
Also fixed focus trap on lower levels.
Please review.
Comment #55
bronzehedwickThanks @finnsky! Your updates addressed all my feedback.
There is one small, new regression, I think from the
1.xrebase. There's extra padding and grey bar below each third level accordion.This seems to be caused by the recently merged additional padding MR running up against the new styles.
One solution would be to change line 38 of
toolbar-menu.pcss.cssfrom:to:
Comment #56
bronzehedwickComment #57
finnsky commentedreverted height. it was experiment anyway.
Comment #58
katannshaw commentedAdded WCAG 2.2 success criteria.
Comment #59
bronzehedwick@finnsky that last commit fixed the issue. Thanks!
This approach also resolves the follow up issues, listed below.
Moving to RTBC.
Comment #60
ckrinaMoving to Needs work per the above feedback.
Comment #61
rkollerOne minor detail I've noticed, you are able to bypass the constraint to expand only a single submenu with a combination of arrow and tab key:
- expand the configuration submenu
- move to the people menu item and press space
- tab until you reach user interface
- press the right arrow
- tab until you reach media
- press the right arrow
That way you are able to have three sub menus expanded at the same time. if you try the same with only
tabandspace, only a single sub menu remains open. while when just use the four arrow key you are only able to move inbetween the sub sub menu items with arrow up and down of for example the expandedmediasubmenu.Comment #62
finnsky commented@rkoller i agree that this should be covered somehow.
But this one is good candidate for follow up.
Comment #63
finnsky commented@ckrina removed that not used code.
Comment #64
finnsky commentedI also think we need to rework current events system.
They should be better documented and all iterations click/hovers/keys should go in same manner.
Since only events cares globally about multiple things. EG
- Switch expand/collapse text
- Switch classes
- Controls sibling elements open/close
Comment #65
bronzehedwick@finnsky would this be appropriate for a follow up ticket?
Comment #66
finnsky commentedRE #65
Thank you!
Yes sure. Now all works.
But i guess all system needs some refactoring.
We have all features onboard. And globally nothing should changed. But we can improve code readability and documentation.
Comment #69
ckrinaMerged! Thanks all, navigating via keyboard is a great improvement for everybody.