Closed batiste closed 9 years ago
The property name for the attribute for
is htmlFor
[1]. Changing for:1
to htmlFor: 1
should work.
Do you have a list of those properties like class -> className, for -> htmlFor ?
I imagine it is something inherent to the DOM model somehow... It would be nice to not have to care about those details in the API
We have an attribute:property mapping on a project that uses virtual-dom because we convert templates to vdom objects and we know everything is getting passed in as an attribute.
You can also pass in attributes directly to virtual-dom by using the attributes
property. So your example could also look like this and work:
virtualDom.create(virtualDom.h('label', {attributes:{for: 1}, title:2}))
virtual-dom doesn't try to have an opinion about this. We just give you a way to set properties and attributes on nodes
To anyone finding this in the future... I just published a package hyperscript-attribute-to-property
to solve this issue.
Use it like this:
var attrToProp = require('hyperscript-attribute-to-property')
var h = attrToProp(require('virtual-dom/h'))
Then, you can do this:
var vnode = h('div', { class: 'my-class' })
Instead of this:
var vnode = h('div', { className: 'my-class' })
Works with for
and the others, too :)
Why does the "for" attribute doesn't work?