mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add support for default values for numberinputs
This commit is contained in:
parent
baa5f75976
commit
0cefacb3a2
@ -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}
|
||||||
|
@ -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}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user