From c7f9b9704f931d8a30daffe27ca22cab3409b8be Mon Sep 17 00:00:00 2001 From: jiverson Date: Fri, 24 May 2024 22:19:47 -0700 Subject: [PATCH] fix: Dialog/Confirm re-focus original element on close --- components/lib/confirmpopup/ConfirmPopup.vue | 8 +++++++- components/lib/dialog/Dialog.vue | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/components/lib/confirmpopup/ConfirmPopup.vue b/components/lib/confirmpopup/ConfirmPopup.vue index cb528aa32..b5045ee3b 100644 --- a/components/lib/confirmpopup/ConfirmPopup.vue +++ b/components/lib/confirmpopup/ConfirmPopup.vue @@ -54,7 +54,8 @@ export default { visible: false, confirmation: null, autoFocusAccept: null, - autoFocusReject: null + autoFocusReject: null, + focusElementOnHide: null, }; }, target: null, @@ -151,6 +152,8 @@ export default { this.autoFocusAccept = this.confirmation.defaultFocus === undefined || this.confirmation.defaultFocus === 'accept' ? true : false; this.autoFocusReject = this.confirmation.defaultFocus === 'reject' ? true : false; + this.focusElementOnHide = document.activeElement; + this.bindOutsideClickListener(); this.bindScrollListener(); this.bindResizeListener(); @@ -164,6 +167,9 @@ export default { this.autoFocusAccept = null; this.autoFocusReject = null; + DomHandler.focus(this.focusElementOnHide); + this.focusElementOnHide = null; + this.unbindOutsideClickListener(); this.unbindScrollListener(); this.unbindResizeListener(); diff --git a/components/lib/dialog/Dialog.vue b/components/lib/dialog/Dialog.vue index 762db37f9..fe592081f 100755 --- a/components/lib/dialog/Dialog.vue +++ b/components/lib/dialog/Dialog.vue @@ -84,7 +84,8 @@ export default { containerVisible: this.visible, maximized: false, focusableMax: null, - focusableClose: null + focusableClose: null, + focusElementOnHide: null, }; }, watch: { @@ -139,6 +140,7 @@ export default { }, onEnter() { this.$emit('show'); + this.focusElementOnHide = document.activeElement; this.focus(); this.enableDocumentSettings(); this.bindGlobalListeners(); @@ -154,6 +156,8 @@ export default { }, onLeave() { this.$emit('hide'); + DomHandler.focus(this.focusElementOnHide); + this.focusElementOnHide = null; this.focusableClose = null; this.focusableMax = null; },