diff --git a/packages/ui/render.js b/packages/ui/render.js index 4d98bf6a79..065ae8fd14 100644 --- a/packages/ui/render.js +++ b/packages/ui/render.js @@ -301,9 +301,19 @@ var materialize = function (node, parent, before, parentComponent) { updateAttributes(elem, attrs); } } - _.each(node, function (child) { - materialize(child, elem, null, parentComponent); - }); + if (node.tagName === 'TEXTAREA') { + var value = ''; + _.each(node, function (child) { + // XXX put the functionality of attributeValueToString in + // something like UI.toText(node) + value += attributeValueToString(child); + }); + elem.value = value; + } else { + _.each(node, function (child) { + materialize(child, elem, null, parentComponent); + }); + } insert(elem, parent, before); } else if (type === 'array') { _.each(node, function (child) { @@ -507,9 +517,17 @@ var toHTML = function (node, parentComponent) { }); } result += '>'; + var contents = ''; _.each(node, function (child) { - result += toHTML(child, parentComponent); + contents += toHTML(child, parentComponent); }); + if (node.tagName === 'TEXTAREA' && + contents.slice(0, 1) === '\n') { + // TEXTAREA will absorb a newline, so if we see one, add + // another one. + result += '\n'; + } + result += contents; if (node.length || ! HTML.isVoidElement(node.tagName)) { // "Void" elements like BR are the only ones that don't get a close // tag in HTML5. They shouldn't have contents, either, so we could diff --git a/packages/ui/render_tests.js b/packages/ui/render_tests.js index d9a4814380..d6f9052ba5 100644 --- a/packages/ui/render_tests.js +++ b/packages/ui/render_tests.js @@ -12,6 +12,7 @@ var UL = HTML.Tag.UL; var LI = HTML.Tag.LI; var SPAN = HTML.Tag.SPAN; var HR = HTML.Tag.HR; +var TEXTAREA = HTML.Tag.TEXTAREA; Tinytest.add("ui - render - basic", function (test) { var run = function (input, expectedInnerHTML, expectedHTML, expectedCode) { @@ -70,6 +71,44 @@ Tinytest.add("ui - render - basic", function (test) { '
Two
Three
Two
Three