Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle [type] attribute on the Button element #1033

Merged
merged 10 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions yew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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 @@ -24,7 +24,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
jstarry marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
Expand Down Expand Up @@ -318,6 +318,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