diff --git a/macros/src/lib.rs b/macros/src/lib.rs index d746946..2e96b78 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -144,8 +144,15 @@ fn expand_wc_struct_trait_shim( super(); this._impl = impl(); this._impl.init_impl(this); - for (const t of this.observedEvents()) {{ - this.addEventListener(t, function(evt) {{ this.handleComponentEvent(evt); }} ); + var self = this; + 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); }} ); + }} }} }} diff --git a/wasm-web-component/Cargo.toml b/wasm-web-component/Cargo.toml index 89c888d..84a8873 100644 --- a/wasm-web-component/Cargo.toml +++ b/wasm-web-component/Cargo.toml @@ -24,8 +24,8 @@ version = "0.3" version = "0.3" features = [ "CustomElementRegistry", + "CustomEvent", "Document", - "KeyboardEvent", "Event", "EventTarget", "Element",