diff --git a/yew/Cargo.toml b/yew/Cargo.toml index ff3e9ce9537..8160b0723ae 100644 --- a/yew/Cargo.toml +++ b/yew/Cargo.toml @@ -71,6 +71,7 @@ features = [ "FocusEvent", "Headers", "HtmlElement", + "HtmlButtonElement", "HtmlInputElement", "HtmlSelectElement", "HtmlTextAreaElement", diff --git a/yew/src/virtual_dom/vtag.rs b/yew/src/virtual_dom/vtag.rs index 4c770bf32cb..0ed95b482e1 100644 --- a/yew/src/virtual_dom/vtag.rs +++ b/yew/src/virtual_dom/vtag.rs @@ -22,7 +22,7 @@ cfg_if! { use std::ops::Deref; use wasm_bindgen::JsCast; use web_sys::{ - Element, HtmlInputElement as InputElement, HtmlTextAreaElement as TextAreaElement, Node, + Element, HtmlInputElement as InputElement, HtmlTextAreaElement as TextAreaElement, Node, HtmlButtonElement }; } } @@ -268,6 +268,21 @@ impl VTag { } } + // TODO: add std_web after https://github.com/koute/stdweb/issues/395 will be approved + // Check this out: https://github.com/yewstack/yew/pull/1033/commits/4b4e958bb1ccac0524eb20f63f06ae394c20553d + #[cfg(feature = "web_sys")] + { + if let Some(button) = element.dyn_ref::() { + if let Some(change) = self.diff_kind(ancestor) { + let kind = match change { + Patch::Add(kind, _) | Patch::Replace(kind, _) => kind, + Patch::Remove(_) => "", + }; + button.set_type(kind); + } + } + } + // `input` element has extra parameters to control // I override behavior of attributes to make it more clear // and useful in templates. For example I interpret `checked`