CustomElementEvent<T> class

A strongly-typed event wrapper for custom element DOM events carrying a deserialized detail payload.

When browser Custom Elements and Web Components (e.g. Shoelace, Lit, Vaadin, FAST) dispatch custom DOM events (such as sl-change, ionChange, or tab-select), their event data payload is carried in the event.detail property. CustomElementEvent automatically unwraps detail into idiomatic Dart values (Map, List, primitives) of type T via jsToDartValue.

Backend Execution Note

Custom element events are dispatched exclusively in the browser during client-side DOM mounting via mount. Event listeners are never triggered during Server-Side Rendering (renderToHtml).

customElement(
  'sl-select',
  events: {
    'sl-change': (CustomElementEvent<dynamic> event) {
      event.preventDefault();
      print('Selected value: ${event.detail}');
    },
  },
)

Constructors

CustomElementEvent({required Event rawEvent, required String type, T? detail, Element? target})
Creates a CustomElementEvent wrapping rawEvent with type and converted detail.

Properties

defaultPrevented bool
Whether preventDefault has been called on the underlying DOM event.
no setter
detail → T?
The deserialized event.detail payload converted to Dart type T.
final
hashCode int
The hash code for this object.
no setterinherited
rawEvent → Event
The underlying native DOM web.Event instance.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
target → Element?
The DOM element that dispatched this event.
final
type String
The custom event type name string (e.g. 'sl-change', 'custom-select').
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
preventDefault() → void
Prevents the browser's default action for this event.
stopPropagation() → void
Stops propagation of this event through the DOM hierarchy.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited