Skip to content

Clarify that declarative custom element definitions don't contain declarative shadow roots. #1101

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

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions proposals/Declarative-Custom-Elements-Strawman.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ First, with the proposed template instantiation API in mind, we imagined a HTML

```html
<definition name="my-element" constructor="MyElement">
<template shadowmode="closed">~</template>
<shadowoptions mode="open"></shadowoptions>
<template>~</template>
<script>
class MyElement extends HTMLElement { ~ }
</script>
Expand All @@ -22,7 +23,8 @@ This still requires having to repeat the constructor name twice. We can avoid th

```html
<definition name="my-element">
<template shadowmode="closed">~</template>
<shadowoptions mode="closed"></shadowoptions>
<template>~</template>
<script type="module">
export default class MyElement extends HTMLElement { ~ }
</script>
Expand All @@ -42,7 +44,8 @@ class /* default custom element */ extends HTMLElement {
const template = customElements.getTemplate(this);
if (!template)
return;
#shadowRoot = this.attachShadow({mode: template.getAttribute('shadowmode')});
const shadowOptions = customElements.getShadowOptions(this);
#shadowRoot = this.attachShadow(shadowOptions);
#templateInstance = #shadowRoot.appendChild(template.createInstance(#shadowRoot));
}
attributeChangedCallback(attributeName, oldValue, newValue, namespace) {
Expand All @@ -57,7 +60,8 @@ Note that the shadow root of the custom element is passed to createInstance's st

```html
<definition name="percentage-bar">
<template shadowmode="closed">
<shadowoptions mode="closed"></shadowoptions>
<template>
<div id="progressbar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="{{root.attributes.percentage.value}}">
<div id="bar" style="width: {{root.attributes.percentage.value}}%"></div>
<div id="label"><slot></slot></div>
Expand Down