-
Notifications
You must be signed in to change notification settings - Fork 13
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
Easier boolean attributes #32
Comments
I agree that conditional attributes using a ternary is a bit clumsy. The only concern I have is that doing Since you've been around the block a time or two getting proposals through the spec groups, at what level do you see this API falling under? Should it be something low level that mimics |
Depends! Both are valid approaches. In particular, trying to piggyback on whatwg/html#3052 might be useful; the implementors there want to be able to produce "trusted HTML" types, where you know for sure that what you're inserting isn't vulnerable to injection, and having a powerful built-in template to do that with can be useful. You don't want to go too far, but putting in just a few small conveniences might make it more attractive. (Libraries will be able to produce these themselves, so they can handle more complicated/weird templating semantics on their own.) |
From the usage example, it looks like boolean attributes currently have to be manually handled by outputting either their name or an empty string, using a ternary.
This is a bit clumsy. It would be a lot more aesthetically appealing if you could write something like:
That is, if the attr name is followed by a
?=
operator, its value is checked as a boolean, and the attribute is either included or omitted accordingly.(Any similar sort of syntax would work, of course.)
The text was updated successfully, but these errors were encountered: