Skip to content

Commit

Permalink
fix(a11y): address event firing from keyboard
Browse files Browse the repository at this point in the history
This commit addresses a few issues from keyboard use

- prevent a user from using the spacebar or enter key to select a disabled option
- disabling the default scrolling of a page when using a spacebar to select an option

Changes to be committed:
modified:   src/auro-menu.js
  • Loading branch information
blackfalcon committed Jan 22, 2022
1 parent c624fbe commit d4fbe92
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/auro-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ class AuroMenu extends LitElement {
}

const handleKeyDown = (evt) => {
if (evt.key.toLowerCase() === 'enter' || evt.key.toLowerCase() === ' ') {
dispatchEventOptionSelected(Number(evt.target.getAttribute('index')), evt.target.getAttribute('data-value'), evt.target.innerText);
if (!evt.target.hasAttribute('disabled')) {
if (evt.key.toLowerCase() === 'enter' || evt.key.toLowerCase() === ' ') {
if (evt.key.toLowerCase() === ' ') {
evt.preventDefault();
}
dispatchEventOptionSelected(Number(evt.target.getAttribute('index')), evt.target.getAttribute('data-value'), evt.target.innerText);
}
}

if (evt.key.toLowerCase() === 'arrowdown') {
Expand Down

0 comments on commit d4fbe92

Please sign in to comment.