Skip to content

Commit ddb7c5d

Browse files
committed
fix(pat modal): Trigger pat-modal-ready event only once.
For pat-modal instances on anchor elements where pat-inject is involved the event ``pat-modal-ready`` was triggered twice. This is now fixed and the event is only triggered after the modal was inserted.
1 parent e037611 commit ddb7c5d

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/pat/modal/modal.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ export default Base.extend({
6363
$("#pat-modal").detach();
6464
});
6565

66-
this.el.addEventListener("pat-inject-success", () => {
67-
// Dispatch the pat-modal-ready event after injection is done.
68-
this.el.dispatchEvent(
69-
new Event("pat-modal-ready", { bubbles: true, cancelable: true })
70-
);
71-
});
72-
7366
inject.init(this.$el, opts);
7467
},
7568

src/pat/modal/modal.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe("pat-modal", function () {
147147
await utils.timeout(1); // wait a tick for async to settle.
148148

149149
// Opened immediately
150-
expect(callback).toHaveBeenCalled();
150+
expect(callback).toHaveBeenCalledTimes(1);
151151
});
152152

153153
it("1.7 - Dispatch pat-modal-ready with a inject-modal.", async function () {
@@ -159,17 +159,17 @@ describe("pat-modal", function () {
159159
`;
160160

161161
const callback = jest.fn();
162+
document.body.addEventListener("pat-modal-ready", callback);
162163
const modal_el = document.querySelector(".pat-modal");
163-
modal_el.addEventListener("pat-modal-ready", callback);
164164
pattern.init(modal_el);
165165
await utils.timeout(1); // wait a tick for async to settle.
166166

167167
expect(callback).not.toHaveBeenCalled();
168168

169-
answer("<html><body><div></div></body></html>");
169+
answer(`<html><body><div></div></body></html>`);
170170
modal_el.click();
171171
await utils.timeout(1); // wait a tick for async to settle.
172-
expect(callback).toHaveBeenCalled();
172+
expect(callback).toHaveBeenCalledTimes(1);
173173
});
174174

175175
it("1.8 - Submit form, do injection and close overlay.", async function () {

0 commit comments

Comments
 (0)