DEV: follow-up to avoid using schedule when opening modal from dropdown (#27970)

This commit is contained in:
Kris 2024-07-18 10:33:06 -04:00 committed by GitHub
parent 6344e3f937
commit 9719aa0e2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 13 deletions

View File

@ -3,7 +3,6 @@ import { tracked } from "@glimmer/tracking";
import { getOwner } from "@ember/application";
import { hash } from "@ember/helper";
import { action } from "@ember/object";
import { schedule } from "@ember/runloop";
import { service } from "@ember/service";
import { modifier as modifierFn } from "ember-modifier";
import { and, eq, not, or } from "truth-helpers";
@ -92,7 +91,12 @@ export default class GlimmerHeader extends Component {
return;
}
if (!panelBody.contains(event.relatedTarget)) {
// don't remove focus from newly opened modal
const isFocusInModal = document
.querySelector(".d-modal")
?.contains(event.relatedTarget);
if (!panelBody.contains(event.relatedTarget) && !isFocusInModal) {
this.closeCurrentMenu();
}
};
@ -110,17 +114,15 @@ export default class GlimmerHeader extends Component {
@action
closeCurrentMenu() {
schedule("afterRender", () => {
if (this.search.visible) {
this.toggleSearchMenu();
} else if (this.header.userVisible) {
this.toggleUserMenu();
document.getElementById(USER_BUTTON_ID)?.focus();
} else if (this.header.hamburgerVisible) {
this.toggleHamburger();
document.getElementById(HAMBURGER_BUTTON_ID)?.focus();
}
});
if (this.search.visible) {
this.toggleSearchMenu();
} else if (this.header.userVisible) {
this.toggleUserMenu();
document.getElementById(USER_BUTTON_ID)?.focus();
} else if (this.header.hamburgerVisible) {
this.toggleHamburger();
document.getElementById(HAMBURGER_BUTTON_ID)?.focus();
}
}
@action