@microsoft/fast-element 2.0.0-beta.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +1 -1
- package/CHANGELOG.json +512 -0
- package/CHANGELOG.md +180 -1
- package/README.md +1 -9
- package/api-extractor.context.json +14 -0
- package/api-extractor.di.json +14 -0
- package/dist/context/context.api.json +1068 -0
- package/dist/di/di.api.json +4929 -0
- package/dist/dts/binding/binding.d.ts +49 -0
- package/dist/dts/binding/normalize.d.ts +9 -0
- package/dist/dts/binding/one-time.d.ts +11 -0
- package/dist/dts/binding/one-way.d.ts +20 -0
- package/dist/dts/{templating/binding-signal.d.ts → binding/signal.d.ts} +19 -4
- package/dist/dts/{templating/binding-two-way.d.ts → binding/two-way.d.ts} +9 -5
- package/dist/dts/components/attributes.d.ts +6 -0
- package/dist/dts/components/element-controller.d.ts +104 -8
- package/dist/dts/components/element-hydration.d.ts +2 -0
- package/dist/dts/components/fast-definitions.d.ts +6 -0
- package/dist/dts/components/hydration.d.ts +56 -0
- package/dist/dts/components/install-hydration.d.ts +1 -0
- package/dist/dts/context.d.ts +29 -15
- package/dist/dts/di/di.d.ts +0 -5
- package/dist/dts/dom-policy.d.ts +83 -0
- package/dist/dts/dom.d.ts +100 -0
- package/dist/dts/hydration/target-builder.d.ts +63 -0
- package/dist/dts/index.d.ts +33 -26
- package/dist/dts/index.rollup.d.ts +0 -1
- package/dist/dts/index.rollup.debug.d.ts +0 -1
- package/dist/dts/interfaces.d.ts +32 -82
- package/dist/dts/metadata.d.ts +6 -5
- package/dist/dts/observation/arrays.d.ts +1 -1
- package/dist/dts/observation/observable.bench.d.ts +18 -0
- package/dist/dts/observation/observable.d.ts +5 -5
- package/dist/dts/pending-task.d.ts +19 -7
- package/dist/dts/platform.d.ts +11 -2
- package/dist/dts/polyfills.d.ts +0 -8
- package/dist/dts/styles/css-binding-directive.d.ts +60 -0
- package/dist/dts/styles/css.d.ts +9 -7
- package/dist/dts/styles/element-styles.d.ts +1 -14
- package/dist/dts/styles/host.d.ts +2 -5
- package/dist/dts/styles/style-strategy.d.ts +42 -0
- package/dist/dts/templating/compiler.d.ts +11 -13
- package/dist/dts/templating/{binding.d.ts → html-binding-directive.d.ts} +22 -42
- package/dist/dts/templating/html-directive.d.ts +44 -140
- package/dist/dts/templating/install-hydratable-view-templates.d.ts +1 -0
- package/dist/dts/templating/node-observation.d.ts +11 -1
- package/dist/dts/templating/ref.d.ts +4 -0
- package/dist/dts/templating/render.bench.d.ts +3 -0
- package/dist/dts/templating/render.d.ts +49 -9
- package/dist/dts/templating/repeat-basic-reverse.bench.d.ts +3 -0
- package/dist/dts/templating/repeat-basic-shift.bench.d.ts +3 -0
- package/dist/dts/templating/repeat.d.ts +31 -9
- package/dist/dts/templating/template.d.ts +97 -12
- package/dist/dts/templating/view.d.ts +149 -26
- package/dist/dts/templating/when-basic.bench.d.ts +3 -0
- package/dist/dts/templating/when-conditional.bench.d.ts +3 -0
- package/dist/dts/templating/when-switch.bench.d.ts +3 -0
- package/dist/dts/templating/when.d.ts +3 -1
- package/dist/dts/testing/fakes.d.ts +12 -1
- package/dist/dts/tsdoc-metadata.json +1 -1
- package/dist/dts/utilities.d.ts +55 -1
- package/dist/esm/binding/binding.js +18 -0
- package/dist/esm/binding/normalize.js +17 -0
- package/dist/esm/binding/one-time.js +21 -0
- package/dist/esm/binding/one-way.js +30 -0
- package/dist/esm/{templating/binding-signal.js → binding/signal.js} +22 -6
- package/dist/esm/{templating/binding-two-way.js → binding/two-way.js} +18 -12
- package/dist/esm/components/attributes.js +16 -1
- package/dist/esm/components/element-controller.js +319 -49
- package/dist/esm/components/element-hydration.js +2 -0
- package/dist/esm/components/fast-definitions.js +12 -4
- package/dist/esm/components/fast-element.js +3 -1
- package/dist/esm/components/hydration.js +104 -0
- package/dist/esm/components/install-hydration.js +3 -0
- package/dist/esm/context.js +26 -4
- package/dist/esm/debug.js +8 -2
- package/dist/esm/di/di.js +9 -12
- package/dist/esm/dom-policy.js +345 -0
- package/dist/esm/dom.js +101 -0
- package/dist/esm/hydration/target-builder.js +175 -0
- package/dist/esm/index.js +34 -25
- package/dist/esm/index.rollup.debug.js +3 -1
- package/dist/esm/index.rollup.js +3 -1
- package/dist/esm/interfaces.js +51 -3
- package/dist/esm/metadata.js +11 -8
- package/dist/esm/observation/arrays.js +1 -1
- package/dist/esm/observation/observable.bench.js +79 -0
- package/dist/esm/observation/observable.js +20 -15
- package/dist/esm/observation/update-queue.js +2 -2
- package/dist/esm/pending-task.js +13 -1
- package/dist/esm/platform.js +12 -2
- package/dist/esm/polyfills.js +3 -61
- package/dist/esm/styles/css-binding-directive.js +76 -0
- package/dist/esm/styles/css.js +14 -7
- package/dist/esm/styles/element-styles.js +0 -33
- package/dist/esm/styles/style-strategy.js +1 -0
- package/dist/esm/templating/children.js +8 -4
- package/dist/esm/templating/compiler.js +37 -44
- package/dist/esm/templating/html-binding-directive.js +218 -0
- package/dist/esm/templating/html-directive.js +25 -152
- package/dist/esm/templating/install-hydratable-view-templates.js +17 -0
- package/dist/esm/templating/node-observation.js +14 -8
- package/dist/esm/templating/ref.js +1 -1
- package/dist/esm/templating/render.bench.js +56 -0
- package/dist/esm/templating/render.js +74 -30
- package/dist/esm/templating/repeat-basic-reverse.bench.js +43 -0
- package/dist/esm/templating/repeat-basic-shift.bench.js +43 -0
- package/dist/esm/templating/repeat.js +116 -17
- package/dist/esm/templating/template.js +135 -60
- package/dist/esm/templating/view.js +259 -32
- package/dist/esm/templating/when-basic.bench.js +36 -0
- package/dist/esm/templating/when-conditional.bench.js +39 -0
- package/dist/esm/templating/when-switch.bench.js +68 -0
- package/dist/esm/templating/when.js +12 -5
- package/dist/esm/testing/fakes.js +32 -1
- package/dist/esm/testing/fixture.js +1 -1
- package/dist/esm/utilities.js +97 -1
- package/dist/fast-element.api.json +9804 -5622
- package/dist/fast-element.d.ts +813 -2386
- package/dist/fast-element.debug.js +2797 -974
- package/dist/fast-element.debug.min.js +3 -1
- package/dist/fast-element.js +2642 -825
- package/dist/fast-element.min.js +3 -1
- package/dist/fast-element.untrimmed.d.ts +669 -315
- package/docs/{api-report.md → api-report.api.md} +243 -158
- package/docs/context/api-report.api.md +69 -0
- package/docs/di/api-report.api.md +315 -0
- package/karma.conf.cjs +2 -1
- package/package.json +59 -47
- package/scripts/run-api-extractor.js +51 -0
- package/scripts/run-benchmarks.js +46 -0
- package/tensile.config.js +12 -0
- package/dist/dts/templating/dom.d.ts +0 -41
- package/dist/esm/templating/binding.js +0 -282
- package/dist/esm/templating/dom.js +0 -49
- package/docs/guide/declaring-templates.md +0 -230
- package/docs/guide/defining-elements.md +0 -214
- package/docs/guide/leveraging-css.md +0 -253
- package/docs/guide/next-steps.md +0 -13
- package/docs/guide/observables-and-state.md +0 -213
- package/docs/guide/using-directives.md +0 -576
- package/docs/guide/working-with-shadow-dom.md +0 -296
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: working-with-shadow-dom
|
|
3
|
-
title: Working with Shadow DOM
|
|
4
|
-
sidebar_label: Working with Shadow DOM
|
|
5
|
-
custom_edit_url: https://github.com/microsoft/fast/edit/master/packages/web-components/fast-element/docs/guide/working-with-shadow-dom.md
|
|
6
|
-
description: See how our custom elements can be composed together with standard HTML or other custom elements.
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
So far we've looked at how to define elements, how to define attributes on those elements, and how to control element rendering through declarative templates. However, we haven't yet seen how our custom elements can be composed together with standard HTML or other custom elements.
|
|
10
|
-
|
|
11
|
-
## The default slot
|
|
12
|
-
|
|
13
|
-
To enable composition, `FASTElement` leverages the Shadow DOM standard. Previously, we've seen how `FASTElement` automatically attaches a `ShadowRoot`, and when your element declares a template, it renders that template into the Shadow DOM. To enable element composition, all we need to do is make use of the standard `<slot>` element within our template.
|
|
14
|
-
|
|
15
|
-
Let's return to our original `name-tag` element example and see how we can use a `slot` to compose the person's name.
|
|
16
|
-
|
|
17
|
-
**Example: Using Slots in a `FASTElement`**
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
import { FASTElement, customElement, attr, html } from '@microsoft/fast-element';
|
|
21
|
-
|
|
22
|
-
const template = html<NameTag>`
|
|
23
|
-
<div class="header">
|
|
24
|
-
<h3>${x => x.greeting.toUpperCase()}</h3>
|
|
25
|
-
<h4>my name is</h4>
|
|
26
|
-
</div>
|
|
27
|
-
|
|
28
|
-
<div class="body">
|
|
29
|
-
<slot></slot>
|
|
30
|
-
</div>
|
|
31
|
-
|
|
32
|
-
<div class="footer"></div>
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
@customElement({
|
|
36
|
-
name: 'name-tag',
|
|
37
|
-
template
|
|
38
|
-
})
|
|
39
|
-
export class NameTag extends FASTElement {
|
|
40
|
-
@attr greeting: string = 'Hello';
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Inside the body `div`, we've placed a `slot` element. This is referred to as the "default slot" for the component because, by default, all content placed between the element's opening and closing tags will be *rendered* at this location.
|
|
45
|
-
|
|
46
|
-
To make this clear, let's look at how the `name-tag` element would be used with content and then see how the browser would composite the final rendered output.
|
|
47
|
-
|
|
48
|
-
**Example: Using `name-tag` with a Default Slot**
|
|
49
|
-
|
|
50
|
-
```html
|
|
51
|
-
<name-tag>John Doe<name-tag>
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**Example: Rendered Output for `name-tag` with a Default Slot**
|
|
55
|
-
|
|
56
|
-
```html
|
|
57
|
-
<name-tag>
|
|
58
|
-
#shadow-root
|
|
59
|
-
<div class="header">
|
|
60
|
-
<h3>HELLO</h3>
|
|
61
|
-
<h4>my name is</h4>
|
|
62
|
-
</div>
|
|
63
|
-
|
|
64
|
-
<div class="body">
|
|
65
|
-
<slot>John Doe</slot>
|
|
66
|
-
</div>
|
|
67
|
-
|
|
68
|
-
<div class="footer"></div>
|
|
69
|
-
#shadow-root
|
|
70
|
-
|
|
71
|
-
John Doe
|
|
72
|
-
</name-tag>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
The text "John Doe" exists in the "Light DOM", but it gets *projected* into the location of the `slot` within the "Shadow DOM".
|
|
76
|
-
|
|
77
|
-
:::note
|
|
78
|
-
If you find the terms "Light DOM" and "Shadow DOM" unintuitive, you're not alone. Another way to think of "Light DOM" is as the "Semantic DOM". It represents your semantic content model, without any concern for rendering. Another way to think of "Shadow DOM" is as the "Render DOM". It represents how your element is rendered, independent of content, or semantics.
|
|
79
|
-
:::
|
|
80
|
-
|
|
81
|
-
With slots at our disposal, we now unlock the full compositional model of HTML for use in our own elements. However, there's even more that slots can do.
|
|
82
|
-
|
|
83
|
-
## Named slots
|
|
84
|
-
|
|
85
|
-
In the example above, we use a single `slot` element to render *all* content placed between the start and end tags of the `name-tag`. However, we're not limited to only having a default slot. We can also have *named slots* that declare other locations to which we can render content. To demonstrate this, let's add a named slot to our `name-tag`'s template where we can display the person's avatar.
|
|
86
|
-
|
|
87
|
-
**Example: `name-tag` with a Named Slot**
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
import { FASTElement, customElement, attr, html } from '@microsoft/fast-element';
|
|
91
|
-
|
|
92
|
-
const template = html<NameTag>`
|
|
93
|
-
<div class="header">
|
|
94
|
-
<slot name="avatar"></slot>
|
|
95
|
-
<h3>${x => x.greeting.toUpperCase()}</h3>
|
|
96
|
-
<h4>my name is</h4>
|
|
97
|
-
</div>
|
|
98
|
-
|
|
99
|
-
<div class="body">
|
|
100
|
-
<slot></slot>
|
|
101
|
-
</div>
|
|
102
|
-
|
|
103
|
-
<div class="footer"></div>
|
|
104
|
-
`;
|
|
105
|
-
|
|
106
|
-
@customElement({
|
|
107
|
-
name: 'name-tag',
|
|
108
|
-
template
|
|
109
|
-
})
|
|
110
|
-
export class NameTag extends FASTElement {
|
|
111
|
-
@attr greeting: string = 'Hello';
|
|
112
|
-
}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
**Example: Using `name-tag` with a Named Slot**
|
|
116
|
-
|
|
117
|
-
```html
|
|
118
|
-
<name-tag>
|
|
119
|
-
John Doe
|
|
120
|
-
<img slot="avatar" src="...">
|
|
121
|
-
</name-tag>
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
**Example: Rendered Output for `name-tag` with a Named Slot**
|
|
125
|
-
|
|
126
|
-
```html
|
|
127
|
-
<name-tag>
|
|
128
|
-
#shadow-root
|
|
129
|
-
<div class="header">
|
|
130
|
-
<slot name="avatar">
|
|
131
|
-
<img slot="avatar" src="...">
|
|
132
|
-
</slot>
|
|
133
|
-
<h3>HELLO</h3>
|
|
134
|
-
<h4>my name is</h4>
|
|
135
|
-
</div>
|
|
136
|
-
|
|
137
|
-
<div class="body">
|
|
138
|
-
<slot>John Doe</slot>
|
|
139
|
-
</div>
|
|
140
|
-
|
|
141
|
-
<div class="footer"></div>
|
|
142
|
-
#shadow-root
|
|
143
|
-
|
|
144
|
-
John Doe
|
|
145
|
-
<img slot="avatar" src="...">
|
|
146
|
-
</name-tag>
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
If an element declares named slots, its content can then leverage the `slot` *attribute* to indicate where it wants to be slotted. Anything without a `slot` attribute will be projected to the default slot. Anything with a `slot` attribute will be projected into its requested slot.
|
|
150
|
-
|
|
151
|
-
Here are a couple of quick notes on slots:
|
|
152
|
-
|
|
153
|
-
* You can have any number of content nodes project into the same slot.
|
|
154
|
-
* You can only place `slot` attributes on the direct content of the containing element.
|
|
155
|
-
```html
|
|
156
|
-
<name-tag>
|
|
157
|
-
<div> <!--Projected to default slot-->
|
|
158
|
-
<img slot="avatar"> <!--Slot Ignored!-->
|
|
159
|
-
</div>
|
|
160
|
-
<img slot="avatar"> <!--Projected to "avatar" slot-->
|
|
161
|
-
</name-tag>
|
|
162
|
-
```
|
|
163
|
-
* If you have direct content elements in the Light DOM for which there is no corresponding Shadow DOM slot, it will not be rendered.
|
|
164
|
-
* Ordering is maintained when projecting to slots. So, if you have two elements projecting into the same slot, they will render in the slot in the same order as they appeared in the Light DOM.
|
|
165
|
-
* A `slot` element can also have a `slot` attribute if the slot element is the direct child of another custom element used in your template. In this case, it means that whatever content would be projected into that slot gets re-projected into the slot of the containing element.
|
|
166
|
-
```html
|
|
167
|
-
<div class="uber-name-tag-template">
|
|
168
|
-
...
|
|
169
|
-
<name-tag>
|
|
170
|
-
<slot name="uber-avatar" slot="avatar">
|
|
171
|
-
<!--uber-name-tag's "uber-avatar" content gets projected into name-tag's "avatar" slot-->
|
|
172
|
-
</slot>
|
|
173
|
-
<slot>
|
|
174
|
-
<!--uber-name-tag's default content gets projected into name-tag's default slot-->
|
|
175
|
-
</slot>
|
|
176
|
-
</name-tag>
|
|
177
|
-
...
|
|
178
|
-
</div>
|
|
179
|
-
```
|
|
180
|
-
* You do not need to provide content for every declared slot. In the above example, just because the `name-tag` has an "avatar" slot does not mean we must provide content for that slot. If no content is provided for a slot, then nothing will be rendered at that location, unless the slot declared fallback content...
|
|
181
|
-
|
|
182
|
-
## Fallback content
|
|
183
|
-
|
|
184
|
-
There are several scenarios for using slots in your elements. So far, we've been showing how to use slots for content projection. However, another major use case is to enable various parts of your element's rendering to be replaced by the software using your element. To enable this, you can provide *fallback content* for any slot. This content will render if the element consumer provides no content for that slot, but if they do, their own content will override the fallback content.
|
|
185
|
-
|
|
186
|
-
**Example: Fallback Slot Content**
|
|
187
|
-
|
|
188
|
-
```html
|
|
189
|
-
<div class="my-slider-template">
|
|
190
|
-
<slot name="thumb">
|
|
191
|
-
<span class="thumb"></span>
|
|
192
|
-
</slot>
|
|
193
|
-
</div>
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
In the example above, the author of the `my-slider` custom element provides default HTML for the slider's "thumb", ensuring that the element will always render and function properly. However, this design leaves open the option to the component's consumer, to replace the thumb with their own HTML by simply providing HTML and assigning the proper slot name.
|
|
197
|
-
|
|
198
|
-
## Slot APIs
|
|
199
|
-
|
|
200
|
-
In addition to the declarative means of using slots described so far, the browser offers a number of slot-specific APIs you can use directly in JavaScript code. Below is a summary of what is available to you.
|
|
201
|
-
|
|
202
|
-
| API | Description |
|
|
203
|
-
| ------------- |-------------|
|
|
204
|
-
| `slotchange` | By adding an event listener for the `slotchange` event on a `slot` element, you can receive notifications any time the slotted nodes of a particular slot change. |
|
|
205
|
-
| `assignedNodes()` | The `slot` element provides an `assignedNodes()` method that can be called to get a list of all nodes that a particular slot currently renders. You can pass an options object with `{ flatten: true }` if you wish to also see fallback content nodes. |
|
|
206
|
-
| `assignedSlot` | The `assignedSlot` property is present on any element that has been projected to a slot so that you can determine where it is projected. |
|
|
207
|
-
|
|
208
|
-
:::tip
|
|
209
|
-
Remember that you can use the templating system's event support to respond to `slotchange` events with `<slot @slotchange=${...}></slot>`. You can also obtain a reference to any slot with the `ref` directive, making it easy to call APIs like `assignedNodes()` or manually add/remove event listeners.
|
|
210
|
-
:::
|
|
211
|
-
|
|
212
|
-
## Events
|
|
213
|
-
|
|
214
|
-
Events originating from within the Shadow DOM appear as if they originated from the custom element itself. In order for an event to propagate from within the Shadow DOM, it must be dispatched with the `composed: true` option. The following is a list of built-in events that compose:
|
|
215
|
-
|
|
216
|
-
* `blur`, `focus`, `focusin`, `focusout`
|
|
217
|
-
* `click`, `dblclick`, `mousedown`, `mouseenter`, `mousemove`, etc.
|
|
218
|
-
* `wheel`
|
|
219
|
-
* `beforeinput`, `input`
|
|
220
|
-
* `keydown`, `keyup`
|
|
221
|
-
* `compositionstart`, `compositionupdate`, `compositionend`
|
|
222
|
-
* `dragstart`, `drag`, `dragend`, `drop`, etc.
|
|
223
|
-
|
|
224
|
-
Here are some events which do not compose and are only visible from within the Shadow DOM itself:
|
|
225
|
-
|
|
226
|
-
* `mouseenter`, `mouseleave`
|
|
227
|
-
* `load`, `unload`, `abort`, `error`
|
|
228
|
-
* `select`
|
|
229
|
-
* `slotchange`
|
|
230
|
-
|
|
231
|
-
To get the fully composed event path from an event object, invoke the `composedPath()` method on the event itself. This will return an array of targets representing the path through which the event bubbled. If your custom element uses `closed` Shadow DOM mode, targets within the Shadow DOM will not be present in the composed path, and it will appear as if the custom element itself was the first target.
|
|
232
|
-
|
|
233
|
-
### Custom events
|
|
234
|
-
|
|
235
|
-
In various scenarios, it may be appropriate for a custom element to publish its own element-specific events. To do this, you can use the `$emit` helper on `FASTElement`. It's a convenience method that creates an instance of `CustomEvent` and uses the `dispatchEvent` API on `FASTElement` with the `bubbles: true` and `composed: true` options. It also ensures that the event is only emitted if the custom element is fully connected to the DOM. Here's an example:
|
|
236
|
-
|
|
237
|
-
**Example: Custom Event Dispatch**
|
|
238
|
-
|
|
239
|
-
```ts
|
|
240
|
-
customElement('my-input')
|
|
241
|
-
export class MyInput extends FASTElement {
|
|
242
|
-
@attr value: string = '';
|
|
243
|
-
|
|
244
|
-
valueChanged() {
|
|
245
|
-
this.$emit('change', this.value);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
:::tip
|
|
251
|
-
When emitting custom events, ensure that your event name is always lower-case, so that your Web Components stay compatible with various front-end frameworks that attach events through DOM binding patterns (the DOM is case insensitive).
|
|
252
|
-
:::
|
|
253
|
-
|
|
254
|
-
## Shadow DOM configuration
|
|
255
|
-
|
|
256
|
-
In all the examples we've seen so far `FASTElement` automatically creates a Shadow Root for your element and attaches it in `open` mode. However, if desired, you can specify `closed` mode or make the element render into the Light DOM instead. These choices can be made by using the `shadowOptions` setting with your `@customElement` decorator.
|
|
257
|
-
|
|
258
|
-
**Example: Shadow DOM in Closed Mode**
|
|
259
|
-
|
|
260
|
-
```ts
|
|
261
|
-
@customElement({
|
|
262
|
-
name: 'name-tag',
|
|
263
|
-
template,
|
|
264
|
-
shadowOptions: { mode: 'closed' }
|
|
265
|
-
})
|
|
266
|
-
export class NameTag extends FASTElement {
|
|
267
|
-
@attr greeting: string = 'Hello';
|
|
268
|
-
}
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
:::tip
|
|
272
|
-
Avoid using `closed` mode since it affects event propagation and makes custom elements less inspectable.
|
|
273
|
-
:::
|
|
274
|
-
|
|
275
|
-
**Example: Render to Light DOM**
|
|
276
|
-
|
|
277
|
-
```ts
|
|
278
|
-
@customElement({
|
|
279
|
-
name: 'name-tag',
|
|
280
|
-
template,
|
|
281
|
-
shadowOptions: null
|
|
282
|
-
})
|
|
283
|
-
export class NameTag extends FASTElement {
|
|
284
|
-
@attr greeting: string = 'Hello';
|
|
285
|
-
}
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
:::important
|
|
289
|
-
If you choose to render to the Light DOM, you will not be able to compose the content, use slots, or leverage encapsulated styles. Light DOM rendering is not recommended for reusable components. It may have some limited use as the root component of a small app.
|
|
290
|
-
:::
|
|
291
|
-
|
|
292
|
-
In addition to the Shadow DOM mode, `shadowOptions` exposes all the options that can be set through the standard `attachShadow` API. This means that you can also use it to specify new options such as `delegatesFocus: true`. You only need to specify options that are different from the defaults mentioned above.
|
|
293
|
-
|
|
294
|
-
## Shadow DOM and the element lifecycle
|
|
295
|
-
|
|
296
|
-
It is during the constructor that `FASTElement` attaches the Shadow DOM for an element. The `shadowRoot` is then available directly as a property on your Custom Element, assuming that the element uses `open` mode.
|