HTMLKit
HTMLKit copied to clipboard
Conditional attributes
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)
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?
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.
Sure, let them come. I appreciate it. :-)
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.