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

Preventing default key event behaviours for menu #80

Closed
roomman opened this issue Sep 7, 2021 · 2 comments · Fixed by #85
Closed

Preventing default key event behaviours for menu #80

roomman opened this issue Sep 7, 2021 · 2 comments · Fixed by #85
Labels
bug Something isn't working

Comments

@roomman
Copy link

roomman commented Sep 7, 2021

Hi all, thanks for this add-on. It's been great to see this develop and to learn some of the newer ways of developing with Ember.

Just a quick question on the keyboard events for <Menu>. Is there a rationale for not preventing the default behaviour for the up and down arrow events? They are causing some jerky scrolling, when the containing element has a height greater than the viewport.

The following additions resolve it for me, but I'm unclear if this creates new issues in terms of accessibility? Can't see anything in the w3 docs to suggest it would.

  @action
  onKeydown(event) {
    switch (event.key) {
      // Ref: https://www.w3.org/TR/wai-aria-practices-1.2/#keyboard-interaction-12
      case 'Enter':
        if (this.args.activeItem) {
          this.args.activeItem.element.click();
        }
        this.args.closeMenu();
        break;
      case 'ArrowDown':
+     event.preventDefault();
        return this.args.goToNextItem();
      case 'ArrowUp':
+     event.preventDefault();
        return this.args.goToPreviousItem();
      default:
        if (event.key.length === 1) {
          return this.args.search(event.key);
        }
    }
  }

Would you accept a PR to handle these events?

@roomman
Copy link
Author

roomman commented Sep 8, 2021

Just checked the React edition of headlessui and their Menu component has preventDefault and stopPropagation. 👍🏻

@alexlafroscia
Copy link
Collaborator

alexlafroscia commented Sep 16, 2021

This is definitely a bug in our implementation; I've noticed the same problem in our app that uses Menu. I don't think it would be a problem to prevent these events' default behavior; I think it's what we should be doing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants