feat: add getPopupOffset prop for dynamic dropdown positioning#1218
feat: add getPopupOffset prop for dynamic dropdown positioning#1218Moses-main wants to merge 1 commit intoreact-component:masterfrom
Conversation
- Add getPopupOffset prop to BaseSelect for dynamic offset calculation - Implement dynamic offset support in SelectTrigger - This enables proper dropdown positioning for multi-line textareas - Fixes cursor position tracking in AutoComplete textarea
|
Someone is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
总体概述向 BaseSelectProps 和 SelectTriggerProps 添加了新的可选属性 getPopupOffset,用于根据输入元素动态计算弹出框偏移量。该属性在 SelectTrigger 中被集成到 mergedBuiltinPlacements 逻辑中,支持动态位置调整。 变更内容
预估代码审查工作量🎯 3 (中等) | ⏱️ ~20 分钟 推荐审阅者
诗歌
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a new getPopupOffset prop to enable dynamic positioning of the dropdown, addressing issues with multi-line textareas by correctly propagating the prop from BaseSelect to SelectTrigger and implementing the offset logic within builtinPlacements. A security review found no vulnerabilities.
| return customOffset; | ||
| } | ||
| // Default offset from base placement | ||
| return placement.offset as [number, number]; |
There was a problem hiding this comment.
The offset property in AlignType is optional. If placement.offset is undefined (e.g., if a custom builtinPlacements prop is provided without an offset for a specific placement), then placement.offset as [number, number] would return undefined. This could lead to unexpected behavior or runtime errors in the underlying Trigger component, which likely expects a [number, number] tuple if an offset is provided. Consider using the nullish coalescing operator (??) to provide a default offset like [0, 0] if placement.offset is undefined.
| return placement.offset as [number, number]; | |
| return placement.offset ?? [0, 0]; |
|
Add some test case please. |
This PR adds a new
getPopupOffsetprop to enable dynamic dropdown positioning, which is needed for proper cursor position tracking in multi-line textareas.Problem
When using AutoComplete with a multi-line TextArea, the dropdown stays at the top-left corner instead of following the cursor to the current line.
Solution
Add
getPopupOffsetprop that receives the input element and returns a[x, y]offset array for positioning the dropdown relative to the cursor.Changes
BaseSelect/index.tsx: AddgetPopupOffsetprop to interface and pass to SelectTriggerSelectTrigger.tsx: Implement dynamic offset calculation in builtinPlacementsUsage
Related Issue
Summary by CodeRabbit
新功能