mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
This commit is contained in:
parent
e29f6a884f
commit
c8e6d18139
3 changed files with 22 additions and 3 deletions
|
@ -576,6 +576,17 @@ impl<El: ElementDescriptor + 'static> HtmlElement<El> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Adds a list of classes separated by ASCII whitespace to an element.
|
||||
#[track_caller]
|
||||
pub fn classes(self, classes: impl Into<Cow<'static, str>>) -> Self {
|
||||
let classes = classes.into();
|
||||
let mut this = self;
|
||||
for class in classes.split_ascii_whitespace() {
|
||||
this = this.class(class.to_string(), true);
|
||||
}
|
||||
this
|
||||
}
|
||||
|
||||
/// Sets a property on an element.
|
||||
#[track_caller]
|
||||
pub fn prop(
|
||||
|
|
|
@ -107,10 +107,15 @@ pub(crate) fn class_expression(
|
|||
|
||||
if force || !HydrationCtx::is_hydrating() {
|
||||
let class_name = wasm_bindgen::intern(class_name);
|
||||
|
||||
if value {
|
||||
class_list.add_1(class_name).unwrap_throw();
|
||||
if let Err(e) = class_list.add_1(class_name) {
|
||||
crate::error!("[HtmlElement::class()] {e:?}");
|
||||
}
|
||||
} else {
|
||||
class_list.remove_1(class_name).unwrap_throw();
|
||||
if let Err(e) = class_list.remove_1(class_name) {
|
||||
crate::error!("[HtmlElement::class()] {e:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -748,7 +748,10 @@ fn element_to_tokens(
|
|||
None => quote! {},
|
||||
Some(class) => {
|
||||
quote! {
|
||||
.class(#class, true)
|
||||
.classes(
|
||||
#[allow(unused_braces)]
|
||||
#class
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue