Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialog: Cherry pick 're-focus original element on close' fix to v4 #6142

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/primevue/src/confirmpopup/ConfirmPopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export default {
visible: false,
confirmation: null,
autoFocusAccept: null,
autoFocusReject: null
autoFocusReject: null,
target: null
};
},
target: null,
Expand Down Expand Up @@ -175,6 +176,8 @@ export default {
this.autoFocusAccept = this.confirmation.defaultFocus === undefined || this.confirmation.defaultFocus === 'accept' ? true : false;
this.autoFocusReject = this.confirmation.defaultFocus === 'reject' ? true : false;

this.target = document.activeElement;

this.bindOutsideClickListener();
this.bindScrollListener();
this.bindResizeListener();
Expand All @@ -188,6 +191,9 @@ export default {
this.autoFocusAccept = null;
this.autoFocusReject = null;

DomHandler.focus(this.target);
this.target = null;

this.unbindOutsideClickListener();
this.unbindScrollListener();
this.unbindResizeListener();
Expand Down
6 changes: 5 additions & 1 deletion packages/primevue/src/dialog/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export default {
containerVisible: this.visible,
maximized: false,
focusableMax: null,
focusableClose: null
focusableClose: null,
target: null,
};
},
watch: {
Expand Down Expand Up @@ -146,6 +147,7 @@ export default {
},
onEnter() {
this.$emit('show');
this.target = document.activeElement;
this.focus();
this.enableDocumentSettings();
this.bindGlobalListeners();
Expand All @@ -161,6 +163,8 @@ export default {
},
onLeave() {
this.$emit('hide');
DomHandler.focus(this.target);
this.target = null;
this.focusableClose = null;
this.focusableMax = null;
},
Expand Down
Loading