mirror of
https://github.com/andwati/dokploy.git
synced 2026-12-06 01:28:46 +00:00
fix: fix number convert when string empty
This commit is contained in:
@@ -31,4 +31,37 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
);
|
||||
Input.displayName = "Input";
|
||||
|
||||
export { Input };
|
||||
const NumberInput = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className, errorMessage, ...props }, ref) => {
|
||||
return (
|
||||
<Input
|
||||
type="text"
|
||||
className={cn("text-left", className)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
if (value === "") {
|
||||
props.onChange?.(e);
|
||||
} else {
|
||||
const number = Number.parseInt(value, 10);
|
||||
if (!Number.isNaN(number)) {
|
||||
const syntheticEvent = {
|
||||
...e,
|
||||
target: {
|
||||
...e.target,
|
||||
value: number.toString(),
|
||||
},
|
||||
};
|
||||
props.onChange?.(syntheticEvent as React.ChangeEvent<HTMLInputElement>);
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
NumberInput.displayName = "NumberInput";
|
||||
|
||||
|
||||
export { Input, NumberInput };
|
||||
|
||||
Reference in New Issue
Block a user