Skip to content

Commit

Permalink
fix(dialog): fix nested dialog propagation problem (#847)
Browse files Browse the repository at this point in the history
This PR fixes the propagation issue during close in nested dialogs

Closes #342

Co-authored-by: Bahar Yılmaz <bahar.yilmaz@trendyol.com>
  • Loading branch information
BaharYilmaz and Bahar Yılmaz authored Apr 29, 2024
1 parent 0de50ae commit 8309185
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/components/dialog/bl-dialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ describe("bl-dialog", () => {
await resetMouse();
});

it("should prevent parent dialog from closing when the child dialog is closed", async () => {
const dialog = await fixture<typeOfBlDialog>(html`<bl-dialog id="parent" open>
<bl-dialog id="child" open>
Child dialog
</bl-dialog>
</bl-dialog>`);

const childDialog = dialog.querySelector("bl-dialog") as typeOfBlDialog;
const childDialogCloseBtn = childDialog?.shadowRoot?.querySelector("bl-button");

expect(dialog.open).to.equal(true);

childDialogCloseBtn?.click();

setTimeout(() => {
expect(dialog.open).to.equal(true);
expect(childDialog.open).to.equal(false);
});
});

it("should add shadow to footer when the content is too long", async () => {
window.innerWidth = 400;

Expand Down
2 changes: 1 addition & 1 deletion src/components/dialog/bl-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class BlDialog extends LitElement {
this.content?.addEventListener("scroll", this.toggleFooterShadow);
} else {
this.dialog?.close?.();
this.onClose({ isOpen: false });
this.onClose({ isOpen: false }, { bubbles: false });
document.body.style.overflow = "auto";
window?.removeEventListener("keydown", this.onKeydown);
window?.removeEventListener("resize", this.toggleFooterShadow);
Expand Down

0 comments on commit 8309185

Please sign in to comment.