Keep checked attribute for elements without special handling (#3373)

* Return checked attr for non-input elements

* Add tests

* fine
This commit is contained in:
Muhammad Hamza 2023-08-11 22:16:06 +05:00 committed by GitHub
parent daf7d21122
commit 3e9e253e66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -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);
}
}
}
}

View File

@ -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() {
@ -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!(),
}
}
}