fix(NumberInput): min & max validation when entering value from keyboard

This commit is contained in:
Botzy 2025-02-10 15:12:43 +02:00
parent 0c9b9927cc
commit d407e6c7b7

View file

@ -67,7 +67,12 @@ const NumberInput = forwardRef<HTMLInputElement, Props>(({ defaultValue, ...prop
value={value}
{...props}
className={classnames(props.className, styles['value'], { 'disabled': props.disabled })}
onChange={(event: ChangeEvent<HTMLInputElement>) => setValue(parseInt(event.target.value))}
onChange={(event: ChangeEvent<HTMLInputElement>) => {
const newValue = parseInt(event.target.value);
if (props.min !== undefined && newValue < props.min) return props.min;
if (props.max !== undefined && newValue > props.max) return props.max;
setValue(newValue);
}}
onKeyDown={onKeyDown}
/>
</div>