-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis 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
Sequence DiagramsequenceDiagram
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
Assessment against linked issues
Possibly related issues
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
🦋 Changeset detectedLatest commit: 386a421 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
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]); |
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.
Incorrect initial placement caused animation to be applied in the wrong direction.
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.
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 newPopoverTopOrBottom
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
⛔ 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.
Whenplacement
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 importedariaShouldCloseOnInteractOutside
seems correctly integrated when constructing the popover logic.
92-92
: Validate default placement.
You changed the defaultplacement
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 updatedgetPopoverProps
merges theplacement
andshouldCloseOnInteractOutside
. 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
: Renamingplacement
toariaPlacement
.
Destructuring theplacement
asariaPlacement
is clear. Just confirm references to the originalplacement
variable are now updated.
182-191
: Returnnull
placement carefully.
WhenariaPlacement
isnull
, you returnnull
forplacement
. Ensure dependent logic can handle anull
placement gracefully without runtime errors.
224-224
: Consolidatedata-placement
logic.
Setting"data-placement"
helps style or test arrow positioning. This appears valid.
238-241
: Ensure re-render triggers.
Includingplacement
andariaPlacement
in the dependency array is prudent. This ensures consistent arrow placement updates.
325-325
: Expose final placement.
Referencing the computedplacement
here is good. Confirm that external code can handle anull
value if that arises.packages/components/dropdown/stories/dropdown.stories.tsx (1)
839-862
: Great demonstration of all placements.
The newPlacements
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
Whenplacement
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 computedstyle
prop in your Framer Motion component simplifies the code and maintains readability. This is a well-structured approach.
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.
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
📒 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
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)
Autocomplete and Select animations are also incorrect.
🚀 New behavior
dropdown-arrow-placement.mov
Arrow is now applied correctly. However, the arrow’s position is slightly off for
left-start
orright-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
New Features
Refactor