Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.46 KB

File metadata and controls

46 lines (35 loc) · 1.46 KB

ShadowRoot

Namespace: SpawnDev.SpawnJS.JSObjects
Inheritance: SpawnJSObject -> EventTarget -> Node -> DocumentFragment -> ShadowRoot
MDN Reference: ShadowRoot on MDN
Source: SpawnDev.SpawnJS/JSObjects/DOM/ShadowRoot.cs

The ShadowRoot interface of the Shadow DOM API is the root node of a DOM subtree that is rendered separately from a document's main DOM tree. Shadow DOM provides encapsulation for DOM and CSS.

Constructor

public ShadowRoot(SpawnJSObjectReference _ref)

Properties

Property Type Description
DelegatesFocus bool Whether the shadow root delegates focus.
Host Element The host element this shadow root is attached to.
InnerHTML string Get/set the HTML content of the shadow root.
Mode string The mode of the shadow root ("open" or "closed").
ActiveElement Element? The currently focused element within the shadow root.

Example

using var element = doc.QuerySelector<Element>("#myComponent");

// Attach a shadow root
using var shadow = element!.AttachShadow(new AttachShadowRootOptions { Mode = "open" });

// Set content
shadow.InnerHTML = @"
    <style>
        :host { display: block; }
        p { color: blue; }
    </style>
    <p>Shadow DOM content</p>
";

// Access host
using var host = shadow.Host;
Console.WriteLine($"Host tag: {host.TagName}");