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(); super();
this._impl = impl(); this._impl = impl();
this._impl.init_impl(this); this._impl.init_impl(this);
for (const t of this.observedEvents()) {{ var self = this;
this.addEventListener(t, function(evt) {{ this.handleComponentEvent(evt); }} ); if (self.shadowRoot) {{
for (const t of this.observedEvents()) {{
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" version = "0.3"
features = [ features = [
"CustomElementRegistry", "CustomElementRegistry",
"CustomEvent",
"Document", "Document",
"KeyboardEvent",
"Event", "Event",
"EventTarget", "EventTarget",
"Element", "Element",