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

fix(ui5-popover, ui5-dialog): don't fire events until the control is connected to DOM #10898

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions packages/fiori/cypress/specs/SideNavigation.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ describe("Side Navigation interaction", () => {

// act
cy.get("#focusStart").realClick();
cy.get("#focusStart").realClick();
cy.realPress("ArrowDown");
cy.realPress("Space");

Expand Down
2 changes: 1 addition & 1 deletion packages/main/cypress/specs/Menu.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ describe("Menu interaction", () => {
.as("menu").then($menu => {
const menu = $menu.get(0) as Menu;

menu.addEventListener("ui5-open", () => {
menu.addEventListener("ui5-before-open", () => {
setTimeout(() => {
menu.loading = false;

Expand Down
17 changes: 7 additions & 10 deletions packages/main/src/Popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,11 @@ abstract class Popup extends UI5Element {
}

async openPopup() {
if (this._opened) {
if (!this.isConnected || this._opened) {
return;
}

const prevented = !this.fireDecoratorEvent("before-open");

if (prevented || this._opened) {
if (!this.fireDecoratorEvent("before-open")) {
return;
}

Expand All @@ -326,9 +324,7 @@ abstract class Popup extends UI5Element {

await renderFinished();

if (this.isConnected) {
this.fireDecoratorEvent("open");
}
this.fireDecoratorEvent("open");
}

_resize() {
Expand Down Expand Up @@ -510,8 +506,7 @@ abstract class Popup extends UI5Element {
return;
}

const prevented = !this.fireDecoratorEvent("before-close", { escPressed });
if (prevented) {
if (this.isConnected && !this.fireDecoratorEvent("before-close", { escPressed })) {
return;
}

Expand All @@ -532,7 +527,9 @@ abstract class Popup extends UI5Element {
this.resetFocus();
}

this.fireDecoratorEvent("close");
if (this.isConnected) {
this.fireDecoratorEvent("close");
}
}

/**
Expand Down