Skip to content

Commit

Permalink
fix(VTextField): on emit change when initial value != lazy
Browse files Browse the repository at this point in the history
fixes #5070
  • Loading branch information
johnleider committed Jul 14, 2021
1 parent 9d539d6 commit 6aaf52b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/vuetify/src/components/VTextField/VTextField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,13 @@ export default baseMixins.extend<options>().extend({
this.badInput = target.validity && target.validity.badInput
},
onKeyDown (e: KeyboardEvent) {
if (e.keyCode === keyCodes.enter) this.$emit('change', this.internalValue)
if (
e.keyCode === keyCodes.enter &&
this.lazyValue !== this.initialValue
) {
this.initialValue = this.lazyValue
this.$emit('change', this.initialValue)
}

this.$emit('keydown', e)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,19 +628,26 @@ describe('VTextField.ts', () => { // eslint-disable-line max-statements
expect(input.element.id).toBe('foo')
})

it('should fire change event when pressing enter', () => {
it('should fire change event when pressing enter and value has changed', () => {
const wrapper = mountFunction()
const input = wrapper.find('input')
const change = jest.fn()
const el = input.element as HTMLInputElement

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

input.trigger('focus')
input.element.value = 'foo'
el.value = 'foo'
input.trigger('input')
input.trigger('keydown.enter')
input.trigger('keydown.enter')

expect(change).toHaveBeenCalledTimes(1)

el.value = 'foobar'
input.trigger('input')
input.trigger('keydown.enter')

expect(change).toHaveBeenCalledTimes(2)
})

Expand Down

0 comments on commit 6aaf52b

Please sign in to comment.