aratcliffe / Leaflet.contextmenu

A context menu for Leaflet.
MIT License
367 stars 107 forks source link

[accessibility] Delegate focus when context menu has been opened #135

Open Malvoz opened 3 years ago

Malvoz commented 3 years ago

It'd be a great accessibility improvement for keyboard users if focus was delegated to the context menu's container.

https://developers.google.com/web/fundamentals/accessibility/a11y-for-teams#managing_focus:

When you change the content of the page, it's important to direct the user's attention by moving focus. A classic example of when this technique is useful is when opening a modal dialog. If a user relying on a keyboard presses a button to open a dialog and their focus is not moved into the dialog element, then their only course of action is to tab through the entire site until they eventually find the new control. By moving focus into the new content as soon as it appears, you can improve the efficiency of these users’ experiences.

A negative tabindex can be used to enable programmatic focus to the context menu's container:

https://webaim.org/techniques/keyboard/tabindex#zero-negative-one:

tabindex="-1" allows that element to receive programmatic focus. This means focus can be set to it using focus() scripting.

Malvoz commented 2 years ago

Other potentially helpful resources:

danieldegroot2 commented 2 years ago

I would recommend adding highlights too, see mentioned issue. (These should be present with or without #136.)