Skip to content

How to handle boolean attributes in HTML? #38

Open

Description

@vpzomtrrfrt

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?

Activity

  1. Schniz commented on Jul 8, 2020

    @Schniz
    Collaborator

    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?

  2. vpzomtrrfrt commented on Jul 8, 2020

    @vpzomtrrfrt
    ContributorAuthor

    That seems reasonable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions