Add the observed event handlers to the shadowRoot

If it exists then add it there. Otherwise add it to the custom element itself.
This commit is contained in:
Jeremy Wall 2023-11-15 20:53:54 -05:00
parent bb60556f29
commit 8ce79d34a5
2 changed files with 10 additions and 3 deletions

View File

@ -144,8 +144,15 @@ fn expand_wc_struct_trait_shim(
super();
this._impl = impl();
this._impl.init_impl(this);
var self = this;
if (self.shadowRoot) {{
for (const t of this.observedEvents()) {{
this.addEventListener(t, function(evt) {{ this.handleComponentEvent(evt); }} );
self.shadowRoot.addEventListener(t, function(evt) {{ self.handleComponentEvent(evt); }} );
}}
}} else {{
for (const t of self.observedEvents()) {{
self.addEventListener(t, function(evt) {{ self.handleComponentEvent(evt); }} );
}}
}}
}}

View File

@ -24,8 +24,8 @@ version = "0.3"
version = "0.3"
features = [
"CustomElementRegistry",
"CustomEvent",
"Document",
"KeyboardEvent",
"Event",
"EventTarget",
"Element",