Skip to content

Commit

Permalink
fix(VSlider): avoid unnecessary input event
Browse files Browse the repository at this point in the history
fixes #10018
  • Loading branch information
johnleider committed Jan 2, 2020
1 parent a5b9cbc commit 2f9b28f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/vuetify/src/components/VSlider/VSlider.ts
Expand Up @@ -95,7 +95,6 @@ export default mixins<options &
keyPressed: 0,
isFocused: false,
isActive: false,
lazyValue: 0,
noClick: false, // Prevent click event if dragging took place, hack for #7915
}),

Expand Down
24 changes: 22 additions & 2 deletions packages/vuetify/src/components/VSlider/__tests__/VSlider.spec.ts
Expand Up @@ -563,19 +563,20 @@ describe('VSlider.ts', () => {
expect(parseKeyDown).toHaveBeenCalled()
})

it('should set value to min value if given a NaN', () => {
it('should set value to min value if given a NaN value', () => {
const input = jest.fn()
const wrapper = mountFunction({
propsData: {
min: -20,
max: 20,
value: NaN,
},
listeners: {
input,
},
})

expect(input).toHaveBeenCalledWith(-20)
expect(wrapper.vm.internalValue).toBe(-20)
})

it('should correctly handle initial value of zero (#7320)', () => {
Expand Down Expand Up @@ -618,4 +619,23 @@ describe('VSlider.ts', () => {
expect(input).not.toHaveBeenCalledWith(-20)
expect(wrapper.html()).toMatchSnapshot()
})

// https://github.com/vuetifyjs/vuetify/issues/10018
it('should not fire event if value is provided and valid', async () => {
const input = jest.fn()
mountFunction({
propsData: { value: 10, min: -20 },
listeners: { input },
})

expect(input).not.toHaveBeenCalled()

// Should set to min value if invalid
mountFunction({
propsData: { value: NaN, min: -20 },
listeners: { input },
})

expect(input).toHaveBeenCalledWith(-20)
})
})

0 comments on commit 2f9b28f

Please sign in to comment.