Skip to content

Element.attachShadow() - doc for options.customElementRegistry#43593

Open
hamishwillee wants to merge 1 commit intomdn:mainfrom
hamishwillee:ff150_attachshadow_options_customElementRegistry
Open

Element.attachShadow() - doc for options.customElementRegistry#43593
hamishwillee wants to merge 1 commit intomdn:mainfrom
hamishwillee:ff150_attachshadow_options_customElementRegistry

Conversation

@hamishwillee
Copy link
Copy Markdown
Collaborator

@hamishwillee hamishwillee commented Mar 27, 2026

Adds customElementRegistry option for the Element.attachShadow()

Fixes #43237
Fixes #38266

Related docs work can be tracked in #43555

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

Preview URLs (2 pages)

(comment last updated: 2026-03-31 05:50:38)

@hamishwillee hamishwillee force-pushed the ff150_attachshadow_options_customElementRegistry branch from 0fe36cf to d502a02 Compare March 31, 2026 05:49
@hamishwillee hamishwillee marked this pull request as ready for review March 31, 2026 05:49
@hamishwillee hamishwillee requested a review from a team as a code owner March 31, 2026 05:49
@hamishwillee hamishwillee requested review from chrisdavidmills and removed request for a team March 31, 2026 05:49
Copy link
Copy Markdown
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

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

@hamishwillee a few bits for you to look at, but this is mostly fine!

- `clonable` {{Optional_Inline}}
- : A boolean that specifies whether the shadow root is clonable: when set to `true`, the shadow host cloned with {{domxref("Node.cloneNode()")}} or {{domxref("Document.importNode()")}} will include shadow root in the copy. Its default value is `false`.

- `customElementRegistry` {{Optional_Inline}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As an FYI, looking at the preview page, the nested DL formatting is broken.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, there are a couple of big sections up top that need dumping into a "Description" section further down. Not sure if you fancy fixing that while you are here? I won't block on it, if not ;-)


- `customElementRegistry` {{Optional_Inline}}
- : A {{DOMxRef('CustomElementRegistry')}} that will be used as the [scoped custom element registry](/en-US/docs/Web/API/Web_components/Using_custom_elements#scoped_custom_element_registries) of the attached shadow root.
If `null` or `undefined`, the shadow root will use the global registry provided by {{domxref("Window.customElements")}}.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
If `null` or `undefined`, the shadow root will use the global registry provided by {{domxref("Window.customElements")}}.
If `null` or `undefined`, the shadow root will use the global registry referenced by {{domxref("Window.customElements")}}.

- : Elements are not automatically assigned to {{HTMLElement("slot")}} elements. Instead, they must be manually assigned with {{domxref("HTMLSlotElement.assign()")}}.
Its default value is `named`.

Note that if you pass a {{DOMxRef('ShadowRoot')}} the method will read the corresponding properties as though it was an [`options`](#options) object.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Feels like this should be formatted as a note, and begin the sentence with "If..."

Also, it is a bit confusing — it is not clear where you pass this ShadowRoot. Is it one of the option values? Does it take the place of the options object? It feels like the note is referencing one of the option descriptions, but I'm not sure which one.

- where the element definition static property `disabledFeatures` has been given a value of `"shadow"`.
- that already has a shadow root that was not created declaratively.
- that has a [declarative shadow root](/en-US/docs/Web/HTML/Reference/Elements/template#declarative_shadow_dom) but the specified `mode` does not match the existing mode.
- passing a `customElementRegistry` value that isn't `null` or a locally scoped registry (that you created using `new CustomElementRegistry()`).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
- passing a `customElementRegistry` value that isn't `null` or a locally scoped registry (that you created using `new CustomElementRegistry()`).
- while passing a `customElementRegistry` value that isn't `null` or a locally scoped registry (that you created using `new CustomElementRegistry()`).

### Basic usage

The most common example you'll see of this property being used is to get access to the {{domxref("CustomElementRegistry.define()")}} method to define and register a new custom element.
For example:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe put this "For example:" on a new line?

Also, the line later on — "However, it is usually shortened to something like the following:" — makes very little sense, as the code snippet that follows it is longer than the first code snippet ;-)

If you fancy it, maybe replace that line with something like "However, the custom element class is usually defined directly inside the define() call, something like this:"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing scoped custom element registries docs Scoped Custom Element Registries

3 participants