Skip to content

Commit 6aaf52b

Browse files
committed
fix(VTextField): on emit change when initial value != lazy
fixes #5070
1 parent 9d539d6 commit 6aaf52b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Diff for: packages/vuetify/src/components/VTextField/VTextField.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,13 @@ export default baseMixins.extend<options>().extend({
474474
this.badInput = target.validity && target.validity.badInput
475475
},
476476
onKeyDown (e: KeyboardEvent) {
477-
if (e.keyCode === keyCodes.enter) this.$emit('change', this.internalValue)
477+
if (
478+
e.keyCode === keyCodes.enter &&
479+
this.lazyValue !== this.initialValue
480+
) {
481+
this.initialValue = this.lazyValue
482+
this.$emit('change', this.initialValue)
483+
}
478484

479485
this.$emit('keydown', e)
480486
},

Diff for: packages/vuetify/src/components/VTextField/__tests__/VTextField.spec.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -628,19 +628,26 @@ describe('VTextField.ts', () => { // eslint-disable-line max-statements
628628
expect(input.element.id).toBe('foo')
629629
})
630630

631-
it('should fire change event when pressing enter', () => {
631+
it('should fire change event when pressing enter and value has changed', () => {
632632
const wrapper = mountFunction()
633633
const input = wrapper.find('input')
634634
const change = jest.fn()
635+
const el = input.element as HTMLInputElement
635636

636637
wrapper.vm.$on('change', change)
637638

638639
input.trigger('focus')
639-
input.element.value = 'foo'
640+
el.value = 'foo'
640641
input.trigger('input')
641642
input.trigger('keydown.enter')
642643
input.trigger('keydown.enter')
643644

645+
expect(change).toHaveBeenCalledTimes(1)
646+
647+
el.value = 'foobar'
648+
input.trigger('input')
649+
input.trigger('keydown.enter')
650+
644651
expect(change).toHaveBeenCalledTimes(2)
645652
})
646653

0 commit comments

Comments
 (0)