Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(overflow-menu): improve overall a11y #1115

Merged
merged 6 commits into from
Sep 24, 2018

Conversation

tw15egan
Copy link
Collaborator

Closes #666

Adds in recommended a11y additions to Overflow Menu component

Changelog

New

  • aria-expanded toggle when it is open / close
  • correct a11y roles and and aria-labels

Changed

  • Event listener now listens for keydown, instead of keypress, so that esc can be used to close the overflow menu and return focus. The overflow menu can now also be opened with the space bar. Was not able to add in navigation via keyboard arrows, might want to open a separate issue for that.

Testing / Reviewing

  • Navigate to Overflow Menu, use enter and space to open / close the menu. Use esc to close the menu
  • Ensure aria-expanded toggles correctly
  • @carmacleod, it would be awesome if you could test these changes with JAWS, as I do not have a machine that can test that.

Copy link
Contributor

@lovemecomputer lovemecomputer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate comment

Copy link
Contributor

@lovemecomputer lovemecomputer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good update! i've done a bit of keyboard shortcut work before and would def like to take a look about implementing it here for another PR

@carmacleod
Copy link
Contributor

Wow, great @tw15egan ! I'm swamped today, but I can run it through the screen readers tomorrow afternoon.
Are the changes on the Carbon Overflow Menu page?

Copy link
Contributor

@joshblack joshblack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@lovemecomputer
Copy link
Contributor

i put an Issue for keyboard implementation at #1119

(or let me know if you want me to just make further commits to this PR!)

@tw15egan
Copy link
Collaborator Author

Great! Let's tackle that in another PR.

@carmacleod no rush! I will ping you when the updates are pushed out live to the website

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tw15egan for jumping in! Just a question.

const shouldBeOpen = isOfSelf && !element.classList.contains(options.classShown);
const state = shouldBeOpen ? 'shown' : 'hidden';

if (isOfSelf) {
if (element.tagName === 'A') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here is for preventing link from being followed. Did you find a new condition where event's default behavior should be prevented?

Copy link
Collaborator Author

@tw15egan tw15egan Sep 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was running into issues when trying to open the menu with the enter key. Perhaps I should I only prevent that if the key === enter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if this is a better solution

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tw15egan for the background and the suggestion! What I saw is that the change from keypress to keydown caused the overflow menu to be open (and thus focus moving to the overflow menu item) in the middle of the keystroke (of enter key). When user finishes the keystroke, the keypress event fires on the overflow menu item given it's a <button> and now has focus.

One way to get around with this is what you suggested. Great to have above finding as comments so that future maintainers/consumers can figure out why, if we go with this approach.

Another approach to address this is below, which directly removes the weird behavior described above, and thus reduces possibility of future issues (esp. wrt browser compatibility).

diff --git a/src/components/overflow-menu/overflow-menu.js b/src/components/overflow-menu/overflow-menu.js
index bdc031f..4a7ffc2 100644
--- a/src/components/overflow-menu/overflow-menu.js
+++ b/src/components/overflow-menu/overflow-menu.js
@@ -82,7 +82,16 @@ class OverflowMenu extends mixin(createComponent, initComponentBySearch, evented
     );
     this.manage(
       on(this.element.ownerDocument, 'keydown', event => {
-        this._handleKeyPress(event);
+        if (event.which === 27) {
+          this._handleKeyPress(event);
+        }
+      })
+    );
+    this.manage(
+      on(this.element.ownerDocument, 'keypress', event => {
+        if (event.which !== 27) {
+          this._handleKeyPress(event);
+        }
       })
     );
     this.manage(
@@ -179,7 +188,7 @@ class OverflowMenu extends mixin(createComponent, initComponentBySearch, evented
       const state = shouldBeOpen ? 'shown' : 'hidden';

       if (isOfSelf) {
-        if (element.tagName === 'A' || key === 13) {
+        if (element.tagName === 'A') {
           event.preventDefault();
         }
         event.delegateTarget = element; // eslint-disable-line no-param-reassign

Don't hesitate to ping me if you have any questions/concerns. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asudoh made the changes, but still found the need to prevent default when the space key is pressed (https://github.com/IBM/carbon-components/pull/1115/files#diff-cdb22c353cb80d123893d9f188477d1bR191) to prevent the screen from jumping down

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks alot @tw15egan! Could you add a comment to describing 32 key default prevention is for preventing screen from jumping down? I think this PR is good to go once it happens - Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the comment in, going to merge it! 😄 Thanks for helping out

@tw15egan tw15egan merged commit c7bdb31 into carbon-design-system:master Sep 24, 2018
@carbon-bot
Copy link
Contributor

🎉 This PR is included in version 9.20.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

joshblack pushed a commit to joshblack/carbon that referenced this pull request May 2, 2019
* fix(Modal): add keyboard trap

Adds a keyboard trap to fix issue carbon-design-system#874

* fix(Modal): focus on modal itself when focus leaves

Fixes the modal keyboard trap to be consistent with vanilla behavior.

* fix(Modal): provide workaround for keyboard trap and floating menus

Makes it possible to escape keyboard trap in modals when using floating menus

* fix(OverflowMenu): focus on menu after closed

This sends focus back to the overflow menu item after the menu gets closed. This
is important for floating overflow menus in modals.

* fix(OverflowMenu): get rid of redundant code

* fix(Modal): improve support for floating menus in keyboard trap

Made algorithm to check for floating menus check parents as well and
made the list of floating menu selectors consistent with vanilla.
@tw15egan tw15egan deleted the overflow-a11y branch April 28, 2021 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overflow menu needs accessibility work
6 participants