Skip to content

Commit

Permalink
Determine checkbox checked status based on presence of checked attrib…
Browse files Browse the repository at this point in the history
…ute (ignoring value)
  • Loading branch information
nicoburns committed Sep 7, 2024
1 parent f98e402 commit bea7717
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
6 changes: 1 addition & 5 deletions packages/blitz/src/renderer/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,11 +1213,7 @@ impl ElementCx<'_> {
if self.element.local_name() == "input"
&& matches!(self.element.attr(local_name!("type")), Some("checkbox"))
{
let checked: bool = self
.element
.attr(local_name!("checked"))
.and_then(|c| c.parse().ok())
.unwrap_or_default();
let checked = self.element.attr(local_name!("checked")).is_some();

// TODO this should be coming from css accent-color, but I couldn't find how to retrieve it
let accent_color = self.style.get_inherited_text().color.as_vello();
Expand Down
32 changes: 15 additions & 17 deletions packages/dom/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,26 +308,24 @@ impl Document {
}

pub fn toggle_checkbox(el: &mut ElementNodeData) {
let checked_attr_opt = el
let is_checked = el
.attrs
.iter_mut()
.find(|attr| attr.name.local == local_name!("checked"));
.iter()
.any(|attr| attr.name.local == local_name!("checked"));

let checked_attr = if let Some(attr) = checked_attr_opt {
attr
} else {
let attr = Attribute {
name: QualName::new(None, ns!(html), local_name!("checked")),
value: String::from("false"),
};
el.attrs.push(attr);
if is_checked {
el.attrs
.iter_mut()
.find(|attr| attr.name.local == local_name!("checked"))
.unwrap()
};
let checked = checked_attr.value.parse().unwrap_or(false);
checked_attr.value = (!checked).to_string();
.retain(|attr| attr.name.local != local_name!("checked"))
} else {
el.attrs.push(Attribute {
name: QualName {
prefix: None,
ns: ns!(html),
local: local_name!("checked"),
},
value: String::new(),
})
}
}

pub fn root_node(&self) -> &Node {
Expand Down

0 comments on commit bea7717

Please sign in to comment.