CustomElementConstructor Class

A custom element constructor (https://html.spec.whatwg.org/multipage/custom-elements.html#custom-element-constructor), passed to CustomElementRegistry.Define.

public class CustomElementConstructor

Remarks

In a browser, a custom element is an instance of a class that extends HTMLElement, and an upgrade changes the prototype of an existing element. A .NET object cannot change its type, so the element is always created by the library (an HtmlElement, or the element interface of the extended element for a customized built-in element), and the constructor creates a CustomElement attached to the element: its virtual methods are the lifecycle callbacks, and HtmlElement.CustomElement returns it. The static members of a JavaScript custom element class (observedAttributes, disabledFeatures, formAssociated) are properties of the constructor, read once by Define.

See also

Constructors

NameDescription
CustomElementConstructor(Func<HtmlElement, CustomElement>)Creates a constructor that attaches the object returned by factory to the elements it constructs.

CustomElementConstructor(Func<HtmlElement, CustomElement>)

CustomElementConstructor.cs

Creates a constructor that attaches the object returned by factory to the elements it constructs.

public CustomElementConstructor(Func<HtmlElement, CustomElement> factory)

Parameters

factory Func<HtmlElement, CustomElement>
Creates the CustomElement of an element, when the element is created (e.g. createElement(), the HTML parser) or upgraded. It must pass the element to the constructor of CustomElement. As in a JavaScript constructor, it must not add attributes or children to the element.

Properties

NameDescription
DisabledFeaturesGets the disabled features: "internals" disables attachInternals(), "shadow" disables attachShadow().
FormAssociatedGets whether the elements are form-associated custom elements (the static formAssociated property of a JavaScript custom element class).
ObservedAttributesGets the names of the attributes whose changes invoke CustomElement.AttributeChangedCallback (the static observedAttributes property of a JavaScript custom element class).

Gets the disabled features: "internals" disables attachInternals(), "shadow" disables attachShadow().

public IReadOnlyCollection<string> DisabledFeatures { get; init; }

Gets whether the elements are form-associated custom elements (the static formAssociated property of a JavaScript custom element class).

public bool FormAssociated { get; init; }

Property value

bool

ObservedAttributes

CustomElementConstructor.cs

Gets the names of the attributes whose changes invoke CustomElement.AttributeChangedCallback (the static observedAttributes property of a JavaScript custom element class).

public IReadOnlyCollection<string> ObservedAttributes { get; init; }