MudPopover: Maintain Scroll Position#11765
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @versile2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses a user experience issue within the MudPopover component, specifically when it's used with list content. Previously, during dynamic height adjustments or 'flip' operations, the scroll position within the popover's list would be lost. My changes introduce a mechanism to preserve and restore this scroll state, ensuring that users maintain their position within the list even as the popover's layout changes.
Highlights
- Scroll Position Preservation: I've implemented logic to save the current scroll position of the popover's list content. This is done by storing the
scrollTopvalue of the list's first child element onto a custommudScrollTopproperty on the main popover content node, specifically before itsmaxHeightis reset for re-evaluation (lines 331-332). - Scroll Position Restoration: I've added code to restore the previously saved scroll position to the list content. This occurs after the
maxHeighthas been recalculated and applied, ensuring that the user's view within the list is maintained. After restoration, the temporarymudScrollTopproperty is cleared (lines 588-590).
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request aims to fix an issue where the scroll position of a popover is lost during a flip operation. The approach is to save the scroll position before recalculating the popover's height and restore it afterward. The implementation is generally sound, but I've identified a bug where the scroll position is not restored if it's at the very top (position 0). I've provided a suggestion to fix this.
| if (popoverContentNode.mudScrollTop) { | ||
| firstChild.scrollTop = popoverContentNode.mudScrollTop; | ||
| popoverContentNode.mudScrollTop = null; | ||
| } |
There was a problem hiding this comment.
The current condition if (popoverContentNode.mudScrollTop) will evaluate to false if mudScrollTop is 0. This means the scroll position will not be restored when the user has scrolled to the very top of the list, which is a valid state that should be preserved.
To fix this, we should check if mudScrollTop is a number. This ensures that a scrollTop of 0 is correctly handled, while null or undefined values are ignored.
| if (popoverContentNode.mudScrollTop) { | |
| firstChild.scrollTop = popoverContentNode.mudScrollTop; | |
| popoverContentNode.mudScrollTop = null; | |
| } | |
| if (typeof popoverContentNode.mudScrollTop === 'number') { | |
| firstChild.scrollTop = popoverContentNode.mudScrollTop; | |
| popoverContentNode.mudScrollTop = null; | |
| } |
There was a problem hiding this comment.
If the scroll position is at the beginning there's no reason to restore it.
There was a problem hiding this comment.
Gemini already making mistakes lol
There was a problem hiding this comment.
Eh it's not perfect but I'll still take double checking over not hehe
|



Resolves #11667 (2nd attempt)
During a flip operation there is code to handle the height of lists. In order to respect "FlipAlways" that code needs to be evaluated each time a movement happens. By resetting the heights if they were modified prior to flip checks scroll position can be lost. I added simple code to save the scroll position of the list and restore it after the height calculation.
Before:

After:

Checklist:
dev).