Skip to content

Commit

Permalink
Handle [type] attribute on the Button element (#1033)
Browse files Browse the repository at this point in the history
* initial

* handle button

* handle button

* remove std_web

* merge

* revert

* Fix unresolved import error. (#5)

* fix yew-stdweb

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>
Co-authored-by: Justin Starry <justin.starry@icloud.com>
  • Loading branch information
3 people authored May 26, 2020
1 parent 01fd132 commit 4b0d3d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions yew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ features = [
"FocusEvent",
"Headers",
"HtmlElement",
"HtmlButtonElement",
"HtmlInputElement",
"HtmlSelectElement",
"HtmlTextAreaElement",
Expand Down
17 changes: 16 additions & 1 deletion yew/src/virtual_dom/vtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}
Expand Down Expand Up @@ -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::<HtmlButtonElement>() {
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`
Expand Down

0 comments on commit 4b0d3d2

Please sign in to comment.