Browse Source

fix: always install composition event listeners

Previously the installation was skipped on Android because
it was not needed for Chinese IME - however some IMEs such
as Japanese exhibits the same behavior as on other browers.

So it is safer to always enable the check. Closes #7367
dev
Evan You 7 years ago
parent
commit
f7ca21eab1
  1. 8
      src/platforms/web/runtime/directives/model.js
  2. 40
      test/unit/features/directives/model-text.spec.js

8
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

40
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: '<input v-model="test">'
}).$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: '<input v-model="test">'
}).$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({

Loading…
Cancel
Save