CustomElementContext class
Context provided to the component builder inside defineCustomElement.
Exposes the custom element's host element, Shadow DOM root (if enabled), reactive signals for observed attributes, and custom event dispatching helpers.
defineCustomElement(
'user-card',
(CustomElementContext context) {
final name = context.attributeSignal('user-name');
return Live(() => Div(
children: [
H1(text: name.value ?? 'Anonymous'),
Button(
text: 'Select',
onClick: (e) => context.dispatchCustomEvent('user-select', detail: {'name': name.value}),
),
],
));
},
observedAttributes: ['user-name'],
);
Constructors
- CustomElementContext({required HTMLElement host, ShadowRoot? shadowRoot})
-
Creates a CustomElementContext for
hostwith optionalshadowRoot.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- host → HTMLElement
-
The host
web.HTMLElementinstance.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shadowRoot → ShadowRoot?
-
The attached
web.ShadowRoot, ornullif Shadow DOM was disabled (useShadowDom: false).final
Methods
-
attributeSignal(
String name) → Signal< String?> -
Returns a reactive Signal tracking the value of attribute
name. -
dispatchCustomEvent(
String type, {Object? detail, bool bubbles = true, bool composed = true, bool cancelable = true}) → void -
Dispatches a custom DOM event from the host element with
typeanddetail. -
getAttribute(
String name) → String? -
Synchronously reads the current string value of attribute
nameon host. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited