Skip to content

Commit

Permalink
Keep checked attribute for elements without special handling (#3373)
Browse files Browse the repository at this point in the history
* Return checked attr for non-input elements

* Add tests

* fine
  • Loading branch information
ranile authored Aug 11, 2023
1 parent daf7d21 commit 3e9e253
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/yew-macro/src/html_tree/html_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@ impl Parse for HtmlElementOpen {
if let Some(attr) = props.value.take() {
props.attributes.push(attr);
}
if let Some(attr) = props.checked.take() {
props.attributes.push(attr);
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions packages/yew/src/dom_bundle/btag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ mod layout_tests {
#[cfg(test)]
mod tests_without_browser {
use crate::html;
use crate::virtual_dom::VNode;

#[test]
fn html_if_bool() {
Expand Down Expand Up @@ -1268,4 +1269,32 @@ mod tests_without_browser {
html! { <div><></></div> },
);
}

#[test]
fn input_checked_stays_there() {
let tag = html! {
<input checked={true} />
};
match tag {
VNode::VTag(tag) => {
assert_eq!(tag.checked(), Some(true));
}
_ => unreachable!(),
}
}
#[test]
fn non_input_checked_stays_there() {
let tag = html! {
<my-el checked="true" />
};
match tag {
VNode::VTag(tag) => {
assert_eq!(
tag.attributes.iter().find(|(k, _)| *k == "checked"),
Some(("checked", "true"))
);
}
_ => unreachable!(),
}
}
}

0 comments on commit 3e9e253

Please sign in to comment.