improvement(components): [virtual-list] preventDefault only when the scroll directions match#22989
Conversation
… scroll directions match
|
Hello, @rzzf, your PR title does not meet the standards, please refer to here. |
commit: |
|
Size Change: +13 B (0%) Total Size: 1.6 MB
ℹ️ View Unchanged
|
|
🧪 Playground Preview: https://element-plus.run/?pr=22989 |
Yeah, this issue is known on Windows, and there is already a PR addressing it. |
|
Sorry I don't see any difference too; feel like the same here. Perhaps with trackpad it will but I currently don't have any right now. |
I'll install a virtual machine and conduct a thorough investigation when I have time. I think this issue needs to be addressed. |
|
After rebasing with #22168 this patch works too 😃 . |
📝 WalkthroughWalkthroughRefines the wheel event preventDefault logic in the virtual-list hook to only prevent default behavior on non-Firefox browsers when an actual scroll delta occurs, rather than unconditionally on non-Firefox browsers. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
🔇 Additional comments (1)
Comment |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/components/virtual-list/src/hooks/use-wheel.ts (1)
41-41: Critical: Early return blocks perpendicular scrolls when at edge.When
newOffsetis 0 (perpendicular scroll), the conditionhasReachedEdge(offset) && hasReachedEdge(offset + newOffset)simplifies tohasReachedEdge(offset) && hasReachedEdge(offset), which returns early if the accumulated offset has reached an edge in the primary direction.Example scenario:
- User scrolls to the top of a vertical list (offset becomes negative, atStartEdge is true)
- Before rAF fires, user tries to scroll horizontally via Shift+wheel
- newOffset = 0 (vertical layout uses deltaY, but Shift+wheel produces deltaX)
- Line 41 evaluates:
hasReachedEdge(offset) = true,hasReachedEdge(offset + 0) = true- Function returns early, blocking the horizontal scroll
This defeats the purpose of this PR, which is to allow perpendicular scrolling.
🔎 Proposed fix
- if (hasReachedEdge(offset) && hasReachedEdge(offset + newOffset)) return + if (newOffset !== 0 && hasReachedEdge(offset) && hasReachedEdge(offset + newOffset)) returnThis ensures the early return only applies when actually scrolling in the primary direction.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/components/virtual-list/src/hooks/use-wheel.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Build windows-latest LTS
- GitHub Check: Unit Test (New)
- GitHub Check: Build ubuntu-latest LTS
- GitHub Check: Lint
- GitHub Check: SSR rendering test
- GitHub Check: Unit Test (LTS)
- GitHub Check: Unit Test (Current)
- GitHub Check: build
- GitHub Check: size-report
- GitHub Check: Coverage
🔇 Additional comments (1)
packages/components/virtual-list/src/hooks/use-wheel.ts (1)
45-47: The logic change is correct but references to unverified platform issues should be removed.The addition of
&& newOffset !== 0correctly preventspreventDefault()from being called when there is no scroll movement in the primary direction (newOffset = 0), which aligns with the stated objective. This allows perpendicular scrolling to pass through as intended.However, references to PR #22168, unresolved Windows Shift+scroll behavior, and platform-specific issues mentioned in the review could not be verified in the codebase. The code already includes Windows Shift+scroll handling (lines 33-37), and the condition logic is sound. Remove speculative claims about unresolved platform problems unless they are substantiated with specific failing test cases or documented issues.
|
@rzzf Thanks for your contribution! ❤️ |



Sometimes we do need tree-v2 to support horizontal scrolling, and the simplest solution is to handle it with custom external styles.
However, the current implementation prevents the default wheel behavior, which makes it impossible to use Shift + scroll or a trackpad to trigger horizontal scrolling.
Therefore, I think we should only prevent the default behavior in the layout direction, and allow scrolling in other directions.
#9861
#20881
demo
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.