Compare commits

..

1 Commits

Author SHA1 Message Date
Greg Johnston
2d7fe46661 docs: add document on adding class and other attributes to <A/> component 2025-06-15 13:26:51 -04:00
4 changed files with 20 additions and 21 deletions

View File

@@ -66,6 +66,25 @@ where
/// This is helpful for accessibility and for styling. For example, maybe you want to set the link a
/// different color if its a link to the page youre currently on.
///
/// ### Additional Attributes
///
/// You can add additional HTML attributes to the `<a>` element created by this component using the attribute
/// spreading syntax for components. For example, to add a class, you can use `attr:class="my-link"`.
/// Alternately, you can add any number of HTML attributes (include `class`) after a `{..}` marker.
///
/// ```rust
/// # use leptos::prelude::*; use leptos_router::components::A;
/// # fn spread_example() -> impl IntoView {
/// view! {
/// <A href="/about" attr:class="my-link" {..} id="foo">"Some link"</A>
/// <A href="/about" {..} class="my-link" id="bar">"Another link"</A>
/// <A href="/about" {..} class:my-link=true id="baz">"One more"</A>
/// }
/// # }
/// ```
///
/// For more information on this attribute spreading syntax, [see here](https://book.leptos.dev/view/03_components.html#spreading-attributes-onto-components).
///
/// ### DOM Properties
///
/// `<a>` elements can take several additional DOM properties with special meanings.

View File

@@ -709,7 +709,7 @@ where
buf.push('<');
buf.push_str(E::TAG);
<At as ToTemplate>::to_template_attribute(
<At as ToTemplate>::to_template(
buf,
&mut class,
&mut style,

View File

@@ -437,17 +437,6 @@ pub trait ToTemplate {
inner_html: &mut String,
position: &mut Position,
);
/// Renders a view type to a template in attribute position.
fn to_template_attribute(
buf: &mut String,
class: &mut String,
style: &mut String,
inner_html: &mut String,
position: &mut Position,
) {
Self::to_template(buf, class, style, inner_html, position);
}
}
/// Keeps track of what position the item currently being hydrated is in, relative to its siblings

View File

@@ -103,15 +103,6 @@ impl ToTemplate for () {
) {
buf.push_str("<!>");
}
fn to_template_attribute(
_buf: &mut String,
_class: &mut String,
_style: &mut String,
_inner_html: &mut String,
_position: &mut Position,
) {
}
}
impl<A: Render> Render for (A,) {