feat(dialog): Support async `MatDialogConfig.closePredicate`
- Linguagem predominante
- TypeScript
- Estrelas
- 25k
- Forks
- 6.8k
- Merge médio
- 1d 8h
- PRs com merge (30d)
- 91
Descrição
### 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(),
});
```
Guia de contribuição
Direção de pesquisa
Comece pelo comportamento existente de MatDialogConfig.closePredicate e pelo fluxo de fechamento do diálogo; a issue fornece a opção pública e um exemplo de uso assíncrono. Rastreie como o resultado do predicado é tratado e, em seguida, verifique se o fechamento do diálogo aguarda uma confirmação assíncrona e continua oferecendo suporte ao cancelamento.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- angular, typescript
- Domínio
- frontend
- Tipo de issue
- Funcionalidade
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Pouca atividade
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 52/100