Skip to content

Commit 853b849

Browse files
committed
fix: Reset checked and value on attribute remove
1 parent f4854ba commit 853b849

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/browser/dom/virtual_dom_bridge.rs

+25-5
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,33 @@ pub fn patch_el_details<Ms>(
260260
})
261261
}
262262
// Remove attributes that aren't in the new vdom.
263-
for name in old.attrs.vals.keys() {
264-
if new.attrs.vals.get(name).is_none() {
263+
for (key, old_val) in &old.attrs.vals {
264+
if new.attrs.vals.get(key).is_none() {
265265
// todo get to the bottom of this
266266
match old_el_ws.dyn_ref::<web_sys::Element>() {
267-
Some(el) => el
268-
.remove_attribute(name.as_str())
269-
.expect("Removing an attribute"),
267+
Some(el) => {
268+
el.remove_attribute(key.as_str())
269+
.expect("Removing an attribute");
270+
271+
// We handle value in the vdom using attributes, but the DOM needs
272+
// to use set_value or set_checked.
273+
match key {
274+
At::Value => match old_val {
275+
AtValue::Some(_) => crate::util::set_value(old_el_ws, ""),
276+
_ => Ok(()),
277+
},
278+
At::Checked => match old_val {
279+
AtValue::Some(_) | AtValue::None => {
280+
crate::util::set_checked(old_el_ws, false)
281+
}
282+
_ => Ok(()),
283+
},
284+
_ => Ok(()),
285+
}
286+
.unwrap_or_else(|err| {
287+
crate::error(err);
288+
})
289+
}
270290
None => {
271291
crate::error("Minor error on html element (setting attrs)");
272292
}

0 commit comments

Comments
 (0)