DeclarativeShadowElement
Base class that handles declarative shadow DOM hydration for components mounted after initial page render.Class Definition
component.js
Usage
Declarative shadow DOM is automatically initialized on page load. For dynamically added components:When to Use
UseDeclarativeShadowElement when you need:
- Encapsulated styles that don’t leak to the page
- Shadow DOM for component isolation
- Support for declarative shadow DOM templates
Component class instead, which extends DeclarativeShadowElement.
Component
Main base class for Horizon web components with automatic refs management, declarative event handling, and lifecycle hooks.Class Signature
Properties
Object containing references to child elements with
ref attributes. Automatically populated and kept in sync with DOM changes.Array of ref names that must be present. Throws
MissingRefError if any are missing.Read-only property returning the root nodes of the component. If the component has a shadow root, returns both the component and its shadow root. Otherwise, returns just the component.
Lifecycle Methods
connectedCallback()
Called when the component is inserted into the DOM.component.js
updatedCallback()
Called when the component is re-rendered by the Section Rendering API.component.js
disconnectedCallback()
Called when the component is removed from the DOM.component.js
Refs System
Basic Refs
Elements withref attributes are automatically tracked:
Array Refs
Useref="name[]" syntax to collect multiple elements:
Required Refs
Validate that critical refs exist:TypeScript Refs
Type-safe refs with TypeScript:Declarative Event Handling
The Component class automatically sets up event listeners using theon: attribute syntax.
Basic Events
Supported Events
component.js
Target Selector
Specify which component should handle the event:Passing Data
Pass data to event handlers:Mutation Observer
The Component class automatically observes DOM changes to keep refs in sync:component.js
- Elements are added or removed
refattributes change- Child components are mounted/unmounted
Complete Example
Helper Functions
Internal helper functions used by the Component class:getAncestor(node)
Finds the ancestor of a node, traversing shadow DOM boundaries:component.js
getClosestComponent(node)
Recursively finds the closest ancestor Component instance:component.js
Error Classes
MissingRefError
Thrown when a required ref is not found:component.js