diff --git a/src/platforms/web/runtime/directives/model.js b/src/platforms/web/runtime/directives/model.js index c3b669f3..cba8ded0 100644 --- a/src/platforms/web/runtime/directives/model.js +++ b/src/platforms/web/runtime/directives/model.js @@ -6,7 +6,7 @@ import { isTextInputType } from 'web/util/element' import { looseEqual, looseIndexOf } from 'shared/util' import { mergeVNodeHook } from 'core/vdom/helpers/index' -import { warn, isAndroid, isIE9, isIE, isEdge } from 'core/util/index' +import { warn, isIE9, isIE, isEdge } from 'core/util/index' /* istanbul ignore if */ if (isIE9) { @@ -34,15 +34,13 @@ const directive = { } else if (vnode.tag === 'textarea' || isTextInputType(el.type)) { el._vModifiers = binding.modifiers if (!binding.modifiers.lazy) { + el.addEventListener('compositionstart', onCompositionStart) + el.addEventListener('compositionend', onCompositionEnd) // Safari < 10.2 & UIWebView doesn't fire compositionend when // switching focus before confirming composition choice // this also fixes the issue where some browsers e.g. iOS Chrome // fires "change" instead of "input" on autocomplete. el.addEventListener('change', onCompositionEnd) - if (!isAndroid) { - el.addEventListener('compositionstart', onCompositionStart) - el.addEventListener('compositionend', onCompositionEnd) - } /* istanbul ignore if */ if (isIE9) { el.vmodel = true diff --git a/test/unit/features/directives/model-text.spec.js b/test/unit/features/directives/model-text.spec.js index 7aae24b6..77a9e3d8 100644 --- a/test/unit/features/directives/model-text.spec.js +++ b/test/unit/features/directives/model-text.spec.js @@ -183,27 +183,25 @@ describe('Directive v-model text', () => { }) } - if (!isAndroid) { - it('compositionevents', function (done) { - const vm = new Vue({ - data: { - test: 'foo' - }, - template: '' - }).$mount() - const input = vm.$el - triggerEvent(input, 'compositionstart') - input.value = 'baz' - // input before composition unlock should not call set - triggerEvent(input, 'input') - expect(vm.test).toBe('foo') - // after composition unlock it should work - triggerEvent(input, 'compositionend') - triggerEvent(input, 'input') - expect(vm.test).toBe('baz') - done() - }) - } + it('compositionevents', function (done) { + const vm = new Vue({ + data: { + test: 'foo' + }, + template: '' + }).$mount() + const input = vm.$el + triggerEvent(input, 'compositionstart') + input.value = 'baz' + // input before composition unlock should not call set + triggerEvent(input, 'input') + expect(vm.test).toBe('foo') + // after composition unlock it should work + triggerEvent(input, 'compositionend') + triggerEvent(input, 'input') + expect(vm.test).toBe('baz') + done() + }) it('warn invalid tag', () => { new Vue({