Skip to content

Commit 1adacee

Browse files
committed
feat: add slotchange event listener to remove empty infotip
1 parent edae699 commit 1adacee

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

assets/web-components/infotip.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ class TatvaInfotip extends HTMLElement {
3636
this.initEvents();
3737
this.hideTooltip();
3838
});
39+
40+
const slot = this.shadowRoot.querySelector('slot');
41+
slot.addEventListener('slotchange', () => {
42+
// gather all assigned nodes
43+
const nodes = slot.assignedNodes({ flatten: true });
44+
// check if there’s any non‑empty text left
45+
const hasText = nodes.some(node =>
46+
node.nodeType === Node.TEXT_NODE && node.textContent.trim() !== ''
47+
);
48+
if (!hasText) this.remove();
49+
});
3950
}
4051

4152
// Renders the main template for the component

0 commit comments

Comments
 (0)