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

fix(popover): unexpected props on a DOM element #2522

Merged
merged 18 commits into from
Apr 2, 2024

Conversation

wingkwong
Copy link
Member

@wingkwong wingkwong commented Mar 14, 2024

📝 Description

Currently if you create a Custom Trigger in Dropdown with elements which don't have isDisabled prop, e.g. div, <User/>, adding isDisabled would make React fail to recognize it on a DOM element. Hence, adding the isDisabled logic to cover this case. Also remove isDisabled prop for non NextUI button elements.

⛳️ Current behavior (updates)

Currently if you set isDisabled to dropdown, it won't make it disabled.

image

🚀 New behavior

With this fix, the dropdown is disabled.

image

💣 Is this a breaking change (Yes/No):

No

📝 Additional Information

Summary by CodeRabbit

  • New Features
    • Introduced a new property isDropdownDisabled for enhanced control over the disabled state of Popover triggers.
  • Enhancements
    • Improved handling of custom triggers and DOM elements within Popover components, including disabled state management.
    • Added a utility function to identify NextUI components, enhancing component recognition capabilities.

Copy link

changeset-bot bot commented Mar 14, 2024

🦋 Changeset detected

Latest commit: fc2c55a

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

This PR includes changesets to release 28 packages
Name Type
@nextui-org/popover Patch
@nextui-org/system-rsc Patch
@nextui-org/theme Patch
@nextui-org/autocomplete Patch
@nextui-org/dropdown Patch
@nextui-org/select Patch
@nextui-org/react Patch
@nextui-org/badge Patch
@nextui-org/code Patch
@nextui-org/divider Patch
@nextui-org/kbd Patch
@nextui-org/skeleton Patch
@nextui-org/spacer Patch
@nextui-org/spinner Patch
@nextui-org/system Patch
@nextui-org/accordion Patch
@nextui-org/button Patch
@nextui-org/listbox Patch
@nextui-org/menu Patch
@nextui-org/modal Patch
@nextui-org/navbar Patch
@nextui-org/slider Patch
@nextui-org/snippet Patch
@nextui-org/table Patch
@nextui-org/tabs Patch
@nextui-org/tooltip Patch
@nextui-org/aria-utils Patch
@nextui-org/framer-transitions 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
Contributor

coderabbitai bot commented Mar 14, 2024

Warning

Rate Limit Exceeded

@wingkwong has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 15 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 1da2651 and fc2c55a.

Walkthrough

The recent updates encompass enhancements and bug fixes in a React application, focusing on prop handling and component recognition. These changes address issues related to unrecognized props on DOM elements, refine disabled state management in dropdown components, and introduce utility functions for identifying NextUI components. This holistic approach not only resolves specific bug reports but also enhances the overall robustness and developer experience within the library.

Changes

File Path Change Summary
.packages/components/popover/src/popover-trigger.tsx Added imports and logic for isDisabled prop handling, custom triggers, and introduced isDropdownDisabled property.
.packages/core/theme/src/components/popover.ts Incorporated styles based on the isDropdownDisabled state.
.packages/core/system-rsc/src/utils.ts Introduced isNextUIEl function to enhance component recognition for NextUI components.
.packages/components/dropdown/__tests__/dropdown.test.tsx
.packages/components/input/__tests__/input.test.tsx
Updated test cases for dropdown and input components.

Assessment against linked issues

Objective Addressed Explanation
Address React warning about unrecognized isDisabled and originalProps props on DOM elements (#2474, #2528, #2593)
Ensure custom attributes are correctly handled and do not generate warnings in React (#2474, #2528, #2593)
Introduce utility function for identifying NextUI components to improve component recognition and handling (#2474, #2528, #2593)

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

vercel bot commented Mar 14, 2024

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

Name Status Preview Comments Updated (UTC)
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2024 6:50am

Copy link

vercel bot commented Mar 14, 2024

@wingkwong is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 5a8768a and 58ecceb.
Files selected for processing (2)
  • .changeset/lovely-snakes-approve.md (1 hunks)
  • packages/components/popover/src/popover-trigger.tsx (2 hunks)
Additional comments: 4
.changeset/lovely-snakes-approve.md (1)
  • 5-5: The changeset description is clear and effectively communicates the purpose of the patch. The mention of "isDisabled" is accurate in the context of prop names, so any spelling concerns flagged by tools can be disregarded.
packages/components/popover/src/popover-trigger.tsx (3)
  • 2-3: The addition of cn and filterDOMProps imports supports the new functionality for handling custom triggers and filtering props, aligning with the PR's objectives.
  • 43-48: The logic to handle isDisabled for custom triggers, such as div elements or custom components, is well-implemented. It ensures that the disabled state is visually represented and prevents React warnings for unrecognized props. Please ensure that filterDOMProps is thoroughly tested to confirm it filters out only the necessary props.
  • 55-55: The final return statement cleverly merges props to ensure the child element receives the appropriate functionality. It's recommended to test this implementation with various trigger types, including custom components, to ensure no unintended side effects occur.

@wingkwong wingkwong marked this pull request as draft March 14, 2024 12:25
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 58ecceb and ac5cdda.
Files selected for processing (1)
  • packages/components/popover/src/popover-trigger.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/components/popover/src/popover-trigger.tsx

@wingkwong wingkwong changed the title fix(popover): handle isDisabled logic for elements without isDisabled props fix(popover): unexpected props on a DOM element Mar 15, 2024
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between ac5cdda and 1001b5e.
Files selected for processing (4)
  • .changeset/lovely-snakes-approve.md (1 hunks)
  • packages/components/popover/src/popover-trigger.tsx (2 hunks)
  • packages/components/popover/src/use-popover.ts (1 hunks)
  • packages/core/theme/src/components/popover.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/components/popover/src/popover-trigger.tsx
Additional comments: 3
.changeset/lovely-snakes-approve.md (1)
  • 1-6: The changeset description is clear and accurately reflects the PR objectives. The mentioned "spelling mistakes" by the static analysis tool are false positives, as "isDisabled" is correctly used in the context of a prop name.
packages/core/theme/src/components/popover.ts (1)
  • 165-170: The addition of the isDisabled variant logic is correctly implemented, using conditional styles to adjust the popover trigger's appearance and interaction based on the disabled state. This change enhances the component's functionality and user experience.
packages/components/popover/src/use-popover.ts (1)
  • 242-254: The introduction of popoverTriggerClassName to dynamically handle the disabled state for custom triggers lacking an isDisabled prop is correctly implemented. This approach ensures that the component remains flexible and functional across various use cases, enhancing its usability.

@wingkwong wingkwong marked this pull request as draft March 15, 2024 16:24
@wingkwong wingkwong marked this pull request as ready for review March 16, 2024 07:05
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 1001b5e and 0147b9a.
Files selected for processing (3)
  • packages/components/popover/src/popover-trigger.tsx (3 hunks)
  • packages/components/popover/src/use-popover.ts (1 hunks)
  • packages/core/theme/src/components/popover.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • packages/components/popover/src/popover-trigger.tsx
  • packages/components/popover/src/use-popover.ts
  • packages/core/theme/src/components/popover.ts

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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 0147b9a and 7e8b4e8.
Files selected for processing (2)
  • packages/components/popover/src/popover-trigger.tsx (3 hunks)
  • packages/core/system-rsc/src/utils.ts (1 hunks)
Additional Context Used
Additional comments not posted (5)
packages/components/popover/src/popover-trigger.tsx (4)

2-3: The addition of isNextUIEl and filterDOMProps imports aligns with the PR's objective to handle isDisabled logic more effectively. This ensures that the necessary utilities are available for filtering props and identifying NextUI elements.


32-32: Renaming rest to restProps improves code readability by making it clearer that these are the remaining props after destructuring. This is a good practice for code clarity.


45-57: The logic to determine isDisabled and isNextUIElement, and subsequently filter DOM props, is crucial for avoiding React warnings about unrecognized props. This approach effectively addresses the issue with custom triggers lacking an isDisabled prop. However, ensure that the enabled property in filterDOMProps is intended to be used here, as its naming might suggest enabling rather than filtering out props.

Verification successful

The enabled property within filterDOMProps is intended to control whether the filtering process is active. If set to false, the function returns the original props without any filtering. This mechanism allows for conditional filtering based on specific conditions, such as the presence of custom triggers lacking an isDisabled prop. The review comment is consistent with the codebase, and the use of the enabled property is correctly implemented to control the activation of the filtering process.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the intended use and effect of the `enabled` property in `filterDOMProps`.
grep -R "filterDOMProps" --include=\*.tsx

Length of output: 2545



Script:

#!/bin/bash
# Search for the implementation of `filterDOMProps` within `@nextui-org/react-utils` package.
grep -R "function filterDOMProps" --include=\*.ts

Length of output: 143



Script:

#!/bin/bash
# Display the contents of the file where `filterDOMProps` is implemented.
cat packages/utilities/react-rsc-utils/src/filter-dom-props.ts

Length of output: 1898


58-58: Using mergeProps to combine buttonProps with filtered restProps is a neat way to ensure that the correct props are passed to the child component. This maintains the component's functionality while adhering to the best practices of prop management.

packages/core/system-rsc/src/utils.ts (1)

109-111: The isNextUIEl function is a valuable addition for identifying NextUI components. This function will help in implementing logic that depends on whether a component is part of the NextUI library. It's important to ensure that all NextUI components have a consistent displayName that includes "NextUI" for this function to work reliably.

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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 7e8b4e8 and 6023e89.
Files selected for processing (1)
  • .changeset/lovely-snakes-approve.md (1 hunks)
Additional Context Used
Additional comments not posted (1)
.changeset/lovely-snakes-approve.md (1)

1-7: The changeset correctly documents the version updates for @nextui-org/popover, @nextui-org/system-rsc, and @nextui-org/theme as patches, which is appropriate for the described bug fixes. The summary provided gives a clear overview of the issue addressed by the pull request.

@jrgarciadev jrgarciadev added this to the v2.3.0 milestone Mar 31, 2024
@jrgarciadev
Copy link
Member

@wingkwong could you please add some tests to avoid this happening in the future?

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

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 6023e89 and f3c7c1d.
Files selected for processing (1)
  • packages/components/dropdown/tests/dropdown.test.tsx (2 hunks)
Additional Context Used
Additional comments not posted (1)
packages/components/dropdown/__tests__/dropdown.test.tsx (1)

7-7: The import of User from the shared-icons directory is correctly added to support the new test cases.

packages/components/dropdown/__tests__/dropdown.test.tsx Outdated Show resolved Hide resolved
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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between f3c7c1d and 1da2651.
Files selected for processing (1)
  • packages/components/dropdown/tests/dropdown.test.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/components/dropdown/tests/dropdown.test.tsx
Additional Context Used

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

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 1da2651 and 4f6099d.
Files selected for processing (3)
  • .changeset/thirty-islands-trade.md (1 hunks)
  • packages/components/input/tests/input.test.tsx (3 hunks)
  • packages/components/radio/src/use-radio.ts (1 hunks)
Additional Context Used
Additional comments not posted (2)
packages/components/input/__tests__/input.test.tsx (1)

99-106: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [103-117]

The modification to remove asynchronous behavior in this test case simplifies it and potentially improves reliability. If this change was made for specific reasons such as performance or reliability, consider adding a comment to clarify.

packages/components/radio/src/use-radio.ts (1)

222-222: The modification in the getInputProps function improves prop merging by adjusting the order and removing direct prop spreading. This change enhances control over prop precedence. Ensure to verify through additional testing that this new order does not inadvertently affect component behavior, especially in edge cases.

.changeset/thirty-islands-trade.md Outdated Show resolved Hide resolved
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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 4f6099d and 3c0ed1e.
Files selected for processing (1)
  • packages/components/dropdown/tests/dropdown.test.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/components/dropdown/tests/dropdown.test.tsx
Additional Context Used

@jrgarciadev jrgarciadev merged commit c5049ed into nextui-org:main Apr 2, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment