Skip to content

Commit

Permalink
fix: inputnumber can not input min value, close #5083
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Dec 27, 2021
1 parent 41f4187 commit 30bbd4c
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions components/input-number/src/InputNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// base rc-input-number@7.3.4
import type { DecimalClass, ValueType } from './utils/MiniDecimal';
import getMiniDecimal, {
roundDownUnsignedDecimal,
roundUpUnsignedDecimal,
toFixed,
} from './utils/MiniDecimal';
import getMiniDecimal, { toFixed } from './utils/MiniDecimal';
import StepHandler from './StepHandler';
import { getNumberPrecision, num2str, trimNumber, validateNumber } from './utils/numberUtil';
import { getNumberPrecision, num2str, validateNumber } from './utils/numberUtil';
import useCursor from './hooks/useCursor';
import useFrame from './hooks/useFrame';
import type { HTMLAttributes, PropType } from 'vue';
Expand All @@ -33,25 +29,9 @@ const getDecimalValue = (stringMode: boolean, decimalValue: DecimalClass) => {

return decimalValue.toNumber();
};

const getDecimalIfValidate = (value: ValueType, precision: number | undefined, isMax?: boolean) => {
const getDecimalIfValidate = (value: ValueType) => {
const decimal = getMiniDecimal(value);
if (decimal.isInvalidate()) {
return null;
}

if (precision === undefined) {
return decimal;
}

const { negative, integerStr, decimalStr, negativeStr } = trimNumber(decimal.toString());
const unSignedNumberStr = integerStr + '.' + decimalStr;

if ((isMax && !negative) || (!isMax && negative)) {
return getMiniDecimal(negativeStr + roundDownUnsignedDecimal(unSignedNumberStr, precision));
} else {
return getMiniDecimal(negativeStr + roundUpUnsignedDecimal(unSignedNumberStr, precision));
}
return decimal.isInvalidate() ? null : decimal;
};

export const inputNumberProps = {
Expand Down Expand Up @@ -210,8 +190,8 @@ export default defineComponent({
}

// >>> Max & Min limit
const maxDecimal = computed(() => getDecimalIfValidate(props.max, props.precision, true));
const minDecimal = computed(() => getDecimalIfValidate(props.min, props.precision, false));
const maxDecimal = computed(() => getDecimalIfValidate(props.max));
const minDecimal = computed(() => getDecimalIfValidate(props.min));

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

0 comments on commit 30bbd4c

Please sign in to comment.