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): correct position logic #4498

Merged
merged 5 commits into from
Jan 5, 2025
Merged

fix(popover): correct position logic #4498

merged 5 commits into from
Jan 5, 2025

Conversation

ryo-manba
Copy link
Member

@ryo-manba ryo-manba commented Jan 5, 2025

Closes #4466

📝 Description

This PR fixes the initial position logic for the Popover.
Previously, the popover could animate in the wrong direction or fail to show the DropDown arrow.

⛳️ Current behavior (updates)

  • The popover occasionally animates incorrectly.
  • The DropDown arrow may fail to appear.

Autocomplete and Select animations are also incorrect.

🚀 New behavior

  • Popover animates from the correct direction.
  • The DropDown arrow displays properly.
dropdown-arrow-placement.mov

Arrow is now applied correctly. However, the arrow’s position is slightly off for left-start or right-end placements, which will be addressed separately:

See: https://github.com/nextui-org/nextui/blob/canary/packages/core/theme/src/components/popover.ts#L58-L61

select-popover.mov
autocomplete-popover.mov

I also fixed the issue causing the Select and Autocomplete animation to be misaligned.

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

No.

📝 Additional Information

Related PRs

Summary by CodeRabbit

  • Bug Fixes

    • Resolved placement and animation issues for dropdown, popover, and select components
    • Fixed initial popover animation and arrow display (related to issue [BUG] - DropDown arrow position #4466)
  • New Features

    • Added new placement stories for dropdown, select, and autocomplete components
    • Enhanced component positioning flexibility
  • Refactor

    • Simplified overlay positioning logic
    • Streamlined placement handling for various UI components

@ryo-manba ryo-manba requested a review from jrgarciadev as a code owner January 5, 2025 08:57
Copy link

vercel bot commented Jan 5, 2025

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 Jan 5, 2025 9:32am
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 5, 2025 9:32am

Copy link
Contributor

coderabbitai bot commented Jan 5, 2025

Walkthrough

This pull request introduces patches for three components from the NextUI library: Dropdown, Popover, and Select. The changes address issues related to the initial animation of the popover and the positioning of the dropdown arrow. The updates simplify the implementation of these components by removing unnecessary complexity, enhancing their placement logic, and adding new stories for testing various configurations.

Changes

File Change Summary
packages/components/dropdown/package.json Removed dependency on @react-aria/overlays
packages/components/dropdown/src/use-dropdown.ts Simplified placement logic and removed overlay positioning utilities
packages/components/dropdown/stories/dropdown.stories.tsx Added new Placements story showcasing dropdown placement options
packages/components/popover/src/free-solo-popover.tsx Enhanced transformOrigin style handling based on placement
packages/components/popover/src/popover-content.tsx Streamlined transform origin style assignment
packages/components/popover/src/use-popover.ts Improved placement determination logic
packages/components/select/stories/select.stories.tsx Added PopoverTopOrBottom story
packages/components/autocomplete/stories/autocomplete.stories.tsx Added PopoverTopOrBottom story

Sequence Diagram

sequenceDiagram
    participant User
    participant Dropdown
    participant Popover
    
    User->>Dropdown: Trigger dropdown
    Dropdown->>Popover: Determine placement
    Popover-->>Dropdown: Apply correct transform origin
    Dropdown->>User: Display with accurate positioning
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix dropdown arrow positioning [#4466]
Correct placement behavior

Possibly related issues

Possibly related PRs

Suggested reviewers

  • wingkwong
  • jrgarciadev

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

changeset-bot bot commented Jan 5, 2025

🦋 Changeset detected

Latest commit: 386a421

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

This PR includes changesets to release 6 packages
Name Type
@nextui-org/dropdown Patch
@nextui-org/popover Patch
@nextui-org/react Patch
@nextui-org/autocomplete Patch
@nextui-org/date-picker Patch
@nextui-org/select 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

Comment on lines +182 to +190
const placement = useMemo(() => {
// If ariaPlacement is null, popoverProps.style isn't set,
// so we return null to avoid an incorrect animation value.
if (!ariaPlacement) {
return null;
}

return getShouldUseAxisPlacement(ariaPlacement, placementProp) ? ariaPlacement : placementProp;
}, [ariaPlacement, placementProp]);
Copy link
Member Author

Choose a reason for hiding this comment

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

Incorrect initial placement caused animation to be applied in the wrong direction.

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

🧹 Nitpick comments (1)
packages/components/select/stories/select.stories.tsx (1)

1498-1517: Consider clarifying the story name and adding tests
The new PopoverTopOrBottom story effectively demonstrates how the popover behaves at the top and bottom, but the story name might benefit from "PopoverTopAndBottom" for clarity. Additionally, consider adding an automated test or visual regression check to confirm that the popover is positioned correctly.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a43b156 and bb38ca7.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • .changeset/lazy-rice-wash.md (1 hunks)
  • packages/components/dropdown/package.json (0 hunks)
  • packages/components/dropdown/src/use-dropdown.ts (3 hunks)
  • packages/components/dropdown/stories/dropdown.stories.tsx (1 hunks)
  • packages/components/popover/src/free-solo-popover.tsx (1 hunks)
  • packages/components/popover/src/popover-content.tsx (2 hunks)
  • packages/components/popover/src/use-popover.ts (6 hunks)
  • packages/components/select/stories/select.stories.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/components/dropdown/package.json
✅ Files skipped from review due to trivial changes (1)
  • .changeset/lazy-rice-wash.md
🔇 Additional comments (13)
packages/components/popover/src/free-solo-popover.tsx (1)

61-61: Confirm "center" mapping.
When placement is "center", the transform origin is forced to "top". Verify if this is indeed the intended behavior for centrally placed popovers or if you need to differentiate between horizontal and vertical centering.

packages/components/dropdown/src/use-dropdown.ts (3)

12-12: Import usage confirmed.
The newly imported ariaShouldCloseOnInteractOutside seems correctly integrated when constructing the popover logic.


92-92: Validate default placement.
You changed the default placement to "bottom". Ensure this aligns with design requirements and doesn’t break existing UI expectations.


149-149: No apparent issues with merged popover props.
The updated getPopoverProps merges the placement and shouldCloseOnInteractOutside. Everything looks consistent.

packages/components/popover/src/use-popover.ts (6)

11-11: New utility import.
getShouldUseAxisPlacement is newly imported. Confirm it is used as intended for the axis-based placement logic.


156-160: Renaming placement to ariaPlacement.
Destructuring the placement as ariaPlacement is clear. Just confirm references to the original placement variable are now updated.


182-191: Return null placement carefully.
When ariaPlacement is null, you return null for placement. Ensure dependent logic can handle a null placement gracefully without runtime errors.


224-224: Consolidate data-placement logic.
Setting "data-placement" helps style or test arrow positioning. This appears valid.


238-241: Ensure re-render triggers.
Including placement and ariaPlacement in the dependency array is prudent. This ensures consistent arrow placement updates.


325-325: Expose final placement.
Referencing the computed placement here is good. Confirm that external code can handle a null value if that arises.

packages/components/dropdown/stories/dropdown.stories.tsx (1)

839-862: Great demonstration of all placements.
The new Placements story thoroughly showcases top, bottom, left, and right placements (including -start/-end) for testing in various layouts.

packages/components/popover/src/popover-content.tsx (2)

83-85: Validate fallback placement logic
When placement is "center", the code uses "top" as a fallback for transform origins. Verify that "center" is valid or necessary, and confirm that the fallback to "top" is the desired outcome across all popover usage scenarios.


96-96: Approved usage of style prop
Applying the computed style prop in your Framer Motion component simplifies the code and maintains readability. This is a well-structured approach.

@ryo-manba ryo-manba marked this pull request as draft January 5, 2025 09:14
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

🧹 Nitpick comments (1)
packages/components/autocomplete/stories/autocomplete.stories.tsx (1)

1190-1209: Consider adding a descriptive story title or a short doc string.
Currently named "PopoverTopOrBottom," it might be more intuitive to convey that this story illustrates how the autocomplete’s popover appears when placed at the top or in the middle. A short doc string or a more descriptive name can help future maintainers and contributors quickly grasp the scenario.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb38ca7 and 386a421.

📒 Files selected for processing (3)
  • .changeset/lazy-rice-wash.md (1 hunks)
  • packages/components/autocomplete/stories/autocomplete.stories.tsx (1 hunks)
  • packages/components/select/stories/select.stories.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/lazy-rice-wash.md
  • packages/components/select/stories/select.stories.tsx

@ryo-manba ryo-manba changed the title fix(popover): fix logic for popover position fix(popover): correct position logic Jan 5, 2025
@wingkwong wingkwong added this to the v2.6.11 milestone Jan 5, 2025
@jrgarciadev jrgarciadev merged commit 33e0418 into canary Jan 5, 2025
8 checks passed
@jrgarciadev jrgarciadev deleted the issue-4466 branch January 5, 2025 12:32
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.

[BUG] - DropDown arrow position
3 participants