Skip to content

Commit 09c13ea

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

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- Implemented `IntoNodes` for `Option<Node<Msg>>` and `Option<Vec<Node<Msg>>>`.
4343
- Added example `graphql` (#400).
4444
- Implemented `UpdateEl` for `i64` and `u64`.
45+
- Reset properties `checked` and `value` on attribute remove (#405).
4546

4647
## v0.6.0
4748
- Implemented `UpdateEl` for `Filter` and `FilterMap`.

src/browser/dom/virtual_dom_bridge.rs

Lines changed: 25 additions & 5 deletions
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)