Skip to content
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

feat: add tab ref #3974

Merged
merged 2 commits into from
Nov 4, 2024
Merged

feat: add tab ref #3974

merged 2 commits into from
Nov 4, 2024

Conversation

winchesHe
Copy link
Member

@winchesHe winchesHe commented Nov 2, 2024

  • fix: prevent test matcher warning

  • chore: add node types

  • chore: update Jest related packages

  • chore: run pnpm install

Summary by CodeRabbit

  • New Features

    • Expanded documentation for the Tabs component, including detailed examples and usage scenarios.
    • Added support for rendering tabs as links with examples for Next.js and React Router.
    • Introduced a new optional tabRef property for the Tab component, allowing direct reference to the tab item.
  • Bug Fixes

    • Improved test coverage for the Tabs component, including ref forwarding and various rendering scenarios.
  • Documentation

    • Clarified installation instructions and enhanced API documentation with detailed prop descriptions and default values.

Copy link

changeset-bot bot commented Nov 2, 2024

🦋 Changeset detected

Latest commit: cd67ce2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@nextui-org/tabs Patch
@nextui-org/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Nov 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextui-docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 7:22am
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 7:22am

Copy link
Contributor

coderabbitai bot commented Nov 2, 2024

Walkthrough

The changes in this pull request enhance the documentation and functionality of the Tabs component. Key updates include the addition of a tabRef prop to the Tab component, expanded usage examples, and improved API documentation. The installation instructions have been clarified, and new subsections have been added to explain rendering tabs as links. Additionally, a new test case has been introduced to verify ref forwarding in the Tabs component, while existing tests have been organized for better coverage.

Changes

File Path Change Summary
apps/docs/content/docs/components/tabs.mdx Clarified installation instructions, expanded usage examples, added link rendering sections, enhanced API documentation.
packages/components/tabs/tests/tabs.test.tsx Added a test for ref forwarding to tab items; organized existing tests for better coverage.
packages/components/tabs/src/base/tab-item-base.ts Added tabRef prop to Props interface for tab item component.
packages/components/tabs/src/tab.tsx Updated ref handling to use mergeRefs, added tabRef to destructured props.

Possibly related PRs

Suggested labels

📋 Scope : Docs

Suggested reviewers

  • jrgarciadev
  • wingkwong

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b6b4209 and cd67ce2.

📒 Files selected for processing (1)
  • .changeset/smooth-mayflies-wonder.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/smooth-mayflies-wonder.md

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
packages/components/tabs/src/tab.tsx (1)

98-98: Consider adding null check for tabRef

While the implementation is correct, consider adding a null check before merging refs to prevent potential issues with undefined tabRef.

Here's a safer implementation:

-      ref={mergeRefs(domRef, tabRef)}
+      ref={tabRef ? mergeRefs(domRef, tabRef) : domRef}
apps/docs/content/docs/components/tabs.mdx (1)

279-279: Enhance the tabRef prop documentation with usage examples.

While the tabRef prop documentation is clear, it would be more helpful to include a brief example of its usage, particularly for cases where direct DOM access is needed (e.g., focus management, scroll into view, etc.).

Consider adding a usage example in the description, such as:
"A ref to the tab item. Useful for programmatic focus management or custom DOM interactions. Example: const tabRef = useRef(null);"

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8de427b and b6b4209.

📒 Files selected for processing (4)
  • apps/docs/content/docs/components/tabs.mdx (1 hunks)
  • packages/components/tabs/__tests__/tabs.test.tsx (1 hunks)
  • packages/components/tabs/src/base/tab-item-base.ts (2 hunks)
  • packages/components/tabs/src/tab.tsx (3 hunks)
🔇 Additional comments (6)
packages/components/tabs/src/base/tab-item-base.ts (2)

2-2: LGTM: Clean import addition

The addition of RefObject import is clean and necessary for the new tabRef prop type definition.


21-22: LGTM: Well-documented ref forwarding support

The tabRef property is well-typed and properly documented. This addition enables proper ref forwarding, which is a common React pattern for accessing DOM elements directly when necessary.

Let's verify the test coverage for this new prop:

✅ Verification successful

Proper test coverage exists for the tabRef prop

The verification shows that the tabRef prop is well-tested in packages/components/tabs/__tests__/tabs.test.tsx. The test creates a ref using createRef<HTMLButtonElement>(), passes it to the Tab component via tabRef, and verifies that the ref is properly attached by checking that ref.current is not null.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there are tests covering the new tabRef prop

# Look for test files related to tabs
rg -l "test|describe|it" packages/components/tabs/

# Look for existing test cases using refs in tabs
rg -A 5 "useRef|createRef|tabRef" packages/components/tabs/

Length of output: 3137

packages/components/tabs/src/tab.tsx (3)

4-4: LGTM: Clean import addition

The mergeRefs utility is appropriately imported alongside related utilities.


47-47: LGTM: Clean props addition

The tabRef prop is correctly destructured from the component props.


Line range hint 47-98: Verify relation to test matcher warnings

While the implementation looks solid, could you clarify how these ref-related changes help prevent test matcher warnings? This would help ensure the changes align with the PR objectives.

apps/docs/content/docs/components/tabs.mdx (1)

Line range hint 1-400: Documentation structure and content are well-organized.

The documentation is comprehensive and well-structured, covering installation, usage examples, accessibility, and API details. The addition of the tabRef prop fits naturally within the existing structure.

@winchesHe winchesHe changed the title fix: prevent test matcher warning (#3893) feat: add tab ref Nov 2, 2024
Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. please add a changeset
  2. any issue / linear page you can link?
  3. just wondering if it is a feat or fix? the title and the branch name are different.

@winchesHe
Copy link
Member Author

  1. please add a changeset
  2. any issue / linear page you can link?
  3. just wondering if it is a feat or fix? the title and the branch name are different.
  1. fixed
  2. No, i found it can't get the tab elment by ref, It lost ref property in state collections, because React Aria doesn't add the ref property to items. Therefore, I added a tabRef to handle that
    image
  3. feat but i create a fix branch name

@wingkwong wingkwong added this to the v2.5.0 milestone Nov 4, 2024
@jrgarciadev jrgarciadev merged commit 7c2c9c4 into canary Nov 4, 2024
8 checks passed
@jrgarciadev jrgarciadev deleted the fix/tab-ref branch November 4, 2024 15:05
ryo-manba pushed a commit that referenced this pull request Nov 6, 2024
* feat: add tab ref

* feat: add changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants