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

[Lit] render DSD attributes based on shadowRootOptions #6351

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
5 changes: 5 additions & 0 deletions .changeset/old-fireants-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/lit': patch
---

Render DSD attributes based on `shadowRootOptions`
6 changes: 5 additions & 1 deletion packages/integrations/lit/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ function* render(Component, attrs, slots) {
yield `>`;
const shadowContents = instance.renderShadow({});
if (shadowContents !== undefined) {
yield '<template shadowroot="open" shadowrootmode="open">';
const { mode = 'open', delegatesFocus } = instance.shadowRootOptions ?? {};
// `delegatesFocus` is intentionally allowed to coerce to boolean to
// match web platform behavior.
const delegatesfocusAttr = delegatesFocus ? ' shadowrootdelegatesfocus' : '';
yield `<template shadowroot="${mode}" shadowrootmode="${mode}"${delegatesfocusAttr}>`;
yield* shadowContents;
yield '</template>';
}
Expand Down
11 changes: 11 additions & 0 deletions packages/integrations/lit/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,15 @@ describe('renderToStaticMarkup', () => {
expect($(tagName).attr('attr1')).to.equal(attr1);
expect($(`${tagName} template`).text()).to.contain(`Hello ${prop1}`);
});

it('should render DSD attributes based on shadowRootOptions', async () => {
const tagName = 'lit-component';
customElements.define(tagName, class extends LitElement {
static shadowRootOptions = {...LitElement.shadowRootOptions, delegatesFocus: true};
});
const render = await renderToStaticMarkup(tagName);
expect(render).to.deep.equal({
html: `<${tagName}><template shadowroot=\"open\" shadowrootmode=\"open\" shadowrootdelegatesfocus><!--lit-part--><!--/lit-part--></template></${tagName}>`,
});
});
});