Skip to content

Commit 30bbd4c

Browse files
committed
fix: inputnumber can not input min value, close #5083
1 parent 41f4187 commit 30bbd4c

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

components/input-number/src/InputNumber.tsx

+6-26
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
22
import type { DecimalClass, ValueType } from './utils/MiniDecimal';
3-
import getMiniDecimal, {
4-
roundDownUnsignedDecimal,
5-
roundUpUnsignedDecimal,
6-
toFixed,
7-
} from './utils/MiniDecimal';
3+
import getMiniDecimal, { toFixed } from './utils/MiniDecimal';
84
import StepHandler from './StepHandler';
9-
import { getNumberPrecision, num2str, trimNumber, validateNumber } from './utils/numberUtil';
5+
import { getNumberPrecision, num2str, validateNumber } from './utils/numberUtil';
106
import useCursor from './hooks/useCursor';
117
import useFrame from './hooks/useFrame';
128
import type { HTMLAttributes, PropType } from 'vue';
@@ -33,25 +29,9 @@ const getDecimalValue = (stringMode: boolean, decimalValue: DecimalClass) => {
3329

3430
return decimalValue.toNumber();
3531
};
36-
37-
const getDecimalIfValidate = (value: ValueType, precision: number | undefined, isMax?: boolean) => {
32+
const getDecimalIfValidate = (value: ValueType) => {
3833
const decimal = getMiniDecimal(value);
39-
if (decimal.isInvalidate()) {
40-
return null;
41-
}
42-
43-
if (precision === undefined) {
44-
return decimal;
45-
}
46-
47-
const { negative, integerStr, decimalStr, negativeStr } = trimNumber(decimal.toString());
48-
const unSignedNumberStr = integerStr + '.' + decimalStr;
49-
50-
if ((isMax && !negative) || (!isMax && negative)) {
51-
return getMiniDecimal(negativeStr + roundDownUnsignedDecimal(unSignedNumberStr, precision));
52-
} else {
53-
return getMiniDecimal(negativeStr + roundUpUnsignedDecimal(unSignedNumberStr, precision));
54-
}
34+
return decimal.isInvalidate() ? null : decimal;
5535
};
5636

5737
export const inputNumberProps = {
@@ -210,8 +190,8 @@ export default defineComponent({
210190
}
211191

212192
// >>> Max & Min limit
213-
const maxDecimal = computed(() => getDecimalIfValidate(props.max, props.precision, true));
214-
const minDecimal = computed(() => getDecimalIfValidate(props.min, props.precision, false));
193+
const maxDecimal = computed(() => getDecimalIfValidate(props.max));
194+
const minDecimal = computed(() => getDecimalIfValidate(props.min));
215195

216196
const upDisabled = computed(() => {
217197
if (!maxDecimal.value || !decimalValue.value || decimalValue.value.isInvalidate()) {

0 commit comments

Comments
 (0)