Skip to content

FF149 ShadowRoot referenceTarget and friends minor update#43543

Draft
hamishwillee wants to merge 2 commits intomdn:mainfrom
hamishwillee:ff149_shadowroot_referencetarget
Draft

FF149 ShadowRoot referenceTarget and friends minor update#43543
hamishwillee wants to merge 2 commits intomdn:mainfrom
hamishwillee:ff149_shadowroot_referencetarget

Conversation

@hamishwillee
Copy link
Copy Markdown
Collaborator

FF149 added support for referenceTarget and shadowRootReferenceTarget attributes behind a pref. These are already mostly documented in #42323. This is pretty basic, but it was and remains about the right level because this isnt supported in releases or preview yet. At that point we should create guide material and cross link (this can be generated from the explainer.

What this does is get us a little bit closer so that when we have to update there is less to do.

  1. Update the docs to use correct templates
  2. Add linked individual property property docs rather than just the top level doc.

I have put a little bit more work into ShadowRoot.referenceTarget docs because it ONLY affects this property. So we could in theory add examples and so on to this without being confusing for other docs. See inline comments.

Related docs work can be tracked in #43453

@github-actions github-actions bot added Content:HTML Hypertext Markup Language docs Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Mar 24, 2026

{{APIRef("Shadow DOM")}}

The **`Element.attachShadow()`** method attaches a shadow DOM tree to the specified element and returns a reference to its {{domxref("ShadowRoot")}}.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change just moves us to Web API template, moving the following stuff into a description.

Comment on lines +80 to +86
The **`attachShadow()`** method attaches a {{domxref("ShadowRoot")}} to the specified element and returns a reference to it.

The returned {{domxref("ShadowRoot")}} is the root node of a shadow tree, which can then be populated with its own DOM content.
The element to which the shadow root is attached is referred to as the "shadow host", and remains in its original DOM.

The `ShadowRoot` acts as a boundary between the original DOM and the shadow tree.
It controls encapsulation — for example, styles defined inside the shadow tree do not affect the original DOM.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new. IMO it is worth saying that the shadow root is what is created, initially empty.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 2026

Preview URLs (6 pages)

Flaws (1)

Note! 5 documents with no flaws that don't need to be listed. 🎉

Found an unexpected or unresolvable flaw? Please report it here.

URL: /en-US/docs/Web/API/ShadowRoot
Title: ShadowRoot
Flaw count: 1

  • macros:
    • Macro domxref produces link /en-US/docs/Web/API/ShadowRoot/getSelection which doesn't resolve
External URLs (1)

URL: /en-US/docs/Web/API/Element/attachShadow
Title: Element: attachShadow() method

(comment last updated: 2026-03-24 07:09:59)

@@ -0,0 +1,33 @@
---
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI "a nothing doc". Not useful but following the pattern of other docs in this this interface.

Comment on lines +42 to +92
### Basic usage

```html
<label for="consent">I consent to cookies</label>
<sp-checkbox id="consent"></sp-checkbox>

<hr />
<div id="log"></div>
```

```js
function log(...args) {
const debug = document.getElementById("log");
debug.innerHTML += args.join(" ") + "<br>";
}
```

```js
customElements.define(
"sp-checkbox",
class Checkbox extends HTMLElement {
checked = "mixed";

constructor() {
super();
this.shadowRoot_ = this.attachShadow({
mode: "closed",
//referenceTarget: "input",
});

this.shadowRoot_.referenceTarget = "input";

this.render();
}
render() {
this.shadowRoot_.innerHTML = `
<input id="input"
type="checkbox"
${this.checked == "true" ? "checked" : ""}
aria-checked=${this.checked == "indeterminate" ? "mixed" : this.checked}>
<span id="box"></span>`;

const input = this.shadowRoot_.getElementById("input");

log("aria-checked:", input.getAttribute("aria-checked"));
log("aria-label:", input.getAttribute("aria-label"));
log("aria-labelledby:", input.getAttribute("aria-labelledby"));
}
},
);
```
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not sure what example to show - this is a modification of the explainer. It is hard because you can't propgrammatically log the supposedly affected attributes, such as aria-labelledby, to show the effect.
I explained this above in the description - the browser doesn't change the element, it computes it when needed.

Open to ideas that don't require a screen reader or other accessibility tools.

Also not sure the right way to "feature test".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meyerweb Any ideas on a good live example at this early stage of the feature?

Note, I'm not planning on going much further with docs on this until it is in preview release/FF nightly. What you did before was sufficient, this is just a bit of tidy.

Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:HTML Hypertext Markup Language docs Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants