dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Remove invalid `data` attribute

Open TheLostLambda opened this issue 10 months ago • 2 comments

It appears that https://docs.rs/dioxus-html/latest/dioxus_html/elements/div/constant.data.html isn't really a valid attribute? The link to MDN on that doc page is also broken!

As far as I understand (this could be incorrect), data by itself isn't a valid attribute; rather, the data-* prefix is a namespace for the user to add custom attributes! https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/data-*

You can still write these custom attributes via the "" syntax:

div {
    class: "tooltip",
    "data-tip": "This is the text content of the tooltip!",

    ...
}

But it might be nice to have some native support by Dioxus for this? Perhaps just converting data_* into data-* so you don't need the quotes and things are still valid Rust identifiers?

If that's not a box we want to open, however, then maybe we should just remove this confusing (and I believe invalid?) attribute from the docs / code.

TheLostLambda avatar Jun 02 '25 13:06 TheLostLambda

That attribute should be removed.

I don't think we should support the data_ syntax for data attributes because we can't provide any guarantees that the attribute name is correct. It would be nice to support extending the existing HTML namespace with your own attributes like data_triggered: "data-triggered". After the declaration, the attribute would be checked, and you could use it without quotes. There is a tracking issue for that feature here: https://github.com/DioxusLabs/dioxus/issues/2040

ealmloff avatar Jun 02 '25 14:06 ealmloff

I have raised PR #4270 that resolves this issue. P.S.: This is my first contribution to Dioxus (it seems an exciting project to me). Please feel free to let me know if there are any potential changes I should make or keep in mind for future contributions.

navyansh007 avatar Jun 12 '25 16:06 navyansh007