angular / angular/components

bug(cdkMenu): Menu closes unexpectedly after button is clicked and it is destroyed or made disabled

Aperta
#29,420 3 commenti 1 reazione 0 assegnatari Vedi su GitHub
area: cdk/menu P4
Lingua principale
TypeScript
Stelle
25k
Fork
6.8k
Merge medio
1g 8h
PR unite (30g)
91

Descrizione

### 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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con la riproduzione StackBlitz collegata e traccia il comportamento del focus del menu CDK dopo aver fatto clic sul pulsante Refresh. Verifica il caso in cui il pulsante sia disabilitato o rimosso dal DOM, quindi conferma che il menu rimanga aperto senza applicare cdkMenuItem al pulsante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
frontend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.