mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
fix(NumberInput): min & max validation when entering value from keyboard
This commit is contained in:
parent
0c9b9927cc
commit
d407e6c7b7
1 changed files with 6 additions and 1 deletions
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue