Filter non-DOM props from field widgets to prevent React warnings#371
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
3bb2c36
into
copilot/update-kernel-to-latest-version
There was a problem hiding this comment.
Pull request overview
This PR ensures that field widgets no longer leak form metadata props like inputType down to DOM elements, removing React warnings about unknown attributes while preserving existing behavior.
Changes:
- Updated 11 field widgets to destructure
inputTypeout ofFieldWidgetPropsand spread only the remainingdomPropsinto ShadcnInput,Textarea,Checkbox, andSwitchprimitives. - Adjusted
disabledhandling in each widget to read fromdomProps.disabledinstead of the originalprops.disabled, keeping semantics identical while avoiding new non-DOM props. - Added inline comments in each widget clarifying that the new destructuring is specifically to filter non-DOM props.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/fields/src/widgets/UrlField.tsx | Filters out inputType before spreading props into the URL Input, preventing non-DOM metadata from reaching the DOM while preserving readonly link behavior and disabled logic. |
| packages/fields/src/widgets/TimeField.tsx | Applies the same inputType filtering and domProps usage for the time Input, keeping readonly display untouched. |
| packages/fields/src/widgets/TextField.tsx | Filters inputType and uses domProps for both single-line Input and multiline Textarea branches, maintaining existing handling of rows, placeholders, and readonly rendering. |
| packages/fields/src/widgets/TextAreaField.tsx | Strips inputType before passing props to Textarea, leaving readonly rendering and max-length UI unchanged. |
| packages/fields/src/widgets/PhoneField.tsx | Prevents inputType from reaching the phone Input DOM node while keeping tel link rendering, placeholders, and error state behavior intact. |
| packages/fields/src/widgets/PasswordField.tsx | Filters inputType for the password Input, keeping visibility toggle and custom className handling the same while avoiding non-DOM attributes. |
| packages/fields/src/widgets/NumberField.tsx | Excludes inputType from props passed to the number Input, preserving precision, placeholder, readonly, and numeric onChange logic. |
| packages/fields/src/widgets/EmailField.tsx | Removes inputType from the props sent to the email Input, retaining readonly mailto link behavior and error state. |
| packages/fields/src/widgets/DateTimeField.tsx | Filters inputType before passing props into the datetime-local Input, leaving readonly formatted display unchanged. |
| packages/fields/src/widgets/DateField.tsx | Excludes inputType from the props for the date Input, maintaining readonly date formatting semantics. |
| packages/fields/src/widgets/BooleanField.tsx | Strips inputType from props passed to Checkbox/Switch while preserving readonly Yes/No display and existing ID/label wiring. |
| // Filter out non-DOM props | ||
| const { inputType, ...domProps } = props as any; | ||
|
|
There was a problem hiding this comment.
These new inputType-filtering semantics are not currently covered by tests: the existing UrlField tests in standard-widgets.test.tsx never pass an inputType prop or assert that it is stripped before reaching the DOM, so regressions here (e.g., accidentally re-spreading inputType) would not be caught. Consider adding a test case that renders UrlField (and/or the other updated widgets) with an inputType prop and verifies that it does not appear as an attribute on the underlying DOM element (or that React does not emit warnings via a mocked console).
| // Filter out non-DOM props | ||
| const { inputType, ...domProps } = props as any; | ||
|
|
There was a problem hiding this comment.
The inputType-filtering pattern (const { inputType, ...domProps } = props as any; followed by spreading domProps) is duplicated across several field widgets (Date, DateTime, Time, Text, TextArea, Number, Email, Phone, Url, Password, Boolean). To improve maintainability and keep this behavior consistent as the form metadata evolves, consider extracting a shared helper (e.g., in the widgets utilities) that strips non-DOM metadata props from FieldWidgetProps before they are passed to primitives, so future changes only need to be made in one place.
Field widgets were spreading metadata props like
inputTypedirectly to DOM elements, causing React to warn about unrecognized DOM attributes.Changes
Updated 11 field widget components to destructure and exclude
inputTypebefore spreading props:Pattern applied:
Affected widgets:
DateField,DateTimeField,TimeFieldTextField,TextAreaField,NumberFieldEmailField,PhoneField,UrlField,PasswordFieldBooleanFieldThe
inputTypeprop is form metadata used byObjectFormfor field type mapping and should not propagate to the DOM layer.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.