diff --git a/src/generators/dom/visitors/attributes/binding/index.js b/src/generators/dom/visitors/attributes/binding/index.js index b8344cd14632..4123f3ad7ac9 100644 --- a/src/generators/dom/visitors/attributes/binding/index.js +++ b/src/generators/dom/visitors/attributes/binding/index.js @@ -33,13 +33,18 @@ export default function createBinding ( generator, node, attribute, current, loc let eventName = 'change'; if ( node.name === 'input' ) { - const type = node.attributes.find( attr => attr.type === 'Attribute' && attr.name === 'type' ); - if ( !type || type.value[0].data === 'text' ) { - // TODO in validation, should throw if type attribute is not static + const typeAttribute = node.attributes.find( attr => attr.type === 'Attribute' && attr.name === 'type' ); + const type = typeAttribute ? typeAttribute.value[0].data : 'text'; // TODO in validation, should throw if type attribute is not static + + if ( type !== 'checkbox' && type !== 'radio' ) { eventName = 'input'; } } + else if ( node.name === 'textarea' ) { + eventName = 'input'; + } + let value; if ( local.isComponent ) { diff --git a/test/generator/binding-textarea/_config.js b/test/generator/binding-textarea/_config.js new file mode 100644 index 000000000000..3ba2735c9081 --- /dev/null +++ b/test/generator/binding-textarea/_config.js @@ -0,0 +1,32 @@ +export default { + data: { + value: 'some text' + }, + + html: ` + +

some text

+ `, + + test ( assert, component, target, window ) { + const textarea = target.querySelector( 'textarea' ); + assert.equal( textarea.value, 'some text' ); + + const event = new window.Event( 'input' ); + + textarea.value = 'hello'; + textarea.dispatchEvent( event ); + + assert.htmlEqual( target.innerHTML, ` + +

hello

+ ` ); + + component.set({ value: 'goodbye' }); + assert.equal( textarea.value, 'goodbye' ); + assert.htmlEqual( target.innerHTML, ` + +

goodbye

+ ` ); + } +}; diff --git a/test/generator/binding-textarea/main.html b/test/generator/binding-textarea/main.html new file mode 100644 index 000000000000..1ee199e30b64 --- /dev/null +++ b/test/generator/binding-textarea/main.html @@ -0,0 +1,2 @@ + +

{{value}}