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

Easier boolean attributes #32

Closed
tabatkins opened this issue Sep 12, 2017 · 2 comments
Closed

Easier boolean attributes #32

tabatkins opened this issue Sep 12, 2017 · 2 comments

Comments

@tabatkins
Copy link

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:

const el = html`<video controls?={showControls} url={url}></video>`;

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.)

@straker
Copy link
Owner

straker commented Sep 13, 2017

I agree that conditional attributes using a ternary is a bit clumsy. The only concern I have is that doing ?= or a similar syntax would be diverging from what is possible with innerHTML. Now I'm not saying that's a bad thing, it's just that I've been trying to figure out the right balance between how to get this proposal moving forward and getting implementer interest and all the different ways the same problem is being solved.

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 innerHTML like syntax but without the need of an outer element? Or would this be better as a higher level API, which means we should add features that break away from innerHTML but that add more conveniences for the developer?

@tabatkins
Copy link
Author

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.)

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