Skip to content

defaultValue instead of value for mutable textareas by default #34

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

Merged
merged 2 commits into from
Sep 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/htmltojsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ HTMLtoJSX.prototype = {
}

if (tagName === 'textarea') {
// Hax: textareas need their inner text moved to a "value" attribute.
attributes.push('value={' + JSON.stringify(node.value) + '}');
// Hax: textareas need their inner text moved to a "defaultValue" attribute.
attributes.push('defaultValue={' + JSON.stringify(node.value) + '}');
}
if (tagName === 'pre') {
this._inPreTag = true;
Expand Down Expand Up @@ -413,7 +413,7 @@ HTMLtoJSX.prototype = {
*/
_isSelfClosing: function(node) {
// If it has children, it's not self-closing
// Exception: All children of a textarea are moved to a "value" attribute.
// Exception: All children of a textarea are moved to a "defaultValue" attribute.
return !node.firstChild || node.tagName.toLowerCase() === 'textarea';
},

Expand All @@ -426,7 +426,7 @@ HTMLtoJSX.prototype = {
var parentTag = node.parentNode && node.parentNode.tagName.toLowerCase();
if (parentTag === 'textarea') {
// Ignore text content of textareas, as it will have already been moved
// to a "value" attribute.
// to a "defaultValue" attribute.
return;
}

Expand Down
4 changes: 2 additions & 2 deletions test/htmltojsx-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ describe('htmltojsx', function() {
});

describe('special tags', function() {
it('should use "value" for textareas', function() {
it('should use "defaultValue" for textareas', function() {
var converter = new HTMLtoJSX({ createClass: false });
expect(converter.convert('<textarea>hello\nworld</textarea>').trim())
.toBe('<textarea value={"hello\\nworld"} />');
.toBe('<textarea defaultValue={"hello\\nworld"} />');
});

it('should do magic voodoo for <pre>', function() {
Expand Down