Spaces:
Sleeping
Sleeping
Pull Request Number: 4279 | |
Title: fix: ref in form component | |
Base Branch: canary | |
Head Branch: fix/form-ref | |
Author: jrgarciadev | |
URL: https://github.com/nextui-org/nextui/pull/4279 | |
State: MERGED | |
Created At: 2024-12-08T11:48:35Z | |
Merged At: 2024-12-08T11:50:12Z | |
Participants: jrgarciadev | |
Description: | |
Closes # | |
π Description | |
β³οΈ Current behavior (updates) | |
π New behavior | |
π£ Is this a breaking change (Yes/No): | |
π Additional Information | |
Summary by CodeRabbit | |
New Features | |
Added support for refs in the Form component, allowing direct access to the underlying DOM node or component instance. | |
Tests | |
Introduced a new test suite for the Form component to verify rendering behavior and ref assignment. | |
Commits: | |
- fix: ref in form component\n | |
Labels: | |
Comments: | |
- changeset-bot: ### π¦ Changeset detected | |
Latest commit: f2695e244390c4187e0f057f2d4fcf208c1d8777 | |
**The changes in this PR will be included in the next version bump.** | |
<details><summary>This PR includes changesets to release 11 packages</summary> | |
| Name | Type | | |
| ------------------------ | ----- | | |
| @nextui-org/form | Patch | | |
| @nextui-org/autocomplete | Patch | | |
| @nextui-org/checkbox | Patch | | |
| @nextui-org/date-input | Patch | | |
| @nextui-org/date-picker | Patch | | |
| @nextui-org/input-otp | Patch | | |
| @nextui-org/input | Patch | | |
| @nextui-org/radio | Patch | | |
| @nextui-org/select | Patch | | |
| @nextui-org/react | Patch | | |
| @nextui-org/table | Patch | | |
</details> | |
Not sure what this means? [Click here to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md). | |
[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/nextui-org/nextui/new/fix/form-ref?filename=.changeset/strange-yaks-sin.md&value=---%0A%22%40nextui-org%2Fform%22%3A%20patch%0A---%0A%0Afix%3A%20ref%20in%20form%20component%0A) | |
\n- vercel: [vc]: #lNQA74O8WHECx6Pi4j/SUAt4+SpZxp5d32+XcrcSu+I=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJuZXh0dWktZG9jcy12MiIsInJvb3REaXJlY3RvcnkiOiJhcHBzL2RvY3MiLCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vbmV4dHVpLW9yZy9uZXh0dWktZG9jcy12Mi84MjhEcG4zcXhOdkdpWHVOaWFCR2N2eTlZbXZNIiwicHJldmlld1VybCI6Im5leHR1aS1kb2NzLXYyLWdpdC1maXgtZm9ybS1yZWYtbmV4dHVpLW9yZy52ZXJjZWwuYXBwIiwibmV4dENvbW1pdFN0YXR1cyI6IlBFTkRJTkciLCJsaXZlRmVlZGJhY2siOnsicmVzb2x2ZWQiOjAsInVucmVzb2x2ZWQiOjAsInRvdGFsIjowLCJsaW5rIjoibmV4dHVpLWRvY3MtdjItZ2l0LWZpeC1mb3JtLXJlZi1uZXh0dWktb3JnLnZlcmNlbC5hcHAifX0seyJuYW1lIjoibmV4dHVpLXN0b3J5Ym9vay12MiIsInJvb3REaXJlY3RvcnkiOiJwYWNrYWdlcy9zdG9yeWJvb2siLCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vbmV4dHVpLW9yZy9uZXh0dWktc3Rvcnlib29rLXYyL0hoMTJRa1gzYXE4S3A3S0FDUTdnczlTREQ2TkMiLCJwcmV2aWV3VXJsIjoibmV4dHVpLXN0b3J5Ym9vay12Mi1naXQtZml4LWZvcm0tcmVmLW5leHR1aS1vcmcudmVyY2VsLmFwcCIsIm5leHRDb21taXRTdGF0dXMiOiJQRU5ESU5HIiwibGl2ZUZlZWRiYWNrIjp7InJlc29sdmVkIjowLCJ1bnJlc29sdmVkIjowLCJ0b3RhbCI6MCwibGluayI6Im5leHR1aS1zdG9yeWJvb2stdjItZ2l0LWZpeC1mb3JtLXJlZi1uZXh0dWktb3JnLnZlcmNlbC5hcHAifX1dfQ== | |
**The latest updates on your projects**. Learn more about [Vercel for Git βοΈ](https://vercel.link/github-learn-more) | |
| Name | Status | Preview | Comments | Updated (UTC) | | |
| :--- | :----- | :------ | :------- | :------ | | |
| **nextui-docs-v2** | π Building ([Inspect](https://vercel.com/nextui-org/nextui-docs-v2/828Dpn3qxNvGiXuNiaBGcvy9YmvM)) | [Visit Preview](https://nextui-docs-v2-git-fix-form-ref-nextui-org.vercel.app) | π¬ [**Add feedback**](https://vercel.live/open-feedback/nextui-docs-v2-git-fix-form-ref-nextui-org.vercel.app?via=pr-comment-feedback-link) | Dec 8, 2024 11:48am | | |
| **nextui-storybook-v2** | π Building ([Inspect](https://vercel.com/nextui-org/nextui-storybook-v2/Hh12QkX3aq8Kp7KACQ7gs9SDD6NC)) | [Visit Preview](https://nextui-storybook-v2-git-fix-form-ref-nextui-org.vercel.app) | π¬ [**Add feedback**](https://vercel.live/open-feedback/nextui-storybook-v2-git-fix-form-ref-nextui-org.vercel.app?via=pr-comment-feedback-link) | Dec 8, 2024 11:48am | | |
\n- coderabbitai: <!-- This is an auto-generated comment: summarize by coderabbit.ai --> | |
<!-- This is an auto-generated comment: failure by coderabbit.ai --> | |
> [!CAUTION] | |
> ## Review failed | |
> | |
> The pull request is closed. | |
<!-- end of auto-generated comment: failure by coderabbit.ai --> | |
<!-- internal state start --> | |
<!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACIAM0QADx5A+LQceMIqViVWXkJKLHxY6AB3DFQmQNoYhQj4L1xkamgRKhJXJkQMFSlMLEZ0RBVixES6xXxG6CxnIVaAFgAmAHYATi1oAElw9HhCZDpGQugAcU0ACVwhTHDprwBVWwAZHgBteHx8XmQuAHp/iRNPAbloWKx/pQkvhcIgINkSFCyDC4f9eL4fP8VhsALoACi+Pz+gOB0zBEORqPhiKpsMQ6Mx2LW6wAlFoPDMVMhqoheJJTvxCFIRjFE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6kSEolsEiqlCgUSoleCqb97SHhA/eERoi730F7QaEF0BkXhGgwsWDKlTR5niDrGx/GJknorGQF5wpVCeiOFQGCsIxxgavTstOgQUxJIyA7fAoyQRXlkcCPcIjerUCdFgPDUhUwjFqgAIRAqE7IUiAXM3oJSsmS8V5TnpfuJlW9Ga70VScZV3KlRqtPr6mA8cDwHDGqcjshmmjwdYjwURCWRYJLyRI6AABeaA+IhS/B4BI6wUFfishqwYaAABvaAWg+vQAAL5SIUUmlR161F6MzXah1ZCkhSMAEmEiKyvhH0pVqWtWRMYvxP8htOkJH1da38C+aUWuYeQP6NITXsgrtE0/ddm7t1pT3WQLaBh2s9b61sAbrJhs4EURAi1KbTOoMm1mmbxjKHGBmqAOaXtFpPRWq9daMRNqcC+j9T1/182nTUBoUGV0IZAA=== --> | |
<!-- internal state end --> | |
<!-- walkthrough_start --> | |
## Walkthrough | |
The changes in this pull request introduce reference support to the Form component within the "@nextui-org/form" package. This enhancement allows users to attach refs to the Form component, enabling direct access to the underlying DOM node or component instance. The implementation involves modifying the Form component to use `forwardRef`, allowing it to forward refs to its underlying elements. Additionally, a new test suite is added to verify the rendering behavior and ref assignment of the Form component. | |
## Changes | |
| File | Change Summary | | |
|--------------------------------------------------|---------------------------------------------------------------------------------------------------------------------| | |
| .changeset/eighty-buttons-do.md | Added ref support to the Form component in the "@nextui-org/form" package. | | |
| packages/components/form/__tests__/form.test.tsx | Introduced a new test suite for the Form component, verifying rendering and ref assignment using React Testing Library. | | |
| packages/components/form/src/form.tsx | Modified the Form component to use `forwardRef`, allowing ref forwarding to the underlying AriaForm component. | | |
## Possibly related PRs | |
- **#3011**: This PR adds missing ref support to the input wrapper in the date-picker component, which is related to the main PR's enhancement of ref support in the Form component. | |
- **#3533**: This PR focuses on synchronizing ref values with internal state in the Input component, which aligns with the main PR's introduction of ref support in the Form component. | |
- **#4198**: This PR addresses issues with forwardRef render functions, ensuring they utilize the ref parameter correctly, which is directly relevant to the main PR's changes to the Form component's ref handling. | |
## Suggested reviewers | |
- wingkwong | |
<!-- walkthrough_end --> | |
--- | |
<details> | |
<summary>π Recent review details</summary> | |
**Configuration used: .coderabbit.yaml** | |
**Review profile: CHILL** | |
<details> | |
<summary>π₯ Commits</summary> | |
Reviewing files that changed from the base of the PR and between 9b7c5e48f2a6b036f1081473a158bca60b8881cd and f2695e244390c4187e0f057f2d4fcf208c1d8777. | |
</details> | |
<details> | |
<summary>π Files selected for processing (3)</summary> | |
* `.changeset/eighty-buttons-do.md` (1 hunks) | |
* `packages/components/form/__tests__/form.test.tsx` (1 hunks) | |
* `packages/components/form/src/form.tsx` (1 hunks) | |
</details> | |
</details> | |
<!-- tips_start --> | |
--- | |
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? | |
<details> | |
<summary>β€οΈ Share</summary> | |
- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) | |
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) | |
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) | |
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) | |
</details> | |
<details> | |
<summary>πͺ§ Tips</summary> | |
### Chat | |
There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): | |
- Review comments: Directly reply to a review comment made by CodeRabbit. Example: | |
- `I pushed a fix in commit <commit_id>, please review it.` | |
- `Generate unit testing code for this file.` | |
- `Open a follow-up GitHub issue for this discussion.` | |
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: | |
- `@coderabbitai generate unit testing code for this file.` | |
- `@coderabbitai modularize this function.` | |
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: | |
- `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` | |
- `@coderabbitai read src/utils.ts and generate unit testing code.` | |
- `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` | |
- `@coderabbitai help me debug CodeRabbit configuration file.` | |
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. | |
### CodeRabbit Commands (Invoked using PR comments) | |
- `@coderabbitai pause` to pause the reviews on a PR. | |
- `@coderabbitai resume` to resume the paused reviews. | |
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. | |
- `@coderabbitai full review` to do a full review from scratch and review all the files again. | |
- `@coderabbitai summary` to regenerate the summary of the PR. | |
- `@coderabbitai resolve` resolve all the CodeRabbit review comments. | |
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. | |
- `@coderabbitai help` to get help. | |
### Other keywords and placeholders | |
- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. | |
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. | |
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically. | |
### Documentation and Community | |
- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. | |
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. | |
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. | |
</details> | |
<!-- tips_end -->\n | |
Files Changed: | |
- .changeset/eighty-buttons-do.md (added, 5 changes)\n Patch: @@ -0,0 +1,5 @@ | |
+--- | |
+"@nextui-org/form": patch | |
+--- | |
+ | |
+Add ref support to Form component\n- packages/components/form/__tests__/form.test.tsx (added, 19 changes)\n Patch: @@ -0,0 +1,19 @@ | |
+import * as React from "react"; | |
+import {render} from "@testing-library/react"; | |
+ | |
+import {Form} from "../src"; | |
+ | |
+describe("Form", () => { | |
+ it("should render correctly", () => { | |
+ const wrapper = render(<Form />); | |
+ | |
+ expect(() => wrapper.unmount()).not.toThrow(); | |
+ }); | |
+ | |
+ it("ref should be forwarded", () => { | |
+ const ref = React.createRef<HTMLFormElement>(); | |
+ | |
+ render(<Form ref={ref} />); | |
+ expect(ref.current).not.toBeNull(); | |
+ }); | |
+});\n- packages/components/form/src/form.tsx (modified, 9 changes)\n Patch: @@ -1,11 +1,14 @@ | |
+import type {ForwardedRef} from "react"; | |
+ | |
import {useProviderContext} from "@nextui-org/system"; | |
+import {forwardRef} from "react"; | |
import {Form as AriaForm, FormProps} from "./base-form"; | |
-export const Form = (props: FormProps) => { | |
+export const Form = forwardRef(function Form(props: FormProps, ref: ForwardedRef<HTMLFormElement>) { | |
const globalContext = useProviderContext(); | |
const validationBehavior = | |
props.validationBehavior ?? globalContext?.validationBehavior ?? "aria"; | |
- return <AriaForm {...props} validationBehavior={validationBehavior} />; | |
-}; | |
+ return <AriaForm {...props} ref={ref} validationBehavior={validationBehavior} />; | |
+});\n |