Skip to content

Commit a809075

Browse files
committed
feat(model): add .eager modifier
Ignore `composing` value on the input and eagerly modify the value while the user is still composing a value. vuejs#9299 vuejs#9777
1 parent 6be3bf4 commit a809075

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/platforms/web/compiler/directives/model.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ function genDefaultModel (
146146
}
147147
}
148148

149-
const { lazy, number, trim } = modifiers || {}
150-
const needCompositionGuard = !lazy && type !== 'range'
149+
const { lazy, number, trim, eager } = modifiers || {}
150+
const needCompositionGuard = !lazy && type !== 'range' && !eager
151151
const event = lazy
152152
? 'change'
153153
: type === 'range'

test/unit/features/directives/model-text.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,26 @@ describe('Directive v-model text', () => {
218218
done()
219219
})
220220

221+
it('.eager modifier', () => {
222+
const vm = new Vue({
223+
data: {
224+
test: 'foo'
225+
},
226+
template: '<input v-model.eager="test">'
227+
}).$mount()
228+
const input = vm.$el
229+
triggerEvent(input, 'compositionstart')
230+
input.value = 'baz'
231+
// input before composition unlock should call set
232+
triggerEvent(input, 'input')
233+
expect(vm.test).toBe('baz')
234+
// after composition unlock it should work
235+
triggerEvent(input, 'compositionend')
236+
input.value = 'bar'
237+
triggerEvent(input, 'input')
238+
expect(vm.test).toBe('bar')
239+
})
240+
221241
it('warn invalid tag', () => {
222242
new Vue({
223243
data: {

0 commit comments

Comments
 (0)