Skip to content

Custom attributes for standard HTML components #3426

Answered by gbj
janschiefer asked this question in Q&A
Discussion options

You must be logged in to vote

To the best of my knowledge, that's invalid HTML, which is why the view macro rejects it. Custom attribute names need to contain a hyphen, which is what the view macro looks for, i.e., either data-datepicker or flowbite-datepicker or whatever. This is really important for forward-compatibility for the Web.

If Flowbite doesn't allow for valid versions of its attributes, you can use it without the view macro, adding the non-standard attribute name with .attr()

use leptos::html::input;

input()
    .id("datepicker-autohide")
    .attr("datepicker", true)
    .attr("datepicker-autohide", true)
    .r#type("text")
    .class("...")
    .placeholder("Select date")

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@janschiefer
Comment options

Answer selected by janschiefer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants