Is it possible to declaratively bind a CustomEvent handler when using Dart Web UI WebComponents? Is it possible to declaratively bind a CustomEvent handler when using Dart Web UI WebComponents? dart dart

Is it possible to declaratively bind a CustomEvent handler when using Dart Web UI WebComponents?


Good question!

I see a couple parts to this question:

  • using custom events directly on a component: Currently web_ui uses different objects to represent your component and the actual dom element it represents. In the future, we plan to extend directly from "DivElement" instead of "WebComponent" and that will allow you to do what you wrote.

    Meanwhile, you'll have to be more explicit when you want to use the host or shadow root of your component. In your example, it seems like you want to attach the event to the host, so you would need to write something more like this:

    Stream<CustomEvent> get onMainAction => mainActionEvent.forTarget(this.host);

  • using 'on-someting-foo' syntax in a component: you probably found a bug/missing feature =). Currently we treat attributes in a special way and bind their values to fields of a component if we identify that the target was corresponds to a component. We do this for value bindings, but not yet for binding custom events. A workaround before this feature is added, would be to query for your element and attach the event by hand:

    query('#host-node').xtag.onMainAction.listen(...);