-
Notifications
You must be signed in to change notification settings - Fork 33
Default type on input set as attribute #38
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
Conversation
This is my test case:
const bel = require('bel');
console.log(bel`<input type="hidden" name="name" value="value" />`.toString());
Which currently outputs <input type="text" type="hidden" name="test" value="" /> when min-document is being used (within node).
I'm not sure where or why the type property is rendered as an attribute, but it seems like it should be set as an attribute rather than a property, which removes the duplicate rendered attribute.
|
I think this looks reasonable; If it's not too much trouble, could you perhaps add a test to catch future regressions? Thanks! ✨ |
|
I added a test, and also updated the test this had broken. |
|
@Raynos any chance we could get this in? |
dom-element.js
Outdated
|
|
||
| if (this.tagName === 'INPUT') { | ||
| this.type = 'text' | ||
| this.setAttribute('type', 'text') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎 Please do both or only properties.
Properties are source of truth, attributes are just a weird bag of stuff.
|
If properties are the source of truth, then I guess bel needs to be updated (around https://github.com/shama/bel/blob/master/index.js#L92) to set type as a property rather than an attribute. Is there any documentation of which attributes rely on properties? |
|
After looking at this more, I think I understand it better. Here's what I've found:
Updated PR does that by changing DOMElement.prototype.setAttributeNS and DOMElement.prototype.getAttributeNS so they set and get the property rather than attribute for input type. |
|
This is great, thanks @sreynen I like this solution. |
|
Fixed in 2.19.0 |
|
I ran into this bug and was directed to this PR. Could 2.19.0 be published to npm please? |
|
Never mind, my cache was stale. Carry on! |
This is my test case:
Which currently outputs
<input type="text" type="hidden" name="test" value="" />when min-document is being used via global, within node.I'm not sure where or why the type property is rendered as an attribute, but it seems like it should be set as an attribute rather than a property, which removes the duplicate rendered attribute.