Skip to content

Commit

Permalink
Merge pull request #567 from zc422/fix-input-number-0206
Browse files Browse the repository at this point in the history
bugfix(input): 修复数字输入框在空值的时候点击上下按键不显示最大/小值的问题
  • Loading branch information
ielgnaw authored Jul 16, 2024
2 parents d08867a + 1fd9c7b commit 162c94a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/input/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,15 @@ export default {
}
},
handleNumberDelete (event) {
let isRawValEmpty = false
if (this.curValue === '') {
isRawValEmpty = true
this.curValue = this.initialControlValue === undefined ? this.max : Math.min(this.initialControlValue, this.max)
}
const curNumberValue = Number(this.curValue)
if (curNumberValue - 1 >= this.min) {
const curLenAfterDot = (String(curNumberValue) || '').split('.')[1] || ''
let newVal = curNumberValue - 1
let newVal = isRawValEmpty ? curNumberValue : curNumberValue - 1
if (typeof this.precision !== 'undefined') {
newVal = this.handleToFixed(newVal, Math.min(16, Math.max(curLenAfterDot.length, this.precision)))
}
Expand All @@ -611,13 +613,15 @@ export default {
}
},
handleNumberAdd (event) {
let isRawValEmpty = false
if (this.curValue === '') {
isRawValEmpty = true
this.curValue = this.initialControlValue === undefined ? this.min : Math.max(this.initialControlValue, this.min)
}
const curNumberValue = Number(this.curValue)
if (curNumberValue <= this.max - 1) {
const curLenAfterDot = (String(curNumberValue) || '').split('.')[1] || ''
let newVal = curNumberValue + 1
let newVal = isRawValEmpty ? curNumberValue : curNumberValue + 1
if (typeof this.precision !== 'undefined') {
newVal = this.handleToFixed(newVal, Math.min(16, Math.max(curLenAfterDot.length, this.precision)))
}
Expand Down

0 comments on commit 162c94a

Please sign in to comment.