Skip to content

Commit 3d4f3c0

Browse files
authored
fix: add children with id to id map even if their parent was teleported (#8321)
1 parent edb03f3 commit 3d4f3c0

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

packages/component-base/src/polylit-mixin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@ const PolylitMixinImplementation = (superclass) => {
224224
this.$ = {};
225225
}
226226

227-
this.renderRoot.querySelectorAll('[id]').forEach((node) => {
228-
this.$[node.id] = node;
227+
[...Object.values(this.$), this.renderRoot].forEach((node) => {
228+
node.querySelectorAll('[id]').forEach((node) => {
229+
this.$[node.id] = node;
230+
});
229231
});
230232
}
231233

packages/component-base/test/polylit-mixin.test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ describe('PolylitMixin', () => {
11961196
}
11971197

11981198
render() {
1199-
return html`Teleported`;
1199+
return html`<slot></slot>`;
12001200
}
12011201
},
12021202
);
@@ -1206,7 +1206,10 @@ describe('PolylitMixin', () => {
12061206
render() {
12071207
return html`
12081208
<div id="title">Title</div>
1209-
<${unsafeStatic(teleportedTag)} id="teleported" />
1209+
1210+
<${unsafeStatic(teleportedTag)} id="teleported">
1211+
<div id="teleportedContent">Teleported content</div>
1212+
</${unsafeStatic(teleportedTag)}>
12101213
`;
12111214
}
12121215
},
@@ -1223,12 +1226,17 @@ describe('PolylitMixin', () => {
12231226

12241227
it('should register elements with id', () => {
12251228
expect(element.$.title).to.be.instanceOf(HTMLDivElement);
1226-
expect(element.$.title.id).to.equal('title');
1229+
expect(element.$.title.textContent.trim()).to.equal('Title');
12271230
});
12281231

12291232
it('should register teleported elements with id', () => {
12301233
expect(element.$.teleported).to.be.instanceOf(HTMLElement);
1231-
expect(element.$.teleported.id).to.equal('teleported');
1234+
expect(element.$.teleported.textContent.trim()).to.equal('Teleported content');
1235+
});
1236+
1237+
it('should register children with id whose parent was teleported', () => {
1238+
expect(element.$.teleportedContent).to.be.instanceOf(HTMLElement);
1239+
expect(element.$.teleportedContent.textContent.trim()).to.equal('Teleported content');
12321240
});
12331241
});
12341242

0 commit comments

Comments
 (0)