Repository navigation
[scroll area] Add data-scrolling state attribute to Root and Viewport parts - #3823
Conversation
commit: |
Greptile SummaryThis PR exposes the Key changes:
The implementation follows the existing patterns in the codebase and properly reuses the Confidence Score: 5/5
Important Files Changed
|
Greptile's behavior is changing!From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
I wonder if this CSS feels too aggressive in terms of blocking pointers after a scroll with the default debounce ( .Viewport[data-scrolling] .ListItem {
pointer-events: none;
}If you scroll, abruptly stop, then move your pointer, it's temporarily (admittedly a short period) going to prevent the UI from being interactive. It's somewhat minor, but for fast interactions it could be an annoyance. Have you found that in your testing? |
@atomiks Not really, we're using this approach in multiple places in our production app with lots of users and never got any complaints. But there's different way of doing this via MutationObserver like:
This way interactions will not be blocked at all. Additionally I have another PR coming that implements the But then again, its just one of the use cases but there's more like styling the scroll area based on the scrolling state. In which case having the attribute directly on the Root and Viewport is better than doing complex selectors like Another use case is disabling expensive hover effects in list items like animating box shadow when scroll is in progress etc |
|
@atomiks please lmk if we can roll with it 🫡 |
atomiks
left a comment
There was a problem hiding this comment.
This seems okay to me. You can't tell if x or y is scrolling unlike the Scrollbar part, but let's go with this for now as that could be added if necessary later.
Bundle size reportℹ️ Using snapshot from parent commit ad517c7 (fallback from merge base 247001c).
Check out the code infra dashboard for more information about this PR. |
data-scrolling state attribute to Root and Viewport parts
Summary
This PR exposes the
data-scrollingattribute onScrollArea.RootandScrollArea.Viewportcomponents, in addition to the existing implementation onScrollArea.Scrollbar.Motivation
Previously,
data-scrollingwas only available on the Scrollbar component. However, many common use cases require detecting scroll state on the Root or Viewport to apply styles or disable interactions on ScrollArea children during scroll via CSS.Use Cases
1. Disable pointer events during scroll to prevent overfetching
When you have a list of items that prefetch data on hover, scrolling through the list can trigger many unnecessary prefetch requests. Disabling pointer events during scroll solves this:
Screen.Recording.2026-01-22.at.08.51.06.mov
2. Hiding Tooltips on scroll:
Screen.Recording.2026-01-22.at.08.47.10.mov
3. Disabling 'play on hover' feature in a scrollable grid of videos
Changes
Test Plan
pnpm typescript passes
pnpm eslint passes
pnpm prettier passes
Added tests in ScrollAreaRoot.test.tsx for Root's data-scrolling
Added tests in ScrollAreaViewport.test.tsx for Viewport's data-scrolling
Existing ScrollArea tests pass
I have followed (at least) the PR section of the contributing guide.