Merge pull request #1513 from ensarkurrt/canary

fix(ui): Prevent Zero from Persisting in Numeric Input
This commit is contained in:
Mauricio Siu 2025-03-16 18:56:59 -06:00 committed by GitHub
commit 5965b73342
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,7 +39,7 @@ const NumberInput = React.forwardRef<HTMLInputElement, InputProps>(
className={cn("text-left", className)}
ref={ref}
{...props}
value={props.value === undefined ? undefined : String(props.value)}
value={props.value === undefined || props.value === "" ? "" : String(props.value)}
onChange={(e) => {
const value = e.target.value;
if (value === "") {
@ -60,6 +60,21 @@ const NumberInput = React.forwardRef<HTMLInputElement, InputProps>(
}
}
}}
onBlur={(e) => {
// If input is empty, make 0 when focus is lost
if (e.target.value === "") {
const syntheticEvent = {
...e,
target: {
...e.target,
value: "0",
},
};
props.onChange?.(
syntheticEvent as unknown as React.ChangeEvent<HTMLInputElement>,
);
}
}}
/>
);
},