added HtmlElement::attr_bool helper method

This commit is contained in:
Jose Quesada 2022-11-27 09:45:38 -06:00
parent 8999a24ec3
commit a51c12d152

View file

@ -113,6 +113,11 @@ impl<El: IntoElement> HtmlElement<El> {
"to set the `id`, please use `HtmlElement::id` instead"
);
assert_ne!(
name, "class",
"to set classes, please use `HtmlElement::class` instead"
);
assert!(
!self.attrs.iter().any(|(n, _)| n == &name),
"attribute `{name}` already set"
@ -124,6 +129,13 @@ impl<El: IntoElement> HtmlElement<El> {
self
}
/// Sets a boolean attribute on the element, i.e., `checked`, or `disabled` in
/// `<input type="checkbox" checked disabled />`
#[track_caller]
pub fn attr_bool(mut self, name: impl Into<Cow<'static, str>>) -> Self {
self.attr(name, "")
}
/// Inserts a child into this element.
pub fn child<C: IntoNode + 'static>(mut self, child: C) -> Self {
self.children.push(Box::new(move |cx| child.into_node(cx)));