Skip to content

Commit

Permalink
fix(Stepper): fix the problem of not supporting direct input
Browse files Browse the repository at this point in the history
  • Loading branch information
anlyyao committed Oct 17, 2024
1 parent 61c6afd commit a168846
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/stepper/Stepper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FormEvent, forwardRef, memo } from 'react';
import React, { forwardRef, memo } from 'react';
import classNames from 'classnames';
import { AddIcon, RemoveIcon } from 'tdesign-icons-react';
import { usePrefixClass } from '../hooks/useClass';
Expand Down Expand Up @@ -89,22 +89,22 @@ const Stepper = forwardRef<HTMLDivElement, StepperProps>((originProps, ref) => {
updateValue(formatValue(add(Number(currentValue), -step)));
};

const handleInput = (e: FormEvent<HTMLInputElement>) => {
const value = formatNumber((e.target as HTMLInputElement).value, !integer);
setCurrentValue(value);
};

const handleChange = () => {
const formattedValue = formatValue(Number(currentValue));
updateValue(formattedValue);
const handleChange = (e: React.FocusEvent<HTMLInputElement, Element>) => {
const { value } = e.currentTarget;
if (isNaN(Number(value))) return;
setCurrentValue(formatNumber(value, !integer));
};

const handleFocus = () => {
onFocus(Number(currentValue));
onFocus?.(Number(currentValue));
};

const handleBlur = () => {
onBlur(Number(currentValue));
const handleBlur = (e: React.FocusEvent<HTMLInputElement, Element>) => {
const { value } = e.currentTarget;
if (isNaN(Number(value))) return;
const formattedValue = formatValue(Number(value));
setCurrentValue(formattedValue);
onBlur?.(formattedValue);
};

return (
Expand Down Expand Up @@ -139,7 +139,6 @@ const Stepper = forwardRef<HTMLDivElement, StepperProps>((originProps, ref) => {
readOnly={disableInput}
onFocus={handleFocus}
onBlur={handleBlur}
onInput={handleInput}
onChange={handleChange}
/>
<div
Expand Down

0 comments on commit a168846

Please sign in to comment.