Skip to content

Commit 0cefacb

Browse files
feat(ui): add support for default values for numberinputs
1 parent baa5f75 commit 0cefacb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

invokeai/frontend/web/src/common/components/InvNumberInput/InvNumberInput.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const InvNumberInput = memo(
2424
fineStep: _fineStep,
2525
onChange: _onChange,
2626
numberInputFieldProps,
27+
defaultValue,
2728
...rest
2829
} = props;
2930

@@ -69,7 +70,7 @@ export const InvNumberInput = memo(
6970
(e) => {
7071
if (!e.target.value) {
7172
// If the input is empty, we set it to the minimum value
72-
onChange(String(min), min);
73+
onChange(String(defaultValue ?? min), Number(defaultValue) ?? min);
7374
} else {
7475
// Otherwise, we round the value to the nearest multiple if integer, else 3 decimals
7576
const roundedValue = isInteger
@@ -83,6 +84,7 @@ export const InvNumberInput = memo(
8384
[
8485
_fineStep,
8586
_step,
87+
defaultValue,
8688
isInteger,
8789
max,
8890
min,
@@ -107,10 +109,11 @@ export const InvNumberInput = memo(
107109
return (
108110
<ChakraNumberInput
109111
ref={ref}
112+
value={valueAsString}
113+
defaultValue={defaultValue}
110114
min={min}
111115
max={max}
112116
step={step}
113-
value={valueAsString}
114117
onChange={onChange}
115118
clampValueOnBlur={false}
116119
isValidCharacter={isValidCharacter}

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/inputs/NumberFieldInputComponent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const NumberFieldInputComponent = (
6161

6262
return (
6363
<InvNumberInput
64+
defaultValue={fieldTemplate.default}
6465
onChange={handleValueChanged}
6566
value={field.value}
6667
min={min ?? -NUMPY_RAND_MAX}

0 commit comments

Comments
 (0)