Skip to content

[scroll area] Add data-scrolling state attribute to Root and Viewport parts - #3823

Merged
atomiks merged 13 commits into
mui:masterfrom
arturbien:feat-scrollarea-data-scrolling
Jan 29, 2026
Merged

atomiks merged 13 commits into
mui:masterfrom
arturbien:feat-scrollarea-data-scrolling

Conversation

@arturbien

@arturbien arturbien commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR exposes the data-scrolling attribute on ScrollArea.Root and ScrollArea.Viewport components, in addition to the existing implementation on ScrollArea.Scrollbar.

Motivation

Previously, data-scrolling was 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:

.Viewport[data-scrolling] .ListItem {
  pointer-events: none;
}
<ScrollArea.Root>
  <ScrollArea.Viewport className="Viewport">
    {items.map((item) => (
      <div 
        key={item.id} 
        className="ListItem"
        onMouseEnter={() => prefetch(item.id)}
      >
        {item.name}
      </div>
    ))}
  </ScrollArea.Viewport>
</ScrollArea.Root>
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

  • Added scrolling to ScrollAreaRootState and ScrollAreaViewportState
  • Root and Viewport now compute scrolling: scrollingX || scrollingY
  • Added data-scrolling to ScrollAreaRootDataAttributes
  • Updated documentation reference files
  • Added tests for the new attribute

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.

@pkg-pr-new

pkg-pr-new Bot commented Jan 22, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3823
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3823
    

commit: c7d21c7

@greptile-apps

greptile-apps Bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR exposes the data-scrolling attribute on ScrollArea.Root and ScrollArea.Viewport components by adding a scrolling boolean property to their state interfaces. The property is computed as scrollingX || scrollingY, leveraging the existing scroll state tracking mechanism.

Key changes:

  • Added scrolling property to ScrollAreaRootState and ScrollAreaViewportState (packages/react/src/scroll-area/root/ScrollAreaRoot.tsx:210, packages/react/src/scroll-area/viewport/ScrollAreaViewport.tsx:407)
  • The data-scrolling attribute is automatically applied through the getStateAttributesProps utility's fallback behavior for boolean state properties
  • Added scrolling enum entry to ScrollAreaRootDataAttributes with documentation
  • Added comprehensive tests for both Root and Viewport components that verify the attribute appears during scroll and disappears after the scroll timeout
  • Updated JSON documentation files for all three components
  • Fixed a typo in the Scrollbar documentation ('users' → 'user')

The implementation follows the existing patterns in the codebase and properly reuses the scrollingX and scrollingY state that was already being tracked at the Root level and passed through context.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is clean and follows established patterns in the codebase. The scrolling state property is correctly computed from existing scrollingX and scrollingY state values. The data-scrolling attribute is automatically applied through the existing getStateAttributesProps utility's fallback behavior for boolean state properties. Comprehensive tests were added for both Root and Viewport components, and documentation was properly updated.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/scroll-area/root/ScrollAreaRoot.tsx Added scrolling property to Root state, correctly computed from `scrollingX
packages/react/src/scroll-area/viewport/ScrollAreaViewport.tsx Added scrolling property to Viewport state, correctly computed from `scrollingX
packages/react/src/scroll-area/root/ScrollAreaRoot.test.tsx Added comprehensive test for data-scrolling attribute on Root, tests both vertical and horizontal scroll
packages/react/src/scroll-area/viewport/ScrollAreaViewport.test.tsx Added comprehensive test for data-scrolling attribute on Viewport, tests both vertical and horizontal scroll

@greptile-apps

greptile-apps Bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

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".

@netlify

netlify Bot commented Jan 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit c7d21c7
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/697be54e2984f8000853dc18
😎 Deploy Preview https://deploy-preview-3823--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@arturbien arturbien changed the title Feat scrollarea data scrolling [ScrollArea] feat: data-scrolling attribute on Root and Viewport Jan 22, 2026
@atomiks

atomiks commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor

I wonder if this CSS feels too aggressive in terms of blocking pointers after a scroll with the default debounce (500ms)

.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?

@arturbien

arturbien commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor Author

I wonder if this CSS feels too aggressive in terms of blocking pointers after a scroll with the default debounce (500ms)

.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:

  • observe ScrollArea.Root data-scrolling attribute and update the scrolling state changes in React.useRef
  • onMouseEnter={() => isScrollingRef.current ? undefined : prefetch}

This way interactions will not be blocked at all.

Additionally I have another PR coming that implements the scrollend event in ScrollArea in supported browsers. With this there will be no 500ms delay

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 .Root:has(.Scrollbar[data-scrolling]) {...}

Another use case is disabling expensive hover effects in list items like animating box shadow when scroll is in progress etc

@zannager zannager added the component: scroll area Changes related to the scroll area component. label Jan 23, 2026
@arturbien

Copy link
Copy Markdown
Contributor Author

@atomiks please lmk if we can roll with it 🫡

@atomiks atomiks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mui-bot

mui-bot commented Jan 28, 2026 •

Copy link
Copy Markdown

Bundle size report

ℹ️ Using snapshot from parent commit ad517c7 (fallback from merge base 247001c).

Bundle Parsed size Gzip size
@base-ui/react 🔺+99B(+0.02%) 🔺+2B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@arturbien
arturbien requested a review from atomiks January 29, 2026 14:06
@atomiks atomiks changed the title [ScrollArea] feat: data-scrolling attribute on Root and Viewport [scroll area] Add data-scrolling state attribute to Root and Viewport parts Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: scroll area Changes related to the scroll area component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants