docsite icon indicating copy to clipboard operation
docsite copied to clipboard

Attribute spreading (`..props.attributes` syntax) is not documented

Open chrivers opened this issue 10 months ago • 1 comments

Attribute "spreading" (I wish we could find a new name for this.. 😅) is the process of assigning properties from a "catch-all" collection.

This is very useful for developing reusable components, but it's completely missing from the docsite.

Here's an example, adapted from https://github.com/DioxusLabs/dioxus/issues/3844:

#[derive(Props, PartialEq, Debug, Clone)]
pub struct ChildProps {
    #[props(extends = button, extends = GlobalAttributes)]
    pub attributes: Vec<Attribute>,
    #[props(optional, default = None)]
    pub children: Element,
}

#[component]
pub fn Child(props: ChildProps) -> Element {
    rsx! {
        button {
            ..props.attributes,
            {props.children}
        }
    }
}

#[component]
pub fn Hero() -> Element {
    rsx! {
        Child {
            class: "hard-to-miss",
            style: "border: 1px solid lime;",
            "Content here..",
        }
    }
}

It would be very nice to have this feature mentioned in the documentation.

chrivers avatar Apr 19 '25 14:04 chrivers

This is now mentioned briefly here with a link to more info on docs.rs

ealmloff avatar Nov 19 '25 18:11 ealmloff