Skip to content

Commit

Permalink
fix(VSlider): set value to min if it's less than min (#6604) (#6605)
Browse files Browse the repository at this point in the history
* fix(VSlider): set value to min if it's less than min (#6604)

fixes #6604

* test(VSlider): Check roundValue is bounded by min and max

The roundValue function gets used by inputWidth to determine placement of the thumb and various
other elements. If the initial value is less than min, inputWidth will return a negative number due
to the roundValue not being bounded by min and max. This test will check the boundaries.

test for fix #6604
  • Loading branch information
hrayr-artunyan authored and johnleider committed Mar 3, 2019
1 parent 2146ca8 commit 91eb0db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vuetify/src/components/VSlider/VSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export default VInput.extend({

const newValue = Math.round((value - offset) / this.stepNumeric) * this.stepNumeric + offset

return parseFloat(Math.min(newValue, this.max).toFixed(decimals))
return parseFloat(Math.max(Math.min(newValue, this.max), this.min).toFixed(decimals))
},
setInternalValue (value) {
this.internalValue = value
Expand Down
12 changes: 12 additions & 0 deletions packages/vuetify/test/unit/components/VSlider/VSlider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,18 @@ test('VSlider.vue', ({ mount }) => {
expect(wrapper.vm.roundValue(5.667)).toBe(5)
})

it('should return a rounded value bounded by min and max', () => {
const wrapper = mount(VSlider, {
propsData: {
min: 5,
max: 10
}
})

expect(wrapper.vm.roundValue(1)).toBe(5)
expect(wrapper.vm.roundValue(15)).toBe(10)
})

it('should not update if value matches lazy value', () => {
const validate = jest.fn()
const wrapper = mount(VSlider, {
Expand Down

0 comments on commit 91eb0db

Please sign in to comment.