DioxusLabs / DioxusLabs/dioxus
Resolve conflicting global and element-specific attributes in prop extensions
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
## Feature Request
Some attributes specific to different elements conflict with global attributes. For instance, if we slightly modify an [example from the docs](https://docs.rs/dioxus/0.7.3/dioxus/prelude/attr.component.html#extending-elements) to extend `input` instead of `button`,
```rs
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,
) -> 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](https://github.com/DioxusLabs/dioxus/blob/9b0d380765301ae7fe337fba8438fcbb814f8748/packages/html/src/attribute_groups.rs#L1546) and an [input](https://github.com/DioxusLabs/dioxus/blob/9b0d380765301ae7fe337fba8438fcbb814f8748/packages/html/src/elements.rs#L1457)-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](https://github.com/DioxusLabs/dioxus/blob/9b0d380765301ae7fe337fba8438fcbb814f8748/packages/html/src/elements.rs#L1457)) 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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.