Skip to content

fix: Reset checked and value on attribute remove #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- Implemented `IntoNodes` for `Option<Node<Msg>>` and `Option<Vec<Node<Msg>>>`.
- Added example `graphql` (#400).
- Implemented `UpdateEl` for `i64` and `u64`.
- Reset properties `checked` and `value` on attribute remove (#405).

## v0.6.0
- Implemented `UpdateEl` for `Filter` and `FilterMap`.
Expand Down
30 changes: 25 additions & 5 deletions src/browser/dom/virtual_dom_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,33 @@ pub fn patch_el_details<Ms>(
})
}
// Remove attributes that aren't in the new vdom.
for name in old.attrs.vals.keys() {
if new.attrs.vals.get(name).is_none() {
for (key, old_val) in &old.attrs.vals {
if new.attrs.vals.get(key).is_none() {
// todo get to the bottom of this
match old_el_ws.dyn_ref::<web_sys::Element>() {
Some(el) => el
.remove_attribute(name.as_str())
.expect("Removing an attribute"),
Some(el) => {
el.remove_attribute(key.as_str())
.expect("Removing an attribute");

// We handle value in the vdom using attributes, but the DOM needs
// to use set_value or set_checked.
match key {
At::Value => match old_val {
AtValue::Some(_) => crate::util::set_value(old_el_ws, ""),
_ => Ok(()),
},
At::Checked => match old_val {
AtValue::Some(_) | AtValue::None => {
crate::util::set_checked(old_el_ws, false)
}
_ => Ok(()),
},
_ => Ok(()),
}
.unwrap_or_else(|err| {
crate::error(err);
})
}
None => {
crate::error("Minor error on html element (setting attrs)");
}
Expand Down