Skip to content

Commit

Permalink
added functionality to focus last element after drpdown closes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-Sinha-11 committed Nov 11, 2024
1 parent 1371cd9 commit e530df6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/KDropdownMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
data() {
return {
trigger: null,
lastFocusElement: null,
};
},
watch: {
Expand Down Expand Up @@ -147,6 +148,7 @@
handleOpen() {
this.$nextTick(() => this.$nextTick(() => this.setFocus()));
window.addEventListener('keydown', this.handleOpenMenuNavigation, true);
this.lastFocusElement = document.activeElement;
},
setFocus() {
this.$refs.menu.$el.querySelector('li').focus();
Expand All @@ -162,6 +164,11 @@
) {
this.focusOnButton();
}
if (this.lastFocusElement) {
this.lastFocusElement.focus();
}
window.removeEventListener('keyup', this.handleKeyUp, true);
},
handleOpenMenuNavigation(event) {
Expand Down

0 comments on commit e530df6

Please sign in to comment.