Skip to content

Commit

Permalink
Fix tab navigation in popover. Tabbing does not move between menu opt…
Browse files Browse the repository at this point in the history
…ions, but rather advances to next element in tab order
  • Loading branch information
marcellamaki committed May 12, 2022
1 parent 321a649 commit 4d794ce
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/KDropdownMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
methods: {
handleOpen() {
this.$nextTick(() => this.setFocus());
window.addEventListener('keydown', this.handleArrowKeys, true);
window.addEventListener('keydown', this.handleOpenMenuNavigation, true);
},
setFocus() {
this.$refs.menu.$el.querySelector('li').focus();
Expand All @@ -121,8 +121,11 @@
}
window.removeEventListener('keyup', this.handleKeyUp, true);
},
handleArrowKeys(event) {
handleOpenMenuNavigation(event) {
// identify the menu state and length
if (!this.$refs.popover && !this.$refs.popover.$el) {
return
}
const popover = this.$refs.popover.$el;
const menuElements = this.$refs.menu.$el.querySelector('div').children;
const lastChild = menuElements[menuElements.length - 1];
Expand All @@ -140,6 +143,9 @@
} else if (event.keyCode == 40 && popoverIsOpen) {
event.preventDefault();
sibling ? this.$nextTick(() => sibling.focus()) : this.$nextTick(() => this.setFocus());
// if a tab key, not an arrow key, close the popover and advance to next item in the tab index
} else if (event.keyCode == 9 && popoverIsOpen) {
this.closePopover()
}
},
handleSelection(selection) {
Expand Down

0 comments on commit 4d794ce

Please sign in to comment.