diff --git a/packages/primitives/leptos/accessible-icon/src/accessible_icon.rs b/packages/primitives/leptos/accessible-icon/src/accessible_icon.rs index 1854c70c..c6120b42 100644 --- a/packages/primitives/leptos/accessible-icon/src/accessible_icon.rs +++ b/packages/primitives/leptos/accessible-icon/src/accessible_icon.rs @@ -1,37 +1,26 @@ use leptos::{ - attr::{ - AriaHidden, Attr, NextAttribute, aria_hidden, - custom::{CustomAttr, custom_attribute}, - }, + attr::{aria_hidden, custom::custom_attribute}, prelude::*, }; use radix_leptos_visually_hidden::VisuallyHidden; -pub type AccessibleIconAttrs = ( - Attr, - CustomAttr<&'static str, &'static str>, -); - -pub fn use_accessible_icon() -> AccessibleIconAttrs { - aria_hidden("true").add_any_attr(custom_attribute("focusable", "false")) -} - #[component] -pub fn AccessibleIcon( - /// The accessible label for the icon. This label will be visually hidden but announced to screen reader users, - /// similar to `alt` text for `img` tags. +pub fn AccessibleIcon( + /// The accessible label for the icon. This label will be visually hidden but announced to screen reader users, similar to `alt` text for `img` tags. #[prop(into)] label: Signal, - render: R, -) -> impl IntoView -where - R: Fn(AccessibleIconAttrs) -> IV, - IV: IntoView, -{ - let attrs = use_accessible_icon(); - + children: TypedChildren, +) -> impl IntoView { + let label = Signal::derive(move || label.get()); view! { - {render(attrs)} - {label} + <> + {children + .into_inner()() + // Accessibility + .add_any_attr(aria_hidden("true")) + // See: https://allyjs.io/tutorials/focusing-in-svg.html#making-svg-elements-focusable + .add_any_attr(custom_attribute("focusable", "false"))} + {label.get()} + } } diff --git a/stories/leptos/src/primitives/accessible_icon.rs b/stories/leptos/src/primitives/accessible_icon.rs index 54b1f1e0..cc870bf5 100644 --- a/stories/leptos/src/primitives/accessible_icon.rs +++ b/stories/leptos/src/primitives/accessible_icon.rs @@ -1,16 +1,13 @@ use leptos::prelude::*; -use radix_leptos_accessible_icon::*; +use radix_leptos_accessible_icon::AccessibleIcon; #[component] pub fn Styled() -> impl IntoView { view! { - } } @@ -20,12 +17,9 @@ pub fn Chromatic() -> impl IntoView { view! {

Some text with an inline accessible icon{" "} - - } - /> + + +

} }