summaryrefslogtreecommitdiff
path: root/packages/integrations/lit/server.js
diff options
context:
space:
mode:
authorGravatar Reece McDonald <39349270+hrmcdonald@users.noreply.github.com> 2023-02-24 12:10:56 -0600
committerGravatar GitHub <noreply@github.com> 2023-02-24 12:10:56 -0600
commit26bf12ef3c7ab874a23ac753f841f7bb329c9361 (patch)
tree3e4a7ce83a135416efa61da7925cdd01b90a3f89 /packages/integrations/lit/server.js
parent5aa6580f775405a4443835bf7eb81f0c65e5aed6 (diff)
downloadastro-26bf12ef3c7ab874a23ac753f841f7bb329c9361.tar.gz
astro-26bf12ef3c7ab874a23ac753f841f7bb329c9361.tar.zst
astro-26bf12ef3c7ab874a23ac753f841f7bb329c9361.zip
[Lit] render DSD attributes based on `shadowRootOptions` (#6351)
* [Lit] render DSD attributes based on `shadowRootOptions` ## Changes - Update `@astrojs/lit`’s `server.js` to properly render elements with `delegatesFocus: false` set in their `shadowRootOptions`. - Logic is based on `@lit-labs/ssr` [latest implementation as found here](https://github.com/lit/lit/blob/b0c3f82ef0f97326a205e77e7e1043b75a5cc53f/packages/labs/ssr/src/lib/render-value.ts#L738) ## Testing A test was added to ensure an element with `delegatesFocus` set to true has this attribute properly included in the rendered static markup. * chore: add changeset
Diffstat (limited to 'packages/integrations/lit/server.js')
-rw-r--r--packages/integrations/lit/server.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/packages/integrations/lit/server.js b/packages/integrations/lit/server.js
index da571466f..aa91d1ea8 100644
--- a/packages/integrations/lit/server.js
+++ b/packages/integrations/lit/server.js
@@ -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>';
}