question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mat menu height gets shrinked when scrolled out of view

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

When an opened menu is scrolled out of the view, and it’s scrolled back to the view, then it should have the original height.

What is the current behavior?

When an opened menu is scrolled out of the view, and it’s scrolled back to the view, then it loses it’s original height and gets shrinked to the height of one menu-item.

What are the steps to reproduce?

  1. Use the mat-menu with reposition scroll strategy (that’s the default)
  2. Open mat-menu
  3. If it’s opened above the menu trigger then scroll down, if it’s opened below then scroll up until you scroll the menu out of the view

Stackblitz example: I used the original mat-menu example from the angular.material.io and just slightly modified the html by adding some extra content to make it scrollable.

Just open the link and see the menu trigger on the middle of the page and do the reproduction steps. Furthermore see the attached gif below.

https://stackblitz.com/edit/angular-rnvofb-2d2zsm?file=src%2Fapp%2Fmenu-overview-example.html

mat menu scrolling issue

What is the use-case or motivation for changing an existing behavior?

To fix the issue mentioned above

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

@angular/material ~8.2.2

Is there anything else we should know?

Tested it in chrome. Possible solution can be: (only checked it in browser console, but it worked) Call the withGrowAfterOpen(true) on the position builder when the related overlay config is retrieved for the overlay. This overlay config instantiated inside the _getOverlayConfig() function in the menu.trigger.ts.

So it would look like this:

private _getOverlayConfig(): OverlayConfig {
    return new OverlayConfig({
      positionStrategy: this._overlay.position()
          .flexibleConnectedTo(this._element)
          .withLockedPosition()
          .withGrowAfterOpen(true) // this is newly added
          .withTransformOriginOn('.mat-menu-panel, .mat-mdc-menu-panel'),
      backdropClass: this.menu.backdropClass || 'cdk-overlay-transparent-backdrop',
      scrollStrategy: this._scrollStrategy(),
      direction: this._dir
    });
  }

My current temporary solution is setting the min height for the connected position overlay element (with class “cdk-overlay-connected-position-bounding-box”) to equal with it’s height after opening, but it’s quite a hack as I get this element from the DOM with getElementsByClassName.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

3reactions
RandomNonameDudecommented, Jan 30, 2020

I also came across this issue and I’d appreciate the fix…

1reaction
fomenkogregorycommented, Nov 2, 2020

Any updates on this one? Or do you guys have found any workarounds? Except of closing it on scroll of course…

For me it worked what I mentioned at the end of my report, see below as well. If you set the min-height for the element equal with it’s height after opening, then it can’t shrink.

My current temporary solution is setting the min height for the connected position overlay element (with class "cdk-overlay-connected-position-bounding-box") to equal with it's height after opening, but it's quite a hack as I get this element from the DOM with getElementsByClassName.

Ty, I have found temporary solution in another issue https://github.com/angular/components/issues/13988. It has done the job for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Customize angular material mat-menu-item to show items ...
Customize angular material mat-menu-item to show items smaller in size (both width and height) Save this question. Show activity on this post.
Read more >
4 Ways to Listen to Page Scrolling for Dynamic UI in Angular ft ...
Using the Event object that is emitted along with the scroll event firing, we can get the scroll position to update our scrollY...
Read more >
Category: HTML, CSS, and Angular Material
I want Angular Material drop-down menu items to go wider before resorting to elipsis. Here is a simplified example. Angular Material cuts off...
Read more >
How to add infinite scroll to Angular material list - Zoaib Khan
Let's use the Angular CDK virtual scroller to add an infinite scroll to Angular. It can make your large lists blazing fast!
Read more >
Prevent Page Scrolling When a Modal is Open | CSS-Tricks
Let's adjust the right padding of the body a bit to avoid that. ... Note that the modal needs to be shorter than...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found