Merge pull request #33637 from sokumon/dialog-focus
fix: bring focus back on control when dialog is opened
This commit is contained in:
commit
5c659e8029
1 changed files with 17 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ frappe.ui.Dialog = class Dialog extends frappe.ui.FieldGroup {
|
|||
super();
|
||||
this.display = false;
|
||||
this.is_dialog = true;
|
||||
this.last_focus = null;
|
||||
|
||||
$.extend(this, { animate: true, size: null, auto_make: true }, opts);
|
||||
if (this.auto_make) {
|
||||
|
|
@ -247,6 +248,7 @@ frappe.ui.Dialog = class Dialog extends frappe.ui.FieldGroup {
|
|||
|
||||
show() {
|
||||
// show it
|
||||
this.handle_focus();
|
||||
if (this.animate) {
|
||||
this.$wrapper.addClass("fade");
|
||||
} else {
|
||||
|
|
@ -274,6 +276,21 @@ frappe.ui.Dialog = class Dialog extends frappe.ui.FieldGroup {
|
|||
this.is_visible = false;
|
||||
}
|
||||
|
||||
handle_focus() {
|
||||
const me = this;
|
||||
if (frappe.get_route) {
|
||||
if (frappe.get_route()[0] == "Form") {
|
||||
if (!me.last_focus) me.last_focus = document.activeElement;
|
||||
}
|
||||
$(document).on("escape", function () {
|
||||
if (me.last_focus) {
|
||||
me.last_focus.focus();
|
||||
me.last_focus = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
get_close_btn() {
|
||||
return this.$wrapper.find(".btn-modal-close");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue