Skip to content

Commit

Permalink
fix: ios 16 input type=digit decimal point question/154584
Browse files Browse the repository at this point in the history
  • Loading branch information
StrivingRabbit committed Oct 10, 2022
1 parent 81acc66 commit dbb4e1a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/core/view/components/input/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,33 @@ export default {
$event.target.addEventListener('blur', clearCachedValue)
return
}
// 处理小数点
if (this.cachedValue) {
if (this.cachedValue.indexOf('.') !== -1) {
// 删除到小数点时
if (
$event.data !== '.' &&
$event.inputType === 'deleteContentBackward'
) {
const dotIndex = this.cachedValue.indexOf('.')
this.cachedValue =
$event.target.value =
this.valueSync =
this.cachedValue.slice(0, dotIndex)
return this.$triggerInput($event, {
value: this.valueSync
}, force)
}
} else if ($event.data === '.') {
// 输入小数点时
this.cachedValue += '.'
this.__clearCachedValue = () => {
this.cachedValue = $event.target.value = this.cachedValue.slice(0, -1)
}
$event.target.addEventListener('blur', this.__clearCachedValue)
return false
}
}
this.cachedValue = this.valueSync = $event.target.value = this.cachedValue === '-' ? '' : this.cachedValue
// 输入非法字符不触发 input 事件
return
Expand Down

0 comments on commit dbb4e1a

Please sign in to comment.