Skip to content

Commit 4b0d3d2

Browse files
captain-yossarianteymour-aldridgejstarry
authored
Handle [type] attribute on the Button element (#1033)
* 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>
1 parent 01fd132 commit 4b0d3d2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

yew/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ features = [
7171
"FocusEvent",
7272
"Headers",
7373
"HtmlElement",
74+
"HtmlButtonElement",
7475
"HtmlInputElement",
7576
"HtmlSelectElement",
7677
"HtmlTextAreaElement",

yew/src/virtual_dom/vtag.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cfg_if! {
2222
use std::ops::Deref;
2323
use wasm_bindgen::JsCast;
2424
use web_sys::{
25-
Element, HtmlInputElement as InputElement, HtmlTextAreaElement as TextAreaElement, Node,
25+
Element, HtmlInputElement as InputElement, HtmlTextAreaElement as TextAreaElement, Node, HtmlButtonElement
2626
};
2727
}
2828
}
@@ -268,6 +268,21 @@ impl VTag {
268268
}
269269
}
270270

271+
// TODO: add std_web after https://github.com/koute/stdweb/issues/395 will be approved
272+
// Check this out: https://github.com/yewstack/yew/pull/1033/commits/4b4e958bb1ccac0524eb20f63f06ae394c20553d
273+
#[cfg(feature = "web_sys")]
274+
{
275+
if let Some(button) = element.dyn_ref::<HtmlButtonElement>() {
276+
if let Some(change) = self.diff_kind(ancestor) {
277+
let kind = match change {
278+
Patch::Add(kind, _) | Patch::Replace(kind, _) => kind,
279+
Patch::Remove(_) => "",
280+
};
281+
button.set_type(kind);
282+
}
283+
}
284+
}
285+
271286
// `input` element has extra parameters to control
272287
// I override behavior of attributes to make it more clear
273288
// and useful in templates. For example I interpret `checked`

0 commit comments

Comments
 (0)