Skip to content

MudPopover: Maintain Scroll Position#11765

Merged
danielchalmers merged 1 commit intoMudBlazor:devfrom
versile2:fix_popoverScroll
Aug 9, 2025
Merged

MudPopover: Maintain Scroll Position#11765
danielchalmers merged 1 commit intoMudBlazor:devfrom
versile2:fix_popoverScroll

Conversation

@versile2
Copy link
Contributor

@versile2 versile2 commented Aug 5, 2025

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:
flip-maxheight-badscroll

After:
flip-maxheight-fixedscroll

Checklist:

  • The PR is submitted to the correct branch (dev).
  • My code follows the style of this project.
  • I've added relevant tests or tested on existing ones.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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 scrollTop value of the list's first child element onto a custom mudScrollTop property on the main popover content node, specifically before its maxHeight is 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 maxHeight has been recalculated and applied, ensuring that the user's view within the list is maintained. After restoration, the temporary mudScrollTop property 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

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

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +588 to +591
if (popoverContentNode.mudScrollTop) {
firstChild.scrollTop = popoverContentNode.mudScrollTop;
popoverContentNode.mudScrollTop = null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
if (popoverContentNode.mudScrollTop) {
firstChild.scrollTop = popoverContentNode.mudScrollTop;
popoverContentNode.mudScrollTop = null;
}
if (typeof popoverContentNode.mudScrollTop === 'number') {
firstChild.scrollTop = popoverContentNode.mudScrollTop;
popoverContentNode.mudScrollTop = null;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the scroll position is at the beginning there's no reason to restore it.

Copy link
Member

Choose a reason for hiding this comment

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

Gemini already making mistakes lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eh it's not perfect but I'll still take double checking over not hehe

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 5, 2025

@github-actions github-actions bot added the bug Unexpected behavior or functionality not working as intended label Aug 6, 2025
@danielchalmers danielchalmers merged commit b9ec264 into MudBlazor:dev Aug 9, 2025
7 checks passed
This was referenced Sep 3, 2025
@versile2 versile2 deleted the fix_popoverScroll branch December 2, 2025 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MudMenu: unable to scroll down

2 participants