mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
treat <textarea> children the same as a value attribute
This commit is contained in:
parent
8d2607c37d
commit
b828fdf855
@ -107,6 +107,20 @@ export default function visitElement ( generator: DomGenerator, block: Block, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( node.name !== 'select' ) {
|
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
|
// <select> value attributes are an annoying special case — it must be handled
|
||||||
// *after* its children have been updated
|
// *after* its children have been updated
|
||||||
visitAttributesAndAddProps();
|
visitAttributesAndAddProps();
|
||||||
|
17
test/runtime/samples/textarea-children/_config.js
Normal file
17
test/runtime/samples/textarea-children/_config.js
Normal file
@ -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
test/runtime/samples/textarea-children/main.html
Normal file
3
test/runtime/samples/textarea-children/main.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<textarea>
|
||||||
|
<p>not actually an element. {{foo}}</p>
|
||||||
|
</textarea>
|
Loading…
Reference in New Issue
Block a user