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

How to handle boolean attributes in HTML? #38

Open
vpzomtrrfrt opened this issue Jul 8, 2020 · 2 comments
Open

How to handle boolean attributes in HTML? #38

vpzomtrrfrt opened this issue Jul 8, 2020 · 2 comments

Comments

@vpzomtrrfrt
Copy link
Contributor

vpzomtrrfrt commented Jul 8, 2020

Certain HTML attributes, such as 's "disabled", are supposed to be present for true and missing for false. Does render have any way to dynamically choose whether an attribute is output?

@Schniz
Copy link
Collaborator

Schniz commented Jul 8, 2020

We can have an enum type for HTML attributes (playground link), so:

enum HtmlAttribute {
  StringValue(String, String),
  BooleanValue(String, bool)
}

and use From<(String, String)> and From<(String, bool)> to generate HtmlAttribute — so the following syntax will be supported:

html! {
  <button disabled={true} type="button" />
}

# will be almost like

::render::SimpleElement {
  tag_name: "button",
  attributes: [HtmlAttribute::from(("disabled", true), HtmlAttribute::from(("type", "button"))],
  children: None
}

What do you think?

@vpzomtrrfrt
Copy link
Contributor Author

That seems reasonable

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

2 participants