mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
added HtmlElement::attr_bool
helper method
This commit is contained in:
parent
8999a24ec3
commit
a51c12d152
1 changed files with 12 additions and 0 deletions
|
@ -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)));
|
||||
|
|
Loading…
Reference in a new issue