fix: honor offset in non-virtual scrollTo, export scroll config types#57
fix: honor offset in non-virtual scrollTo, export scroll config types#57aojunhao123 wants to merge 3 commits into
Conversation
|
@aojunhao123 is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
|
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 (8)
🚧 Files skipped from review as they are similar to previous changes (7)
Walkthrough新增 Changes滚动边距与 scrollTo 流程
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ListyRef
participant useRawListScroll
participant TargetElement
participant Browser
ListyRef->>useRawListScroll: scrollTo(config)
useRawListScroll->>TargetElement: 设置 scrollMarginTop/Bottom
useRawListScroll->>Browser: 调用 scrollIntoView
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #57 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 211 209 -2
Branches 62 58 -4
=========================================
- Hits 211 209 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for custom offsets when scrolling to items or group headers in RawList. It refactors the scroll margin application by replacing the CSS-variable-based approach with direct inline styles (scrollMarginTop and scrollMarginBottom) dynamically computed on the target element. It also adds a new "Scroll To" demo, exports relevant types, and updates the test suite to verify the new behavior. There are no review comments, so I have no feedback to provide.
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.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/RawList/useRawListScroll.ts`:
- Around line 69-77: 在 useRawListScroll 中分离 item 与 group 的滚动定位属性:根据 isItem 选择
data-item-key 或 data-group-key 构造选择器,避免继续使用
data-key;同时确保对应的条目和分组节点分别写入匹配的数据属性,并保留现有 applyScrollMargin 的定位行为。
- Around line 39-52: Update applyScrollMargin so sticky header height is
included for item targets whenever align is not 'bottom', including 'auto';
retain zero header offset for bottom alignment and non-item targets.
🪄 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: 41b08372-c439-473b-a4a2-4559168c7b23
📒 Files selected for processing (7)
docs/demos/scroll-to.mddocs/examples/scroll-to.tsxsrc/RawList/index.tsxsrc/RawList/useRawListScroll.tssrc/index.tstests/listy.behavior.test.tsxtests/semantic.test.tsx
这个 PR 在做什么这个 PR 为 RawList 的 item/group 结论不适合合并 存在一个可由合法输入触发的滚动目标混淆问题:item key 与 group key 相同时,会滚动到错误节点。应先拆分两类节点的定位属性并补充回归测试;此外,当前分支与 问题清单🔴 高优先级(阻塞合并)
🟡 中优先级(建议修复)无。 🟢 低优先级(可选改进)无。 |
The virtual list already applied the `offset` from `scrollTo({ key, align,
offset })`, but the non-virtual RawList path ignored it: it set a
`--rc-listy-item-scroll-margin-top` CSS variable that only accounted for the
sticky header height and never the user's offset, and it never set a bottom
margin, so `align: 'bottom'` offsets did nothing.
- RawList now applies `scrollMarginTop`/`scrollMarginBottom` directly on the
scroll target at scroll time (header height + offset for items on `top`
align, offset otherwise), matching the virtual path.
- Drop the CSS-variable indirection and the per-render inline scrollMarginTop
on every item; the margin is applied only on the target, only when scrolling.
- Export `ScrollAlign` and `ListyScrollToConfig` so consumers can type the
config they pass to `scrollTo`.
- Add a `scroll-to` demo exercising both virtual and raw modes.
`align: 'auto'` maps to `scrollIntoView({ block: 'nearest' })`, which can land
the item at the container top where the sticky header would occlude it. The
header offset was only added for `align: 'top'`, so `auto` (and the default)
were left uncorrected in both the raw and virtual paths.
Apply the header offset whenever alignment is not explicitly `bottom`, in both
RawList and VirtualList, keeping the two modes consistent.
62adb9d to
7b6970c
Compare
这个 PR 在做什么PR #57 已 rebase 到包含 #56 的最新 结论不适合合并 RawList 的 offset 实现基本正确,但 VirtualList 对 问题清单🔴 高优先级(阻塞合并)
🟡 中优先级(建议修复)
🟢 低优先级(可选改进)
|
Summary
scrollTo({ key, align, offset })already appliedoffsetin the virtual list, but the non-virtual (virtual={false})RawListpath ignored it. It set a--rc-listy-item-scroll-margin-topCSS variable that only accounted for the sticky-header height, never the user'soffset, and it never set a bottom margin — soalign: 'bottom'offsets did nothing at all in non-virtual mode.This PR brings the non-virtual path to parity and tidies up the approach:
offset— it setsscrollMarginTop/scrollMarginBottomdirectly on the scroll target at scroll time (sticky-header height +offsetfor items withalign: 'top',offsetotherwise), matching the virtual list.--rc-listy-item-scroll-margin-top) and the per-render inlinescrollMarginTopon every item. The margin is now applied only on the actual target, and only while scrolling.ScrollAlignandListyScrollToConfigfrom the package entry so consumers can type the config they pass toscrollTo(previously declared but not exported).scroll-todemo that exercises both virtual and raw modes with livealign/offset/ key / group controls.No changes to the public config shape —
offsetwas already a typed option; it simply didn't work in non-virtual mode.Test plan
tests/listy.behavior.test.tsxandtests/semantic.test.tsxupdated and passing (25/25) — assertscrollMarginTop/scrollMarginBottomreflect header height + offset on the target, and that a user-suppliedstyles.item.scrollMarginTopis present at rest but the internal offset wins on the scroll target.tsc --noEmitcleaneslintclean on changed source and the new demoscroll-todemo in both virtual and non-virtual modes🤖 Generated with Claude Code
Summary by CodeRabbit
align: bottom时的滚动落点逻辑。