Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide type checking support for HTML attribute values in rsx macro #2398

Open
mrgzi opened this issue May 8, 2024 · 0 comments
Open

Provide type checking support for HTML attribute values in rsx macro #2398

mrgzi opened this issue May 8, 2024 · 0 comments

Comments

@mrgzi
Copy link

mrgzi commented May 8, 2024

Feature Request

Since Rust is a strongly typed language, it seems sensible to check types in HTML attribute values as well. Currently, rsx macro allows the following usage:

pub fn component() -> Element {
    rsx! {
        input {
            r#type: "text",
            maxlength: "10",
        }
    }
}

However, the maxlength attribute should actually be an integer:

pub fn component() -> Element {
    rsx! {
        input {
            r#type: "text",
            maxlength: 10,
        }
    }
}

Implement Suggestion

Forcing developers to use strongly typed HTML might not be a good idea. However, this feature could still be beneficial for some. I propose two options:

  1. We could issue compiler warnings instead of errors for type mismatches.
  2. We could introduce a configuration option in Dioxus.toml, such as typed_rsx = true, which would make the rsx macro emit errors if there are type mismatches in attribute values.

I’m also considering whether it would be a good idea to define enums for types like InputType, etc.

Another consideration is that traditionally, HTML attributes always accept strings:

<label for="name">Name (4 to 8 characters):</label>
<input type="text" id="name" name="name" required minlength="4" maxlength="8" size="10" />

While I am still not sure whether this is a good idea, I would like to get opinions about this feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant