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

Conditional attributes #134

Open
tonyarnold opened this issue Jun 29, 2023 · 4 comments
Open

Conditional attributes #134

tonyarnold opened this issue Jun 29, 2023 · 4 comments
Labels
html Includes the HTML idea v3

Comments

@tonyarnold
Copy link
Contributor

In HTML, there are attributes that we'd only want to add on some condition, such as "checked" and "disabled". This is currently quite verbose to do, involving something like:

if someCondition {
  Input()
    .checked()
} else {
  Input()
}

It would be really helpful if there were support for something like:

Input()
  .checked(when: someCondition)
  .disabled(when: someConditition)
@mattesmohr
Copy link
Member

mattesmohr commented Jun 30, 2023

You can use instead:

Input()
   .modify(if: true) {
        $0.checked()
   }

But I like your idea.

I like the fact, that it's a one-liner. Let me check, if we had it in the past and I removed it for any reason.

One good thing about modify(if:), it's the universal approach.

What do you think?

@tonyarnold
Copy link
Contributor Author

Sure, that works for me for the time being :)

There are a few ergonomics changes I'd like to propose once I've used it a bit more in anger - I'll raise separate issues.

@mattesmohr mattesmohr added html Includes the HTML v3 idea labels Jun 30, 2023
@mattesmohr
Copy link
Member

mattesmohr commented Jun 30, 2023

Sure, let them come. I appreciate it. :-)

@mattesmohr
Copy link
Member

mattesmohr commented Jul 2, 2023

For alpha.6 I have added a condition option for

  • hidden
  • disabled
  • autoplay
  • readonly
  • checked
  • required

There are more, but I think it makes no sense to add it for them:

  • autofocus
  • muted
  • selected
  • novalidate
  • loop
  • ismap
  • download
  • defer
  • controls
  • async

I went through them, thinking about it from a user standpoint and what could be a possibly an option flag in the user settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
html Includes the HTML idea v3
Development

No branches or pull requests

2 participants