Skip to content

Resolve conflicting global and element-specific attributes in prop extensions #5271

@matous-volf

Description

@matous-volf

Feature Request

Some attributes specific to different elements conflict with global attributes. For instance, if we slightly modify an example from the docs to extend input instead of button,

fn app() -> Element {
    rsx! {
        Input {
            // A global AND an input-specific attribute
            width: "10px",
            // An input-specific attribute
            disabled: true,
        }
    }
}

#[component]
fn Input(
    #[props(extends = GlobalAttributes, extends = input)]
    attributes: Vec<Attribute>,
) -> Element {
    rsx! {
        input { ..attributes }
    }
}

we get

error[E0034]: multiple applicable items in scope
  --> src/main.rs:18:13
   |
18 |             width: "10px",
   |             ^^^^^ multiple `width` found
   |
note: candidate #1 is defined in an impl of the trait `dioxus::prelude::GlobalAttributesExtension` for the type `InputPropsBuilder<(__attributes,)>`
note: candidate #2 is defined in an impl of the trait `dioxus::prelude::InputExtension` for the type `InputPropsBuilder<(__attributes,)>`

This is because width is both a global and an input-specific attribute. It is not precisely a bug, the docs clearly state this behaviour. Still, it would be nice to be able to write code like the example above. The element-specific attributes (candidate #2 in the error message) should be preffered over the global ones.

I've come accross this with width, height and autofocus.

Implement Suggestion

Maybe just deleting the element-specific attributes (like deleting this line) would solve this, but I'm afraid it's not that simple. The conflicting attributes might have different types (?), which could be an issue, but I'm not sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions