From e530df6bc61ce34236d781e154fa302c814f8a90 Mon Sep 17 00:00:00 2001 From: Sahil-Sinha-11 Date: Mon, 11 Nov 2024 23:44:34 +0530 Subject: [PATCH] added functionality to focus last element after drpdown closes --- lib/KDropdownMenu.vue | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/KDropdownMenu.vue b/lib/KDropdownMenu.vue index 5a4fd3f6a..dac694309 100644 --- a/lib/KDropdownMenu.vue +++ b/lib/KDropdownMenu.vue @@ -117,6 +117,7 @@ data() { return { trigger: null, + lastFocusElement: null, }; }, watch: { @@ -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(); @@ -162,6 +164,11 @@ ) { this.focusOnButton(); } + + if (this.lastFocusElement) { + this.lastFocusElement.focus(); + } + window.removeEventListener('keyup', this.handleKeyUp, true); }, handleOpenMenuNavigation(event) {