Skip to content
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