Skip to content

[material-ui][Popper] Fix scroll jump when popperOptions change#48089

Closed
AyushCoder9 wants to merge 1 commit into
mui:masterfrom
AyushCoder9:fix/issue-48087-datepicker-scroll-jump
Closed

[material-ui][Popper] Fix scroll jump when popperOptions change#48089
AyushCoder9 wants to merge 1 commit into
mui:masterfrom
AyushCoder9:fix/issue-48087-datepicker-scroll-jump

Conversation

@AyushCoder9

Copy link
Copy Markdown

Fixes mui/mui-x#21839

What

Fixes a bug where providing a dynamic popperOptions (e.g., an inline object) to Popper or DatePicker causes the page to automatically scroll to the bottom when an interior component is auto-focused.

Why

Issue mui/mui-x#21839 reports that when popperOptions is passed to a controlled DatePicker with views={['month', 'year']}, selecting a month causes the page to scroll down.

When popperOptions changes its reference (like passing an inline {} object on render), BasePopper.tsx’s useEnhancedEffect destroys and creates the popper.js instance.

popper.destroy() synchronously clears the inline CSS position, top, and left properties applied to the DOM element by @popperjs/core before the next instance is created. This temporarily causes the element to revert to position: static. Since the Popper is typically mounted in a Portal at the end of the document.body, the static element drops to the absolute bottom of the HTML page flow. When the Year view subsequently receives auto-focus, the browser scrolls down to bring the newly-focused element into view, causing the jarring visual jump.

How

In packages/mui-material/src/Popper/BasePopper.tsx, I updated the cleanup phase of the useEnhancedEffect. Directly after popper.destroy(), we manually restore the original inline position: fixed along with top: 0 and left: 0.
This bridges the small gap right after destruction, ensuring the Portal element remains fixed and detached from regular document flow, completely avoiding bottom-page layouts and subsequent jumping on autofocus.

I also added a simple unit test ensuring position: static is not temporarily set.

@mui-bot

mui-bot commented Mar 24, 2026

Copy link
Copy Markdown

Netlify deploy preview

https://deploy-preview-48089--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 🔺+67B(+0.01%) 🔺+37B(+0.03%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against 81fc6f2

@AyushCoder9 AyushCoder9 force-pushed the fix/issue-48087-datepicker-scroll-jump branch from a4f642f to 6cf4dc6 Compare March 24, 2026 19:45
@AyushCoder9 AyushCoder9 force-pushed the fix/issue-48087-datepicker-scroll-jump branch from 6cf4dc6 to 81fc6f2 Compare March 24, 2026 20:01
@AyushCoder9

Copy link
Copy Markdown
Author

@jarib Kindly check this PR

@ZeeshanTamboli

Copy link
Copy Markdown
Member

See mui/mui-x#21839 (comment).

@mj12albert

Copy link
Copy Markdown
Member

Apologies I missed this and opened #48121

Appreciate the effort 🙏

@mj12albert mj12albert closed this Mar 30, 2026
Comment on lines +212 to +215
// Restore the fixed positioning to prevent scroll jump before next Popper creation
tooltipNode.style.position = 'fixed';
tooltipNode.style.top = '0';
tooltipNode.style.left = '0';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The actual values should be read before .destroy() to restore to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: Popper The React component. See <Popup> for the latest version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatePicker - controlled DatePicker with views={["month", "year"]} and popperOptions set to anything causes scrolling down when selecting month

5 participants