bug(cdkMenu): Menu closes unexpectedly after button is clicked and it is destroyed or made disabled
- 主要言語
- TypeScript
- スター
- 25k
- フォーク
- 6.8k
- 平均マージ
- 1日 8時間
- マージ済み PR(30日)
- 91
説明
### 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
コントリビューションガイド
調査の方向性
リンクされた StackBlitz の再現から始め、Refresh ボタンをクリックした後の CDK メニューのフォーカス動作を追跡します。ボタンが無効化されている、または DOM から削除されているケースを確認し、その後、ボタンに cdkMenuItem を適用せずにメニューが開いたままになることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- angular, typescript
- 領域
- frontend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100