diff --git a/packages/yew-macro/tests/classes_macro/classes-pass.rs b/packages/yew-macro/tests/classes_macro/classes-pass.rs index 4735e303d50..fb73e802e1c 100644 --- a/packages/yew-macro/tests/classes_macro/classes-pass.rs +++ b/packages/yew-macro/tests/classes_macro/classes-pass.rs @@ -49,6 +49,11 @@ fn compile_pass() { // single expression ::yew::classes!(::std::vec!["one", "two"]); + // single array + ::yew::classes!(["one", "two"]); + // multiple arrays + ::yew::classes!(["one"], ["two"]); + // optional classes ::yew::classes!( ::std::option::Option::Some("one"), @@ -58,7 +63,7 @@ fn compile_pass() { // mixed types { use ::std::borrow::ToOwned; - ::yew::classes!("one".to_owned(), "two", ::std::vec!["three"]); + ::yew::classes!("one".to_owned(), "two", ::std::vec!["three"], ["four", "five"]); } } diff --git a/packages/yew/src/html/classes.rs b/packages/yew/src/html/classes.rs index f7217278427..0a5bb9cc9b0 100644 --- a/packages/yew/src/html/classes.rs +++ b/packages/yew/src/html/classes.rs @@ -274,6 +274,12 @@ impl + Clone> From<&[T]> for Classes { } } +impl, const SIZE: usize> From<[T; SIZE]> for Classes { + fn from(t: [T; SIZE]) -> Self { + t.into_iter().collect() + } +} + impl PartialEq for Classes { fn eq(&self, other: &Self) -> bool { self.set.len() == other.set.len() && self.set.iter().eq(other.set.iter()) diff --git a/website/docs/concepts/html/classes.mdx b/website/docs/concepts/html/classes.mdx index 5cd87106813..1e6e85d1d53 100644 --- a/website/docs/concepts/html/classes.mdx +++ b/website/docs/concepts/html/classes.mdx @@ -84,10 +84,8 @@ html! { ```rust use yew::{classes, html}; -let my_classes = ["class-1", "class-2"]; - html! { -
+
}; ```