feat(ui): add support for default values for numberinputs

This commit is contained in:
psychedelicious 2024-01-03 07:46:43 +11:00
parent baa5f75976
commit 0cefacb3a2
2 changed files with 6 additions and 2 deletions

View File

@ -24,6 +24,7 @@ export const InvNumberInput = memo(
fineStep: _fineStep, fineStep: _fineStep,
onChange: _onChange, onChange: _onChange,
numberInputFieldProps, numberInputFieldProps,
defaultValue,
...rest ...rest
} = props; } = props;
@ -69,7 +70,7 @@ export const InvNumberInput = memo(
(e) => { (e) => {
if (!e.target.value) { if (!e.target.value) {
// If the input is empty, we set it to the minimum value // If the input is empty, we set it to the minimum value
onChange(String(min), min); onChange(String(defaultValue ?? min), Number(defaultValue) ?? min);
} else { } else {
// Otherwise, we round the value to the nearest multiple if integer, else 3 decimals // Otherwise, we round the value to the nearest multiple if integer, else 3 decimals
const roundedValue = isInteger const roundedValue = isInteger
@ -83,6 +84,7 @@ export const InvNumberInput = memo(
[ [
_fineStep, _fineStep,
_step, _step,
defaultValue,
isInteger, isInteger,
max, max,
min, min,
@ -107,10 +109,11 @@ export const InvNumberInput = memo(
return ( return (
<ChakraNumberInput <ChakraNumberInput
ref={ref} ref={ref}
value={valueAsString}
defaultValue={defaultValue}
min={min} min={min}
max={max} max={max}
step={step} step={step}
value={valueAsString}
onChange={onChange} onChange={onChange}
clampValueOnBlur={false} clampValueOnBlur={false}
isValidCharacter={isValidCharacter} isValidCharacter={isValidCharacter}

View File

@ -61,6 +61,7 @@ const NumberFieldInputComponent = (
return ( return (
<InvNumberInput <InvNumberInput
defaultValue={fieldTemplate.default}
onChange={handleValueChanged} onChange={handleValueChanged}
value={field.value} value={field.value}
min={min ?? -NUMPY_RAND_MAX} min={min ?? -NUMPY_RAND_MAX}