Skip to content

Commit 727f804

Browse files
Make sure the content change when the slot content change
Signed-off-by: Phillip Kruger <phillip.kruger@gmail.com>
1 parent 2bd28d3 commit 727f804

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

qui-code-block.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class QuiCodeBlock extends LitElement {
6262

6363
connectedCallback() {
6464
super.connectedCallback();
65+
this._updateSlotContent();
6566
if(this.src){
6667
// if mode is not provided, figure is out
6768
if(!this.mode){
@@ -83,7 +84,12 @@ class QuiCodeBlock extends LitElement {
8384
}else{
8485
this._basicTheme = basicDark;
8586
}
86-
87+
const slot = this.shadowRoot.querySelector('slot');
88+
if (slot) {
89+
slot.addEventListener('slotchange', () => {
90+
this._updateSlotContent();
91+
});
92+
}
8793
}
8894

8995
disconnectedCallback() {
@@ -94,13 +100,17 @@ class QuiCodeBlock extends LitElement {
94100
}
95101

96102
firstUpdated() {
97-
103+
this._updateSlotContent();
104+
}
105+
106+
_updateSlotContent() {
98107
// See if the content is provided in a slot
99108
const slotValue = this.shadowRoot.getElementById('slotContent');
100109
if(slotValue){
101110
const v = slotValue.assignedNodes()[1];
102111
if(v && v.textContent){
103112
this.content = this._removeEmptyLines(v.textContent);
113+
this._updateContent();
104114
}
105115
}
106116

0 commit comments

Comments
 (0)