-
Notifications
You must be signed in to change notification settings - Fork 71
fix(eds-core-react)!: Improve onChange handler typing for TextField component and remove multiline support #4134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: torleifhalseth <2523381+torleifhalseth@users.noreply.github.com>
This is very complex and I would like to fix the fundamental issue even if this breaks existing implementations of TextField with multiple prop set to true. People using TextField with multiple should use the TextArea component. Could we refactor so that this works as expected without the overly complex OverridableComponent type? We want to keep this as simple and close to native input as possible. @copilot |
Co-authored-by: torleifhalseth <2523381+torleifhalseth@users.noreply.github.com>
I've simplified the implementation as requested. The changes in commit 30a1738: Breaking Change:
Simplified Solution:
Result:
The TextField implementation is now straightforward - it's just a wrapper around Input with label, helper text, and meta support. Users needing multiline should use the Textarea component directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we create documentation on how to migrate existing use of TextField with multiple property. We could also suggest prompts to run in codebases to refactor the use of TextField with multiple to use TextArea. We could also provide codemods to update this breaking change. Can you look at this @copilot ?
CSSProperties, | ||
ElementType, | ||
ComponentPropsWithoutRef, | ||
InputHTMLAttributes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used. Should be removed @copilot ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the unused import in commit 91fa52c.
describe('Input onChange typing', () => { | ||
it('Should properly type onChange event for Input', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you improve these descriptions to be more specific @copilot ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated test descriptions to be more user-friendly in commit 91fa52c:
- "Allows onChange handler without manual event type annotation"
- "Allows onFocus handler without manual event type annotation"
// This should work without manual typing | ||
// event.target.value should be properly typed as string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this in the description of the tests, but dont include the technical parts with reference to object values. @copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the comments to focus on user benefits in commit 91fa52c. Changed from technical implementation details to "TypeScript infers event type automatically".
Co-authored-by: torleifhalseth <2523381+torleifhalseth@users.noreply.github.com>
Co-authored-by: torleifhalseth <2523381+torleifhalseth@users.noreply.github.com>
Created comprehensive migration resources in commit 0756981:
Quick usage: # Find TextField with multiline
rg "TextField.*multiline" src/
# Auto-migrate with codemod
npx jscodeshift -t textfield-to-textarea.codemod.js --parser=tsx src/ |
Problem
When using
onChange
handlers withTextField
component, developers had to manually specify event types, which created unnecessary boilerplate and reduced developer experience:This was caused by the
TextField
type definition using a union type that prevented TypeScript from properly inferring event types.Solution
Simplified TextField Implementation
Simplified
packages/eds-core-react/src/components/TextField/TextField.tsx
:multiline
prop support from TextField - users should now use theTextarea
component directly for multiline inputrowsMax
andtextareaRef
propsInputHTMLAttributes<HTMLInputElement>
Input
component (much closer to native input behavior)Reverted Complex Changes
packages/eds-utils/src/utils/overridableComponent.ts
to original simple implementationIntrinsicElementFromHTMLElement
helper typeAdded Test Coverage
Input.onChange.test.tsx
: Verifies onChange and onFocus event typing for InputTextField.onChange.test.tsx
: Verifies onChange event typing for TextFieldResult
TextField now properly types onChange handlers without manual type annotations:
For multiline text input, users should now use the
Textarea
component directly:Migration Resources
To help with the breaking change, comprehensive migration resources have been provided:
1. Migration Guide (
MIGRATION_TEXTFIELD_MULTILINE.md
)2. Automated Codemod (
textfield-to-textarea.codemod.js
)npx jscodeshift -t textfield-to-textarea.codemod.js --parser=tsx src/
3. Codemod Documentation (
CODEMOD.md
)4. Search Prompts (
SEARCH_PROMPTS.md
)Quick Migration
Find TextField with multiline:
rg "TextField.*multiline" src/
Auto-migrate:
Manual migration:
Testing
Fixes #4133
Original prompt
Fixes #4133
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.