Skip to content

Commit

Permalink
feat(input-number): allowInputOverLimit (#2037)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaishi authored Nov 21, 2022
1 parent 47119d8 commit 0f0c2dc
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/input-number/useInputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,40 @@ export default function useInputNumber(props: TdInputNumberProps) {
{ immediate: true },
);

const handleStepValue = (op: 'add' | 'reduce') =>
getStepValue({
const handleStepValue = (op: 'add' | 'reduce') => {
const newValue = getStepValue({
op,
step: props.step,
max: props.max,
min: props.min,
lastValue: tValue.value,
largeNumber: props.largeNumber,
});
const { largeNumber, max, min } = props;
const overLimit = getMaxOrMinValidateResult({
value: newValue,
largeNumber,
max,
min,
});
return {
overLimit,
newValue,
};
};

const handleReduce = (e: KeyboardEvent | MouseEvent) => {
if (disabledReduce.value || props.readonly) return;
const newValue = handleStepValue('reduce');
setTValue(newValue, { type: 'reduce', e });
const r = handleStepValue('reduce');
if (r.overLimit && !props.allowInputOverLimit) return;
setTValue(r.newValue, { type: 'reduce', e });
};

const handleAdd = (e: KeyboardEvent | MouseEvent) => {
if (disabledAdd.value || props.readonly) return;
const newValue = handleStepValue('add');
setTValue(newValue, { type: 'add', e });
const r = handleStepValue('add');
if (r.overLimit && !props.allowInputOverLimit) return;
setTValue(r.newValue, { type: 'add', e });
};

const onInnerInputChange = (val: string, { e }: { e: InputEvent }) => {
Expand Down

0 comments on commit 0f0c2dc

Please sign in to comment.