From a809075be94f7639187df9970dcbac6f706ba40c Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 2 Apr 2019 22:10:48 +0200 Subject: [PATCH] feat(model): add .eager modifier Ignore `composing` value on the input and eagerly modify the value while the user is still composing a value. #9299 #9777 --- .../web/compiler/directives/model.js | 4 ++-- .../features/directives/model-text.spec.js | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/platforms/web/compiler/directives/model.js b/src/platforms/web/compiler/directives/model.js index a42096109a..ba822dcbd6 100644 --- a/src/platforms/web/compiler/directives/model.js +++ b/src/platforms/web/compiler/directives/model.js @@ -146,8 +146,8 @@ function genDefaultModel ( } } - const { lazy, number, trim } = modifiers || {} - const needCompositionGuard = !lazy && type !== 'range' + const { lazy, number, trim, eager } = modifiers || {} + const needCompositionGuard = !lazy && type !== 'range' && !eager const event = lazy ? 'change' : type === 'range' diff --git a/test/unit/features/directives/model-text.spec.js b/test/unit/features/directives/model-text.spec.js index 7cf5167461..ff37aec63b 100644 --- a/test/unit/features/directives/model-text.spec.js +++ b/test/unit/features/directives/model-text.spec.js @@ -218,6 +218,26 @@ describe('Directive v-model text', () => { done() }) + it('.eager modifier', () => { + const vm = new Vue({ + data: { + test: 'foo' + }, + template: '' + }).$mount() + const input = vm.$el + triggerEvent(input, 'compositionstart') + input.value = 'baz' + // input before composition unlock should call set + triggerEvent(input, 'input') + expect(vm.test).toBe('baz') + // after composition unlock it should work + triggerEvent(input, 'compositionend') + input.value = 'bar' + triggerEvent(input, 'input') + expect(vm.test).toBe('bar') + }) + it('warn invalid tag', () => { new Vue({ data: {