feat(dropdown): 添加滚动容器内锁定功能#7069
Conversation
- 当 Dropdown 打开时锁定父级滚动容器的滚动 - 添加相关测试用例
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough在 ChangesDropdown 滚动容器 overflow 锁定
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
commit: |
There was a problem hiding this comment.
Code Review
This pull request introduces scroll locking for the scroll parent of a Dropdown component when it is opened, restoring the original overflow style upon closing or unmounting, and adds corresponding unit tests. The reviewer identified a potential issue where multiple Dropdown components sharing the same scroll parent could cause state conflicts (such as premature unlocking). To resolve this, the reviewer suggested implementing a module-level WeakMap to keep track of the scroll lock count for each scroll parent, ensuring the overflow style is only restored when all dropdowns sharing that parent are closed.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7069 +/- ##
=======================================
Coverage 93.35% 93.35%
=======================================
Files 337 337
Lines 7416 7451 +35
Branches 1859 1910 +51
=======================================
+ Hits 6923 6956 +33
- Misses 485 487 +2
Partials 8 8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/dropdown/dropdown.tsx`:
- Around line 108-123: The current implementation saves and restores the
overflow style on a per-instance basis, which causes issues when multiple
Dropdown components share the same scrollParent. When the first Dropdown closes,
it restores the overflow style prematurely, and the second Dropdown may then set
it incorrectly. Implement reference counting per scrollParent container:
maintain a map or counter that tracks how many Dropdown instances are currently
using each scrollParent, save the original overflow only when the first instance
starts using it, and only restore the original overflow when the counter reaches
zero (when the last Dropdown instance closes). This applies to both the code
section around containerRef.current and getScrollParent(container) where
overflow is being set (lines 108-123) and where it is being restored (lines
135-137).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 656a74cf-a65a-4c1e-acd5-190c9a4f2eea
📒 Files selected for processing (2)
src/components/dropdown/dropdown.tsxsrc/components/dropdown/tests/dropdown.test.tsx
- 使用 WeakMap 维护滚动容器的锁计数状态 - 只有当所有 Dropdown 都关闭时才恢复原始 overflow 样式 - 添加测试用例验证多 Dropdown 场景
这个 PR 在做什么这个 PR 为 结论不适合合并 核心思路对,但当前实现的引用计数在真实 DOM 下会失效:第一个 Dropdown 锁住容器后,第二个 Dropdown 可能已经找不到这个滚动父容器,导致仍会提前解锁。 问题清单🔴 高优先级(阻塞合并)
🟡 中优先级(建议修复)
🟢 低优先级(可选改进)无。 |
- 新增 getLockTarget 方法精确查找要锁定的容器 - 优化滚动锁定逻辑,防止多 Dropdown 共享容器时提前解锁 - 更新测试用例验证修复效果
fixed #6606
Summary by CodeRabbit
Release Notes
Bug Fixes
overflowY,关闭后恢复;多个下拉共享同一滚动父容器时不会提前解锁。Tests
window场景(不修改 body 溢出样式),以及多个实例共享时的引用计数解锁与卸载恢复。