-
-
Notifications
You must be signed in to change notification settings - Fork 954
feat(Form): add useFormControl hook #4268
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
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
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.
Pull Request Overview
This pull request introduces the new useFormControl hook, which streamlines form control functionality for custom form components and integrates them seamlessly within a Form component. Key changes include the implementation of the useFormControl hook, updates to import paths and helper functions in related files, and corresponding documentation updates across component and validation pages.
Reviewed Changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/useFormControl/useFormControl.tsx | New hook implementation and lifecycle handling for form control. |
src/useFormControl/test/utilsSpec.ts | Updated import path for utils. |
src/useFormControl/index.tsx | Export updates for the hook. |
src/useFormControl/hooks/useField.ts | Updated import path for nameToPath. |
src/index.tsx | Export inclusion of useFormControl. |
src/FormControl/FormControl.tsx | Refactored to use the new hook; props and context values merged. |
src/Form/hooks/useFormValidate.ts | Updated import path for nameToPath in validation hook. |
src/Form/FormContext.tsx | Changed onFieldChange signature to allow an optional event. |
Documentation files | Updated examples and descriptions for useFormControl functionality. |
Files not reviewed (1)
- docs/component.config.json: Language not supported
Comments suppressed due to low confidence (1)
src/Form/FormContext.tsx:14
- [nitpick] Making the event parameter optional might affect consumers expecting the event argument. Ensure that all usages of onFieldChange suitably handle an undefined event.
onFieldChange: (name: string, value: any, event?: React.SyntheticEvent) => void;
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #4268 +/- ##
=======================================
Coverage 89.94% 89.94%
=======================================
Files 565 566 +1
Lines 13183 13200 +17
Branches 3273 3276 +3
=======================================
+ Hits 11857 11873 +16
- Misses 621 622 +1
Partials 705 705
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR introduces the new useFormControl hook to provide form control functionality in custom form components within a Form. It implements the hook and refactors associated modules and documentation to integrate the new functionality.
- Implements the useFormControl hook with proper registration, value management, and event handling for form fields.
- Refactors existing components (e.g., FormControl) to use the new hook.
- Updates documentation and tests to illustrate and validate the new hook's usage.
Reviewed Changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/useFormControl/useFormControl.tsx | New hook implementation for managing form control behavior |
src/useFormControl/test/utilsSpec.ts | Updated import path for nameToPath utility |
src/useFormControl/index.tsx | Export updates for useFormControl and its types |
src/useFormControl/hooks/useRegisterModel.ts | Changed register model function to be an exported function |
src/useFormControl/hooks/useField.ts | Adjusted exports and made nestedField optional |
src/index.tsx | Export updated for useFormControl hook |
src/FormControl/FormControl.tsx | Refactored to use useFormControl for handling form control logic |
src/Form/hooks/useFormValidate.ts | Updated import path for nameToPath utility |
src/Form/FormContext.tsx | Modified onFieldChange signature to accept an optional event |
Documentation files | Added and modified documentation to include useFormControl hook examples |
Files not reviewed (1)
- docs/component.config.json: Language not supported
Comments suppressed due to low confidence (1)
src/useFormControl/useFormControl.tsx:60
- [nitpick] Consider updating this error message to be clearer and more concise. Avoid referencing a fixed React version (16.6.0+) since it may become outdated over time, and consider throwing an error instead of logging to the console to enforce proper usage.
if (!onFieldChange) {
https://rsuite-nextjs-git-feat-add-useformcontrol-hook-rsuite.vercel.app/components/form/
The
useFormControl
hook provides form control functionality for custom form components. It must be used within a<Form>
component.(default)
(false)
(false)
Return Values
Example