angular / angular/components

feat(dialog): Support async `MatDialogConfig.closePredicate`

Ouverte
#32,142 1 commentaire 5 réactions 0 personnes assignées Voir sur GitHub
area: material/dialog feature P3
Langage dominant
TypeScript
Étoiles
25k
Forks
6.8k
Merge moyen
1 j 8 h
PR mergées (30 j)
91

Description

### 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(),
});
```

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par le comportement existant de MatDialogConfig.closePredicate et le flux de fermeture de la boîte de dialogue ; l’issue fournit l’option publique et un exemple d’utilisation asynchrone. Suivez la manière dont le résultat du prédicat est traité, puis vérifiez que la fermeture de la boîte de dialogue attend une confirmation asynchrone tout en prenant toujours en charge l’annulation.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
angular, typescript
Domaine
frontend
Type d'issue
Fonctionnalité
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
52/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.