Skip to content

Commit

Permalink
feat(menu): auto-focus menu when dropdown opens
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-capsule42 committed Jan 27, 2022
1 parent 65e753c commit d48c5ee
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/auro-dropdownmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ class AuroDropdownmenu extends LitElement {
}

firstUpdated() {
this.addEventListener('click', () => {
const menuItems = this.querySelectorAll('auro-menuoption');

let focusIndex = 0;

for (let optionsIndex = 0; optionsIndex < menuItems.length; optionsIndex += 1) {
if (menuItems[optionsIndex].hasAttribute('selected')) {
focusIndex = optionsIndex;
}
}

menuItems[focusIndex].focus();
});

this.addEventListener('optionSelected', (evt) => {
try {
this.shadowRoot.querySelector('auro-dropdown').hide();
Expand Down

0 comments on commit d48c5ee

Please sign in to comment.