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

View File

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