From 82ed54bea7e9e3f1f33a21da4b153ff53e574fa5 Mon Sep 17 00:00:00 2001 From: Andrey Yamanov Date: Mon, 24 Nov 2025 17:38:05 +0100 Subject: [PATCH] fix: form attribute spread prevention --- .changeset/f5h6b0cx9ra.md | 5 +++++ .cursor/rules/changeset.mdc | 2 +- src/components/fields/TextInput/TextInput.tsx | 1 + src/components/form/Form/use-field/use-field-props.tsx | 5 ++++- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/f5h6b0cx9ra.md diff --git a/.changeset/f5h6b0cx9ra.md b/.changeset/f5h6b0cx9ra.md new file mode 100644 index 000000000..396ae51a3 --- /dev/null +++ b/.changeset/f5h6b0cx9ra.md @@ -0,0 +1,5 @@ +--- +"@cube-dev/ui-kit": patch +--- + +Fix form fields to prevent internal `form` prop from being spread to DOM elements diff --git a/.cursor/rules/changeset.mdc b/.cursor/rules/changeset.mdc index 86f817723..3c393b666 100644 --- a/.cursor/rules/changeset.mdc +++ b/.cursor/rules/changeset.mdc @@ -3,7 +3,7 @@ description: When user asked to add a changeset alwaysApply: false --- -Place the changeset in the `/.changeset` folder. +Add changeset manually. Place the changeset in the `/.changeset` folder. ## Version Selection - Use `patch` for bug fixes and small changes (even with minor breaking changes) diff --git a/src/components/fields/TextInput/TextInput.tsx b/src/components/fields/TextInput/TextInput.tsx index abd4dce66..c5db0c775 100644 --- a/src/components/fields/TextInput/TextInput.tsx +++ b/src/components/fields/TextInput/TextInput.tsx @@ -32,6 +32,7 @@ export const TextInput = forwardRef(function TextInput( let { labelProps: userLabelProps, inputRef: propsInputRef, + form, ...restProps } = props; let localInputRef = useRef(null); diff --git a/src/components/form/Form/use-field/use-field-props.tsx b/src/components/form/Form/use-field/use-field-props.tsx index 889dba992..b641b1859 100644 --- a/src/components/form/Form/use-field/use-field-props.tsx +++ b/src/components/form/Form/use-field/use-field-props.tsx @@ -133,9 +133,12 @@ export function useFieldProps< ? field.field.errors[0] : undefined; + // Exclude 'form' from field to prevent it from being spread to DOM elements + const { form: _form, ...fieldWithoutForm } = field ?? {}; + const result: Props = isOutsideOfForm ? props - : mergeProps(props, field, valueProps, { + : mergeProps(props, fieldWithoutForm, valueProps, { validateTrigger: field.validateTrigger ?? defaultValidationTrigger, onBlur: onBlurChained, errorMessage: compiledErrorMessage,