mirror of
https://github.com/leptos-rs/leptos
synced 2024-09-20 14:32:00 +00:00
This commit is contained in:
parent
328d42656d
commit
b80f9e3871
2 changed files with 16 additions and 2 deletions
|
@ -658,6 +658,15 @@ impl<El: ElementDescriptor + 'static> HtmlElement<El> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a class to an element.
|
/// Adds a class to an element.
|
||||||
|
///
|
||||||
|
/// **Note**: In the builder syntax, this will be overwritten by the `class`
|
||||||
|
/// attribute if you use `.attr("class", /* */)`. In the `view` macro, they
|
||||||
|
/// are automatically re-ordered so that this over-writing does not happen.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
/// This directly uses the browser’s `classList` API, which means it will throw
|
||||||
|
/// a runtime error if you pass more than a single class name. If you want to
|
||||||
|
/// pass more than one class name at a time, you can use [HtmlElement::classes].
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn class(
|
pub fn class(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -842,7 +842,8 @@ fn element_to_tokens(
|
||||||
};
|
};
|
||||||
let attrs = node.attributes.iter().filter_map(|node| {
|
let attrs = node.attributes.iter().filter_map(|node| {
|
||||||
if let Node::Attribute(node) = node {
|
if let Node::Attribute(node) = node {
|
||||||
if node.key.to_string().trim().starts_with("class:") {
|
let name = node.key.to_string();
|
||||||
|
if name.trim().starts_with("class:") || fancy_class_name(&name, cx, node).is_some() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(attribute_to_tokens(cx, node, global_class))
|
Some(attribute_to_tokens(cx, node, global_class))
|
||||||
|
@ -853,7 +854,11 @@ fn element_to_tokens(
|
||||||
});
|
});
|
||||||
let class_attrs = node.attributes.iter().filter_map(|node| {
|
let class_attrs = node.attributes.iter().filter_map(|node| {
|
||||||
if let Node::Attribute(node) = node {
|
if let Node::Attribute(node) = node {
|
||||||
if node.key.to_string().trim().starts_with("class:") {
|
let name = node.key.to_string();
|
||||||
|
if let Some((fancy, _, _)) = fancy_class_name(&name, cx, node) {
|
||||||
|
Some(fancy)
|
||||||
|
}
|
||||||
|
else if name.trim().starts_with("class:") {
|
||||||
Some(attribute_to_tokens(cx, node, global_class))
|
Some(attribute_to_tokens(cx, node, global_class))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Reference in a new issue