angular / angular/components

bug(cdkMenu): cdkMenu is scrolled down when max-height is set

Open
#29,776 1 comment 0 reactions 0 assignees View on GitHub
area: cdk/menu P4
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

### Is this a regression?

- [ ] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

_No response_

### Description

When using max-height on cdkMenu with overflow-y: auto, menu is scrolled down a bit when first shown.
Bad:
![image](https://github.com/user-attachments/assets/de4088d6-9839-4b10-afc6-4c55f287a2a1)
Good:
![image](https://github.com/user-attachments/assets/a72de3ed-76a1-4f4f-b5ea-815fec658a56)

### Reproduction

StackBlitz link: https://stackblitz.com/edit/gbirs4?file=src/example/cdk-menu-standalone-menu-example.html,src/example/cdk-menu-standalone-menu-example.css
Steps to reproduce:
1. Add cdk menu with options with at least one cdkMenuHeaderItem.
2. Set max-height on cdkMenu.
3. Open menu.

### Expected Behavior

Menu should not be scrolled at all.

### Actual Behavior

Menu is scrolled a bit down.

### Environment

- Angular: 18.2.2
- CDK/Material: 18.2.2
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): macOS

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue using the StackBlitz example, starting with src/example/cdk-menu-standalone-menu-example.html and src/example/cdk-menu-standalone-menu-example.css. Check the cdkMenu with a cdkMenuHeaderItem and max-height plus overflow-y: auto; done means the menu opens without any initial scroll offset.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.