{shadow}
The shadow root of a custom element, rendered on the server as declarative shadow DOM.
Syntax
{shadow} ... {/shadow}
{shadow css='file.css, www:other.css', mode='closed', focus} ... {/shadow}
Options
-
css -
Stylesheets inlined as one
<style>at the start of the root, separated by commas: a.cssfile of the application, orwww:one of itswww/directory. -
mode -
open(the default) orclosed. -
focus -
Bare option: adds
shadowrootdelegatesfocus.
Description
{shadow} writes <template shadowrootmode="open"> around its rendered content. Placed inside a custom element, it is that element's shadow root: the browser builds the root while it parses the page, so the element shows - with encapsulated styles and slotted light DOM - before any script has run, and a module that defines the element later finds the root ready in this.shadowRoot. Like {tidy}, the tag runs twice: the content renders first, then the template tags go around it.
A shadow root takes no styles from the page, and a <style> written into the template would have its braces read as PAD tags. css= therefore inlines stylesheet files instead, as one <style> at the start of the root: a .css file of the application, or with www: one in its www/ directory - the file rule of {source}. Each file is read once a request. mode='closed' makes a closed root, focus adds shadowrootdelegatesfocus.
The usual home of {shadow} is a custom tag in _tags/ that writes a custom element, combined with {parms}; the first example uses _tags/shadowCard.pad with its stylesheet _tags/shadowCard.css. Inside the pair, {#name} is {shadow}'s own parameter - in a custom tag, put the tag's parameters to use outside the pair, or carry one in with {set $value = {#value}} before it.
A stylesheet that is not there or is no .css file, a mode that is neither open nor closed, and a pair that never closes are errors.
Examples
A card with a shadow root
A custom tag writes a custom element with its shadow root, the stylesheet inlined, the title slotted.
{shadowCard title='Revenue'}
<p>€ 12,400 this month.</p>
{/shadowCard}
€ 12,400 this month.
A closed root that delegates focus
The pair straight in a page - mode='closed' and focus, the light DOM slotted.
<search-box>
{shadow mode='closed', focus}
<label><slot name="label"></slot> <input type="search"></label>
{/shadow}
<span slot="label">Search the shop</span>
</search-box>