Skip to content

Commit 5509a15

Browse files
erikras-gilfoyle-agenterikras-gilfoyle-agent
andauthored
fix: Support input prop override in Field component (#1066)
Fixes #1048 In v6.x, users could pass an `input` prop to override or extend the field's input properties. This broke in v7.0.0 because the `input` prop wasn't being destructured and merged with `field.input`. Changes: - Destructure `input` prop from Field component props - Merge provided `input` with `field.input` (user props take precedence) - Add `input?: Partial<FieldInputProps>` to FieldProps interface - Apply merged input to all render paths (children function, string component, custom component) This restores v6.x behavior while maintaining v7.0.0 improvements. Example usage: ```tsx <Field name="email" component={MyInput} input={{ onChange: customOnChange, // Override onChange value: customValue, // Override value }} /> ``` Co-authored-by: erikras-gilfoyle-agent <gilfoyle@openclaw.local>
1 parent f25a24e commit 5509a15

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/Field.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function FieldComponent<
1919
format,
2020
formatOnBlur,
2121
initialValue,
22+
input,
2223
isEqual,
2324
multiple,
2425
name,
@@ -52,17 +53,22 @@ function FieldComponent<
5253
value,
5354
});
5455

56+
// Merge provided input prop with field.input
57+
const mergedField = input
58+
? { ...field, input: { ...field.input, ...input } }
59+
: field;
60+
5561
if (typeof children === "function") {
5662
return (
5763
children as (
5864
props: FieldRenderProps<FieldValue, T> & typeof rest,
5965
) => React.ReactNode
60-
)({ ...field, ...rest });
66+
)({ ...mergedField, ...rest });
6167
}
6268

6369
if (typeof component === "string") {
6470
// ignore meta, combine input with any other props
65-
const inputProps = { ...field.input };
71+
const inputProps = { ...mergedField.input };
6672

6773
// Ensure multiple select has array value
6874
if (
@@ -86,7 +92,7 @@ function FieldComponent<
8692
}
8793

8894
return renderComponent(
89-
{ children, component, ...rest, ...field },
95+
{ children, component, ...rest, ...mergedField },
9096
{},
9197
`Field(${name})`,
9298
);

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export interface FieldProps<
126126
Omit<RenderableProps<FieldRenderProps<FieldValue, T>>, "children"> {
127127
name: string;
128128
children?: RenderableProps<FieldRenderProps<FieldValue, T>>["children"];
129+
input?: Partial<FieldInputProps<FieldValue, T>>; // Allow overriding input props
129130
[key: string]: any; // Allow additional props for HTML elements
130131
}
131132

typescript/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export interface FieldProps<
125125
Omit<RenderableProps<FieldRenderProps<FieldValue, T>>, "children"> {
126126
name: string;
127127
children?: RenderableProps<FieldRenderProps<FieldValue, T>>["children"];
128+
input?: Partial<FieldInputProps<FieldValue, T>>;
128129
[key: string]: any;
129130
}
130131

0 commit comments

Comments
 (0)