Skip to content

Commit a1ec276

Browse files
committed
Fix some important issue
1 parent 5c1b11a commit a1ec276

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

docs/.vuepress/components/PlayGround.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
<pre
4747
class="m-0"
4848
style="margin: 0"
49-
>{{ config }}</pre
5049
>
50+
{{ config }}
51+
</pre>
5152
</Dialog>
5253
</div>
5354
</div>
@@ -149,6 +150,7 @@ export default {
149150
suffix: '',
150151
precision: 2,
151152
nullValue: '',
153+
max: 1234.567,
152154
masked: false
153155
}
154156
}

src/core.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ export function updateValue(el: CustomInputElement, vnode: VNode | null, { emit
105105
if (clean) {
106106
if (Number(max) === max && Number(unmasked) > max) {
107107
masked = number.format(max)
108-
unmasked = number.unformat(max)
108+
unmasked = max.toString()
109109
} else if (Number(min) === min && Number(unmasked) < min) {
110110
masked = number.format(min)
111-
unmasked = number.unformat(min)
111+
unmasked = min.toString()
112112
}
113+
el.oldValue = masked
113114
}
114115

115-
el.oldValue = masked
116116
el.unmasked = unmasked
117117

118118
// safari makes the cursor jump to the end if el.value gets assign even if to the same value
@@ -195,7 +195,7 @@ export function keydownHandler(event: KeyboardEvent, el: CustomInputElement) {
195195
const { key } = event
196196
const regExp = new RegExp(`${prefix}|${suffix}`, 'g')
197197
const newValue = el.value.replace(regExp, '')
198-
const canNegativeInput = min === undefined || Number(min) < 0 || Number(min) !== min
198+
const canBeNegative = min === undefined || Number(min) < 0 || Number(min) !== min
199199
if (key === decimal) {
200200
if (newValue.includes(decimal)) {
201201
event.preventDefault()
@@ -204,7 +204,7 @@ export function keydownHandler(event: KeyboardEvent, el: CustomInputElement) {
204204
// trigger input event
205205
el.dispatchEvent(new Event('input'))
206206
}
207-
} else if (key === MINUS && !canNegativeInput) {
207+
} else if (key === MINUS && !canBeNegative) {
208208
event.preventDefault()
209209
} else if (key === 'Backspace') {
210210
// check current cursor position is after separator when backspace key down

src/number-format.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export default class NumberFormat {
3333
input: Input
3434
number: Input
3535
isClean: boolean
36-
isCustomDecimal: boolean
3736
preSurRegExp: RegExp
3837
numberRegExp: RegExp
3938
cleanRegExp: RegExp
@@ -51,7 +50,6 @@ export default class NumberFormat {
5150
this.numberRegExp = new RegExp(`[^0-9\\${decimal}]+`, 'gi')
5251
this.cleanRegExp = new RegExp('[^0-9]+', 'gi')
5352
this.negativeRegExp = new RegExp('[^0-9\\-]+', 'gi')
54-
this.isCustomDecimal = decimal !== '.'
5553
}
5654

5755
isNull() {
@@ -97,13 +95,11 @@ export default class NumberFormat {
9795

9896
numbers() {
9997
const { reverseFill, decimal } = this.options
100-
const hasDeciaml = this.input.toString().indexOf(decimal) >= 0
101-
const input = !hasDeciaml && this.isCustomDecimal ? this.input + decimal : this.input
10298
if (reverseFill) {
10399
this.number = this.toFixed().replace('.', decimal)
104100
} else if (typeof this.input === 'number') {
105101
this.number = this.parts(this.input.toString().replace('-', ''), '.').join(decimal)
106-
} else if (!isNaN(this.toNumber(input))) {
102+
} else if (!isNaN(this.toNumber(this.input))) {
107103
this.number = this.parts(this.input.replace('-', ''), '.').join(decimal)
108104
} else {
109105
this.number = this.parts(this.numberOnly()).join(decimal)

0 commit comments

Comments
 (0)