Skip to content

Commit

Permalink
Merge pull request #34 from sickslives/master
Browse files Browse the repository at this point in the history
defaultValue instead of value for mutable textareas by default
  • Loading branch information
Daniel15 committed Sep 13, 2015
2 parents 9056a27 + 7bc0a20 commit 8b90aa3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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

0 comments on commit 8b90aa3

Please sign in to comment.