feat(dialog): Support async `MatDialogConfig.closePredicate`
- 主要语言
- TypeScript
- 星标
- 25k
- 派生
- 6.8k
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 91
描述
### Feature Description
For a long time we wanted to be able to cancel dialog closure, in #14292. It was solved via a new option, `closePredicate`, in #14292. But that new option does not support async code. And so we cannot, for example, ask user for the confirmation to close the dialog (via a second dialog), nor do XHR to verify things on server-side.
This kind of use case was already mentioned by @teolag in https://github.com/angular/components/issues/14292#issuecomment-2828734239, but that specific part of the message was left unanswered. And @Nakira had to come up with a custom solution to solve this in https://github.com/angular/components/issues/14292#issuecomment-2907749489
### Use Case
I want the dialog closure to wait until I know whether it can be closed. Possibly via asking the user that he is OK to lose all the data he just input in the dialog, like so:
```ts
this.matDialog.open(MyDialogComponent, {
closePredicate: async () => await askUserIfReallySure(),
});
```
贡献指南
调研方向
从现有的 MatDialogConfig.closePredicate 行为和对话框关闭流程开始;issue 提供了公共选项和异步使用示例。跟踪 predicate 结果的处理方式,然后验证对话框关闭会等待异步确认,并且仍支持取消。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- angular, typescript
- 领域
- frontend
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100