Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add children with id to id map even if their parent was teleported #8321

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/component-base/src/polylit-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ const PolylitMixinImplementation = (superclass) => {
this.$ = {};
}

this.renderRoot.querySelectorAll('[id]').forEach((node) => {
this.$[node.id] = node;
[...Object.values(this.$), this.renderRoot].forEach((node) => {
node.querySelectorAll('[id]').forEach((node) => {
this.$[node.id] = node;
});
});
}

Expand Down
16 changes: 12 additions & 4 deletions packages/component-base/test/polylit-mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ describe('PolylitMixin', () => {
}

render() {
return html`Teleported`;
return html`<slot></slot>`;
}
},
);
Expand All @@ -1206,7 +1206,10 @@ describe('PolylitMixin', () => {
render() {
return html`
<div id="title">Title</div>
<${unsafeStatic(teleportedTag)} id="teleported" />

<${unsafeStatic(teleportedTag)} id="teleported">
<div id="teleportedContent">Teleported content</div>
</${unsafeStatic(teleportedTag)}>
`;
}
},
Expand All @@ -1223,12 +1226,17 @@ describe('PolylitMixin', () => {

it('should register elements with id', () => {
expect(element.$.title).to.be.instanceOf(HTMLDivElement);
expect(element.$.title.id).to.equal('title');
expect(element.$.title.textContent.trim()).to.equal('Title');
});

it('should register teleported elements with id', () => {
expect(element.$.teleported).to.be.instanceOf(HTMLElement);
expect(element.$.teleported.id).to.equal('teleported');
expect(element.$.teleported.textContent.trim()).to.equal('Teleported content');
});

it('should register children with id whose parent was teleported', () => {
expect(element.$.teleportedContent).to.be.instanceOf(HTMLElement);
expect(element.$.teleportedContent.textContent.trim()).to.equal('Teleported content');
});
});

Expand Down
Loading