Skip to content

Commit c5468f2

Browse files
committed
fix: input-number parse error #3249
1 parent ef51ede commit c5468f2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

components/vc-input-number/src/index.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export default defineComponent({
148148

149149
// Trigger onChange when max or min change
150150
// https://github.com/ant-design/ant-design/issues/11574
151-
const nextValue = 'value' in props ? value : this.sValue;
151+
const nextValue = 'value' in props ? value : this.$data.sValue;
152152
// ref: null < 20 === true
153153
// https://github.com/ant-design/ant-design/issues/14277
154154
if (
@@ -187,14 +187,14 @@ export default defineComponent({
187187
// This caused that if an input didn't init with the selection,
188188
// set will cause cursor not correct when first focus.
189189
// Safari will focus input if set selection. We need skip this.
190-
if (this.cursorStart !== undefined && this.focused) {
190+
if (this.cursorStart !== undefined && this.$data.focused) {
191191
// In most cases, the string after cursor is stable.
192192
// We can move the cursor before it
193193

194194
if (
195195
// If not match full str, try to match part of str
196196
!this.partRestoreByAfter(this.cursorAfter) &&
197-
this.sValue !== this.value
197+
this.$data.sValue !== this.value
198198
) {
199199
// If not match any of then, let's just keep the position
200200
// TODO: Logic should not reach here, need check if happens
@@ -233,7 +233,7 @@ export default defineComponent({
233233
if (!this.pressingUpOrDown) {
234234
return;
235235
}
236-
if (this.focusOnUpDown && this.focused) {
236+
if (this.focusOnUpDown && this.$data.focused) {
237237
if (document.activeElement !== inputElem) {
238238
this.focus();
239239
}
@@ -266,7 +266,7 @@ export default defineComponent({
266266
this.__emit('keyup', e, ...args);
267267
},
268268
onChange(e) {
269-
if (this.focused) {
269+
if (this.$data.focused) {
270270
this.inputting = true;
271271
}
272272
this.rawInput = this.parser(this.getValueFromEvent(e));
@@ -286,7 +286,7 @@ export default defineComponent({
286286
this.setState({
287287
focused: false,
288288
});
289-
const value = this.getCurrentValidValue(this.inputValue);
289+
const value = this.getCurrentValidValue(this.$data.inputValue);
290290
const newValue = this.setValue(value);
291291
if (this.$attrs.onBlur) {
292292
const originValue = this.inputRef.value;
@@ -303,7 +303,7 @@ export default defineComponent({
303303
} else if (!this.isNotCompleteNumber(parseFloat(val, 10))) {
304304
val = this.getValidValue(val);
305305
} else {
306-
val = this.sValue;
306+
val = this.$data.sValue;
307307
}
308308
return this.toNumber(val);
309309
},
@@ -363,7 +363,7 @@ export default defineComponent({
363363
// always set input value same as value
364364
this.setState(
365365
{
366-
inputValue: this.toPrecisionAsStep(this.sValue),
366+
inputValue: this.toPrecisionAsStep(this.$data.sValue),
367367
},
368368
callback,
369369
);
@@ -538,7 +538,7 @@ export default defineComponent({
538538
},
539539
toNumber(num) {
540540
const { precision, autofocus } = this.$props;
541-
const { focused = autofocus } = this;
541+
const { focused = autofocus } = this.$data;
542542
// num.length > 16 => This is to prevent input of large numbers
543543
const numberIsTooLarge = num && num.length > 16 && focused;
544544
if (this.isNotCompleteNumber(num) || numberIsTooLarge) {
@@ -579,7 +579,7 @@ export default defineComponent({
579579
return;
580580
}
581581
const { max, min } = this;
582-
const value = this.getCurrentValidValue(this.inputValue) || 0;
582+
const value = this.getCurrentValidValue(this.$data.inputValue) || 0;
583583
if (this.isNotCompleteNumber(value)) {
584584
return;
585585
}
@@ -648,11 +648,11 @@ export default defineComponent({
648648
[className]: className,
649649
[prefixCls]: true,
650650
[`${prefixCls}-disabled`]: disabled,
651-
[`${prefixCls}-focused`]: this.focused,
651+
[`${prefixCls}-focused`]: this.$data.focused,
652652
});
653653
let upDisabledClass = '';
654654
let downDisabledClass = '';
655-
const { sValue } = this;
655+
const { sValue } = this.$data;
656656
if (sValue || sValue === 0) {
657657
if (!isNaN(sValue)) {
658658
const val = Number(sValue);

0 commit comments

Comments
 (0)