Skip to content

Commit ac27e20

Browse files
committed
fix(pat-tooltip): Cleanup tooltip after it's destroyed.
When the tooltip is destroyed, also call the tooltip's BasePattern destroy method to clean up and release the tooltip from the element. After that it can be instantiated on the same element again. This change was necessary after the recent BasePattern change.
1 parent f9ca65a commit ac27e20

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/pat/tooltip/tooltip.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class Pattern extends BasePattern {
119119

120120
show() {
121121
// Show this tooltip
122-
// API method.
123122
this.tippy.show();
124123
}
125124

@@ -131,7 +130,7 @@ class Pattern extends BasePattern {
131130

132131
destroy() {
133132
// Remove this tooltip
134-
// API method.
133+
super.destroy(); // Unregister
135134
this.tippy.destroy();
136135
}
137136

src/pat/tooltip/tooltip.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,48 @@ describe("pat-tooltip", () => {
200200
spy_trigger.mockRestore();
201201
});
202202
});
203+
204+
it("1.4.1 - Cannot instantiated twice on the same element", async () => {
205+
document.body.innerHTML = `
206+
<a class="pat-tooltip"
207+
data-pat-tooltip="source: title"
208+
title="This is the title attribute"
209+
>test</a>
210+
`;
211+
const el = document.querySelector(".pat-tooltip");
212+
const instance = new Pattern(el);
213+
await events.await_pattern_init(instance);
214+
215+
expect(el["pattern-tooltip"]).toBe(instance);
216+
217+
const instance2 = new Pattern(el);
218+
await utils.timeout(1); // await_pattern_init never fullfilled.
219+
220+
expect(el["pattern-tooltip"]).toBe(instance);
221+
expect(el["pattern-tooltip"]).not.toBe(instance2);
222+
});
223+
224+
it("1.4.2 - Can be instantiated again on the same element after the first was destroyed.", async () => {
225+
document.body.innerHTML = `
226+
<a class="pat-tooltip"
227+
data-pat-tooltip="source: title"
228+
title="This is the title attribute"
229+
>test</a>
230+
`;
231+
const el = document.querySelector(".pat-tooltip");
232+
const instance = new Pattern(el);
233+
await events.await_pattern_init(instance);
234+
235+
expect(el["pattern-tooltip"]).toBe(instance);
236+
237+
instance.destroy();
238+
239+
const instance2 = new Pattern(el);
240+
await utils.timeout(1); // await_pattern_init never fullfilled.
241+
242+
expect(el["pattern-tooltip"]).not.toBe(instance);
243+
expect(el["pattern-tooltip"]).toBe(instance2);
244+
});
203245
});
204246

205247
describe("2 - Tooltip closing behavior", () => {

0 commit comments

Comments
 (0)