mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Keep checked attribute for elements without special handling (#3373)
* Return checked attr for non-input elements * Add tests * fine
This commit is contained in:
parent
daf7d21122
commit
3e9e253e66
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user