-
Notifications
You must be signed in to change notification settings - Fork 48
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
Boolean attributes #14
Comments
I think this is a bug in the parser. |
Any update on this? |
Fixed in 2.0.1. This was very non-trivial to fix! Booleans throw a wrench into lots of places in the parser. |
@substack Nice fix! I spent more time than I care to admit trying to fix it too, but gave up. Glad you got it fixed! |
@substack Sadly, this doesn't seem fully fixed. If the boolean attribute is followed by a normal attribute, it crashes hyperx with Here's a test case: var test = require('tape')
var vdom = require('virtual-dom')
var hyperx = require('../')
var hx = hyperx(vdom.h)
test('boolean attribute followed by normal attribute', function (t) {
var tree = hx`<video autoplay volume="50"></video>`
t.equal(vdom.create(tree).toString(), '<video autoplay="autoplay" volume="50"></video>')
t.end()
}) |
Fixed in 2.0.2 and I added this case to the test suite. Re-open if there are any more failing cases. |
@feross @substack I spent too long on this too before giving up. I really appreciate you both getting this in! |
Hey! Not sure if I’m doing something wrong, but this works: hx`<div aria-hidden="${isVisible ? 'false' : 'true'}">content</div>` And this does not: hx`<div ${isVisible ? '' : 'aria-hidden="true"'}">content</div>` So I can toggle between attribute values, but can’t omit an attribute entirely, based on a condition. |
@arturi AFAIK, that currently isn't possible as the parser needs to know whether it's in a attribute and can't evaluate an expression to determine it. The library that constructs the element should know that a boolean attribute set to content `` be the correct practice.
For example in bel, if the attribute is |
All right, got it, thanks! Refactored to I’m using |
@arturi It likely could be but depends on it's common usage. Looking at the examples on MDN, it looked like it was common to set |
@substack: Is there a way to write boolean attributes, such as
checked
on<input type="checkbox"/>
?I've tried various combinations of keys and values, and I can't get anything passed through to the wrapped hyperscript function.The text was updated successfully, but these errors were encountered: