Fix: Can't focus to map after a popup is closed.

Signed-off-by: Gökay Şatır <gokaysatir@gmail.com>
Change-Id: I2a0c59001761489f34cdc9ab9be8c1d6255c4eff
This commit is contained in:
Gökay Şatır 2023-05-24 16:27:08 +03:00 committed by thebearon
parent 82628571d8
commit 1c28a4a5f3

View file

@ -68,12 +68,7 @@ L.Control.JSDialog = L.Control.extend({
return;
}
try {
this.dialogs[id].lastFocusedElement.focus();
}
catch (error) {
this.map.focus();
}
this.focusToLastElement(id);
var builder = this.clearDialog(id);
if (sendCloseEvent !== false && builder)
@ -111,6 +106,17 @@ L.Control.JSDialog = L.Control.extend({
else {
this.clearDialog(id);
}
this.focusToLastElement(id);
},
focusToLastElement: function(id) {
try {
this.dialogs[id].lastFocusedElement.focus();
}
catch (error) {
this.map.focus();
}
},
setTabs: function() {
@ -473,7 +479,8 @@ L.Control.JSDialog = L.Control.extend({
var instance = e.data;
// Save last focused element, we will set the focus back to this element after this popup is closed.
instance.lastFocusedElement = document.activeElement;
if (!this.dialogs[instance.id] || !this.dialogs[instance.id].lastFocusedElement) // Avoid to reset while updates.
instance.lastFocusedElement = document.activeElement;
instance.callback = e.callback;
instance.isSnackbar = e.data.type === 'snackbar';