mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-21 02:50:11 +08:00
fix(input-number): fix increase/decrease button not work (#1259)
* fix(input-number): fix increase/decrease button not work - fix increase/decrease not work when modelValue not in [min, max] * test(input-number): add a test case which check increase/decrease button
This commit is contained in:
parent
070e434994
commit
6530cdbeba
@ -242,4 +242,59 @@ describe('InputNumber.vue', () => {
|
||||
await nextTick()
|
||||
expect(wrapper.vm.num).toBe(1)
|
||||
})
|
||||
|
||||
test('check increase and decrease button when modelValue not in [min, max]', async () => {
|
||||
const wrapper = _mount({
|
||||
template: `
|
||||
<el-input-number
|
||||
ref="inputNumber1"
|
||||
v-model="num1"
|
||||
:min="1"
|
||||
:max="10"
|
||||
/>
|
||||
<el-input-number
|
||||
ref="inputNumber2"
|
||||
v-model="num2"
|
||||
:min="1"
|
||||
:max="10"
|
||||
/>`,
|
||||
setup() {
|
||||
const num1 = ref(-5)
|
||||
const num2 = ref(15)
|
||||
const inputNumber1 = ref(null)
|
||||
const inputNumber2 = ref(null)
|
||||
return {
|
||||
num1,
|
||||
num2,
|
||||
inputNumber1,
|
||||
inputNumber2,
|
||||
}
|
||||
},
|
||||
})
|
||||
const elInputNumber1 = wrapper.vm.inputNumber1
|
||||
const elInputNumber2 = wrapper.vm.inputNumber2
|
||||
expect(wrapper.vm.num1).toBe(1)
|
||||
expect(wrapper.vm.num2).toBe(10)
|
||||
|
||||
elInputNumber1.decrease()
|
||||
await nextTick()
|
||||
expect(wrapper.vm.num1).toBe(1)
|
||||
elInputNumber1.increase()
|
||||
await nextTick()
|
||||
expect(wrapper.vm.num1).toBe(2)
|
||||
elInputNumber1.increase()
|
||||
await nextTick()
|
||||
expect(wrapper.vm.num1).toBe(3)
|
||||
|
||||
|
||||
elInputNumber2.increase()
|
||||
await nextTick()
|
||||
expect(wrapper.vm.num2).toBe(10)
|
||||
elInputNumber2.decrease()
|
||||
await nextTick()
|
||||
expect(wrapper.vm.num2).toBe(9)
|
||||
elInputNumber2.decrease()
|
||||
await nextTick()
|
||||
expect(wrapper.vm.num2).toBe(8)
|
||||
})
|
||||
})
|
||||
|
@ -269,8 +269,14 @@ export default defineComponent({
|
||||
newVal = toPrecision(newVal, props.precision)
|
||||
}
|
||||
}
|
||||
if (newVal !== undefined && newVal >= props.max) newVal = props.max
|
||||
if (newVal !== undefined && newVal <= props.min) newVal = props.min
|
||||
if (newVal !== undefined && newVal >= props.max) {
|
||||
newVal = props.max
|
||||
emit('update:modelValue', newVal)
|
||||
}
|
||||
if (newVal !== undefined && newVal <= props.min) {
|
||||
newVal = props.min
|
||||
emit('update:modelValue', newVal)
|
||||
}
|
||||
data.currentValue = newVal
|
||||
data.userInput = null
|
||||
},
|
||||
@ -284,7 +290,7 @@ export default defineComponent({
|
||||
innerInput.setAttribute('aria-valuenow', data.currentValue)
|
||||
innerInput.setAttribute('aria-disabled', inputNumberDisabled.value)
|
||||
if (toRawType(props.modelValue) !== 'Number' && props.modelValue !== undefined) {
|
||||
setCurrentValue(undefined)
|
||||
emit('update:modelValue', undefined)
|
||||
}
|
||||
})
|
||||
onUpdated(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user