Skip to content

Commit

Permalink
fix: Dialog/Confirm re-focus original element on close
Browse files Browse the repository at this point in the history
  • Loading branch information
jiverson committed May 25, 2024
1 parent dd02b1d commit c7f9b97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion components/lib/confirmpopup/ConfirmPopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default {
visible: false,
confirmation: null,
autoFocusAccept: null,
autoFocusReject: null
autoFocusReject: null,
focusElementOnHide: null,
};
},
target: null,
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion components/lib/dialog/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export default {
containerVisible: this.visible,
maximized: false,
focusableMax: null,
focusableClose: null
focusableClose: null,
focusElementOnHide: null,
};
},
watch: {
Expand Down Expand Up @@ -139,6 +140,7 @@ export default {
},
onEnter() {
this.$emit('show');
this.focusElementOnHide = document.activeElement;
this.focus();
this.enableDocumentSettings();
this.bindGlobalListeners();
Expand All @@ -154,6 +156,8 @@ export default {
},
onLeave() {
this.$emit('hide');
DomHandler.focus(this.focusElementOnHide);
this.focusElementOnHide = null;
this.focusableClose = null;
this.focusableMax = null;
},
Expand Down

0 comments on commit c7f9b97

Please sign in to comment.