Skip to content

MudPopover: MudList MaxHeight Adjustments#11734

Merged
danielchalmers merged 4 commits intoMudBlazor:devfrom
versile2:fix_11730
Aug 4, 2025
Merged

MudPopover: MudList MaxHeight Adjustments#11734
danielchalmers merged 4 commits intoMudBlazor:devfrom
versile2:fix_11730

Conversation

@versile2
Copy link
Contributor

@versile2 versile2 commented Jul 29, 2025

Resolves #11730

There is a section of code that triggers when a popover has FlipAlways or FlipOnOpen that is supposed to determine if

  1. The popover is a MudList -> Typically a MudSelect, MudMenu, or MudAutocomplete.
  2. The list or popover does not already have a max height set
  3. The popover would exceed all of the available space even after it flips. (minus padding on top/bottom)

Then if it would exceed the available space it would assign a max height to both the popover and the mud list that would force a recalculation and repositioning resulting in a best fit scenario.

Found and Fixed 3 bugs in the calculation and reworked it to be easier to follow.
Bug 1) I was not resetting the list maxheight if I altered it during a reflow.
Bug 2) I was doing the reset outside of flip logic. Unnecessary
Bug 3) [and the one related to attached issue] If a popover started at exactly the the top position that matches the overflow it tried to set maxheight. Previously it was getting overwritten in a reflow but a previous fix brought this edge case bug out.

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.

Updated `mudPopover.js` to improve handling of popover maximum height, including checks for "mud-list" elements and adjustments based on viewport space. Ensured proper display in relation to the app bar and added logic for resetting max height for recalculations.

Introduced a new test layout in `PopoverListMaxHeightTest.razor` to demonstrate the popover's functionality, featuring a `MudAppBar` with a menu. This test is linked to a related GitHub issue for tracking purposes.
@github-actions github-actions bot added the bug Unexpected behavior or functionality not working as intended label Jul 29, 2025
@versile2 versile2 requested a review from Copilot July 29, 2025 21:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes bugs in the MudPopover JavaScript logic that handles max height adjustments for MudList components (used in MudSelect, MudMenu, MudAutocomplete) when they would exceed available screen space after flipping.

  • Refactored the height adjustment logic to be clearer and more maintainable
  • Fixed three specific bugs: improper max height reset, unnecessary reset outside flip logic, and edge case where popover at exact top position incorrectly triggered max height setting
  • Added a test component to verify the fix for issue #11730

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/MudBlazor/TScripts/mudPopover.js Restructured popover height adjustment logic, fixed bugs in max height calculations and reset behavior
src/MudBlazor.UnitTests.Viewer/TestComponents/Popover/PopoverListMaxHeightTest.razor Added test component demonstrating MudMenu behavior in app bar layout

@danielchalmers
Copy link
Member

Could you take a look at the Quality Gate

@versile2
Copy link
Contributor Author

versile2 commented Aug 1, 2025

should have fixed all the sonarcube problems, however now it's mad because eslint is using a really old version.
https://sonarcloud.io/organizations/mudblazor/rules?open=javascript%3AS6582&rule_key=javascript%3AS6582
Check JS is ES6 compliant:

1s
Run eslint --env 'es6' MudBlazor/TScripts
  eslint --env 'es6' MudBlazor/TScripts
  shell: /usr/bin/bash -e {0}

/home/runner/work/MudBlazor/MudBlazor/src/MudBlazor/TScripts/mudPopover.js
  323:43  error  Parsing error: Unexpected token .

✖ 1 problem (1 error, 0 warnings)

Error: Process completed with exit code 1.

So if we can support ES2020 then update .eslintrc here:

{
  "parserOptions": {
    "ecmaVersion": 2020
  }
}

or change line 323 to read (sonar will complain):

const isList =
  firstChild &&
  firstChild.classList &&
  firstChild.classList.contains("mud-list");

@versile2 versile2 requested a review from danielchalmers August 1, 2025 18:32
@danielchalmers
Copy link
Member

@gemini-code-assist review

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 refactors the popover positioning logic, especially for lists that need to have their height adjusted to fit on the screen. The changes aim to fix several bugs related to max-height calculation when a popover flips.

Overall, the refactoring in mudPopover.js significantly improves the readability and structure of the height adjustment logic. The introduction of helper variables and functions like isUnset and checkHeight, and the clear separation of logic for upward-flipped and downward-opening popovers, make the code much easier to understand and maintain.

I've found one high-severity logical issue in the new JavaScript implementation that should be addressed, as it prevents the popover from using all available space in certain scenarios. Additionally, I've pointed out a minor typo in the new test component.

Once the identified issue is resolved, this pull request will be a great improvement to the popover's behavior and stability.

Comment on lines +568 to +573
availableHeight = anchorY - overflowPadding - popoverNode.offsetHeight;
shouldClamp = availableHeight < popoverContentNode.offsetHeight;
if (shouldClamp) {
top = overflowPadding;
offsetY = 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There appears to be a logic issue in the calculation of availableHeight when a popover is flipped upwards and needs to be clamped.

When shouldClamp is true for an upward-flipped popover, its top position is correctly reset to overflowPadding, moving it to the top of the viewport. However, availableHeight is not recalculated to account for this new position. It's still based on the original anchorY, which limits the popover's max-height to the space above the anchor, not the full available viewport height.

To fix this, availableHeight should be recalculated after the popover is moved to the top. This will allow the popover to use all the available vertical space as intended.

                            if (shouldClamp) {
                                top = overflowPadding;
                                offsetY = 0;
                                availableHeight = window.innerHeight - top - overflowPadding;
                            }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since shouldClamp is determined by the available height being less than the popover height, not defining available height first would not have the method know if it needs to be clamped. (e.g. would it exceed the screen before the anchor.)

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 4, 2025

@danielchalmers danielchalmers merged commit 1b5ac83 into MudBlazor:dev Aug 4, 2025
6 checks passed
@versile2 versile2 deleted the fix_11730 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.

MudPopover: MudMenu shrinks when no MaxHeight is set.

3 participants