callumbwhyte / meganav

A flexible, draggable link picker for constructing site navigation menus in Umbraco
MIT License
35 stars 34 forks source link

Improve keyboard navigation #50

Open callumbwhyte opened 2 years ago

callumbwhyte commented 2 years ago

Now V2 / V3 is out, it would be awesome to improve the ability to navigate / tab around the Meganav in the backoffice with a keyboard. This will significantly improve both the accessibility and usability of the package.

Umbraco has come a long way with this in recent years and so most of the components being used work pretty well, just could be even better.

I can imagine there's several places where the tab index is off or triggers the wrong thing.

I'd love to see keyboard shortcuts for:

Marking this as "help wanted" to see if any helpful people out there want to have a go 😎

eden-jh commented 2 years ago

I tested this with a keyboard and poked around in inspector. I can confirm that there's currently no way to reorder items with the keyboard, but the controls use <button> elements so other functionality is either already keyboard accessible or has more easily-fixable issues:

When you say keyboard shortcuts, do you mean something like a hotkey to a specific functionality (like using letter keys with a modifier key)? If so, that's probably unnecessary for accessibility. (Some combination of tab/shift+tab, space/enter, and arrow keys should be sufficient.)

eden-jh commented 2 years ago

Oh, I forgot one thing. If I recall correctly, the visibility toggle needs a state so screen reader users will know whether it's active or not. aria-pressed is probably fine.

callumbwhyte commented 2 years ago

Thank you so much @eden-jh, this is very thorough! Looks like we have some easily actionable items which is great.

I’ve taken a look at the item actions being visible on focus, I believe we already have most of the styles required for this we’re just missing a tabindex on the outer nav item and the actions itself as they’re not inputs.

As for my initial comment about keyboard shortcuts, this wasn’t so much with accessibility in mind but for improving speed for power users. I think being able to add, edit, toggle collapsed / visible, for nav items with a hot key would be cool. Additionally indenting items via a hotkey. I’m not sure what best practice would be here, so as not to interfere with other browser functions or accessibility tools. I’m guessing Alt+something, and perhaps only when a specific item is in focus. Would love your ideas here.

Thanks again!

eden-jh commented 2 years ago

Ah, okay. Yeah, per WCAG 2.4.1 (Character Key Shortcuts) as long as there's a non-character modifier key included, shortcuts should not interfere with assistive technology.

As far as basic keyboard functionality for moving items, I did some research on accessible patterns for reordering, and I see two main implementations that could be useful here:

  1. Each menu item contains a toggle button that when pressed, allows reordering via arrow keys (once you've moved it where you want it, you press it again to turn the dragging/reordering off)
  2. Each menu item has a collapsible list of options for where it should be moved (up, down, inside of or outside of a specific parent item)

A version of approach 2 that requires you to re-open the menu after every move so you can choose "Move Up" a million times is not super usable, and I'm not sure it makes sense to keep the menu open as it's moved. Maybe including both approaches would be the most usable? A user can use the "Move into Submenu X" option to get a menu item into the right submenu, and then use the arrow keys to get it into the right position.

Some additional concerns for screen readers:

Here are some examples. Just as a note, there are two examples of approach 1 here that don't have the interaction mode issue, but they both use a listbox role which is not appropriate for the nav editor: