bug(cdkMenu): Menu closes unexpectedly after button is clicked and it is destroyed or made disabled
- Lenguaje dominante
- TypeScript
- Estrellas
- 25k
- Forks
- 6.8k
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 91
Descripción
### 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
My goal is to implement a button that opens a menu. On this menu there are static elements (texts) and some button.
When button is clicked then button is removed from the DOM (or disabled).
This cannot be implemented using `cdkMenuTriggerFor` and `cdkMenu` because cdkMenu is closed automatically.
### Reproduction
StackBlitz link: https://stackblitz.com/edit/pbb6fn
Steps to reproduce:
1. click on "Click me" to open the menu
2. click on "Refresh" item
PS:
Notice that buttons don't have `cdkMenuItem` directive applied on purpose.
### Expected Behavior
Have ability to stop closing of the menu when button is disabled or button is destroyed (removed from the DOM) after button click.
### Actual Behavior
Menu is closed due to lost focus on the clicked button (I guess).
Same problem occurs if on item click we destroy the button (e.g. using `ngIf="!btnDisabled"`)
### Environment
- Angular: 18.1.0
- CDK/Material: 18.1.0
- Browser(s): Google Chrome 126.0.6478.127
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 11
Guía de contribución
Línea de trabajo
Comienza con la reproducción vinculada de StackBlitz y sigue el comportamiento del foco del menú de CDK después de hacer clic en el botón Refresh. Verifica el caso en el que el botón está deshabilitado o se elimina del DOM y, a continuación, confirma que el menú permanece abierto sin aplicar cdkMenuItem al botón.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- angular, typescript
- Área
- frontend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100