Skip to content

Commit

Permalink
treat <textarea> children the same as a value attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed May 27, 2017
1 parent 8d2607c commit b828fdf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/generators/dom/visitors/Element/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ export default function visitElement ( generator: DomGenerator, block: Block, st
}

if ( node.name !== 'select' ) {
if ( node.name === 'textarea' ) {
// this is an egregious hack, but it's the easiest way to get <textarea>
// children treated the same way as a value attribute
if ( node.children.length > 0 ) {
node.attributes.push({
type: 'Attribute',
name: 'value',
value: node.children
});

node.children = [];
}
}

// <select> value attributes are an annoying special case — it must be handled
// *after* its children have been updated
visitAttributesAndAddProps();
Expand Down
17 changes: 17 additions & 0 deletions test/runtime/samples/textarea-children/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
'skip-ssr': true, // SSR behaviour is awkwardly different

data: {
foo: 42
},

html: `<textarea></textarea>`,

test ( assert, component, target ) {
const textarea = target.querySelector( 'textarea' );
assert.strictEqual( textarea.value, `\n\t<p>not actually an element. 42</p>\n` );

component.set({ foo: 43 });
assert.strictEqual( textarea.value, `\n\t<p>not actually an element. 43</p>\n` );
}
};
3 changes: 3 additions & 0 deletions test/runtime/samples/textarea-children/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<textarea>
<p>not actually an element. {{foo}}</p>
</textarea>

0 comments on commit b828fdf

Please sign in to comment.