fix: compile attr:aria-* syntax (#2887)

This commit is contained in:
luoxiaozero 2024-08-28 00:00:13 +08:00 committed by GitHub
parent 58476bb98e
commit 7dc58e248c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -547,10 +547,12 @@ pub(crate) fn attribute_absolute(
node: &KeyedAttribute, node: &KeyedAttribute,
after_spread: bool, after_spread: bool,
) -> Option<TokenStream> { ) -> Option<TokenStream> {
let contains_dash = node.key.to_string().contains('-'); let key = node.key.to_string();
let contains_dash = key.contains('-');
let attr_aira = key.starts_with("attr:aria-");
// anything that follows the x:y pattern // anything that follows the x:y pattern
match &node.key { match &node.key {
NodeName::Punctuated(parts) if !contains_dash => { NodeName::Punctuated(parts) if !contains_dash || attr_aira => {
if parts.len() >= 2 { if parts.len() >= 2 {
let id = &parts[0]; let id = &parts[0];
match id { match id {
@ -566,6 +568,14 @@ pub(crate) fn attribute_absolute(
Some( Some(
quote! { ::leptos::tachys::html::#key::#key(#value) }, quote! { ::leptos::tachys::html::#key::#key(#value) },
) )
} else if key_name == "aria" {
let mut parts_iter = parts.iter();
parts_iter.next();
let fn_name = parts_iter.map(|p| p.to_string()).collect::<Vec<String>>().join("_");
let key = Ident::new(&fn_name, key.span());
Some(
quote! { ::leptos::tachys::html::attribute::#key(#value) },
)
} else { } else {
Some( Some(
quote! { ::leptos::tachys::html::attribute::#key(#value) }, quote! { ::leptos::tachys::html::attribute::#key(#value) },