angular / angular/components

feat(MatDateRangePicker): add ability to use a custom component inside a dialog/popup

Aperta
#20,613 9 commenti 9 reazioni 0 assegnatari Vedi su GitHub
area: material/datepicker feature P2
Lingua principale
TypeScript
Stelle
25k
Fork
6.8k
Merge medio
1g 8h
PR unite (30g)
91

Descrizione

#### Feature Description

At the moment, the component that is used by the [`MatDatepickerBase._openAsDialog`](https://github.com/angular/components/blob/dfdf5cf7574a201b98b7e35ce770984527c790ee/src/material/datepicker/datepicker-base.ts#L500) and [`MatDatepickerBase._openAsPopup`](https://github.com/angular/components/blob/dfdf5cf7574a201b98b7e35ce770984527c790ee/src/material/datepicker/datepicker-base.ts#L542) methods is hardcoded. And you can't extend those because they are private.

If, instead, `MatDatepickerContent` was injected, we would have the ability to provide a component with extended functionality, e.g. with predefined date ranges. So, in the `MatDatepickerBase` we should have something like that:
```ts
constructor(
// ...
@Inject(MAT_DATEPICKER_CONTENT) private datepickerContent: MatDatepickerContentBase,
) {
// ...
}

// ...

private _openAsDialog(): void {
// ...
this._dialogRef = this._dialog.open>(this.datepickerContent, /* ... */);
// ...
}
```

We can then import `MatDatepickerContentBase`, extend it and provide our own component to be used in a dialog or popup.

#### Use Case

Add predefined ranges, use two calendars instead of one, add buttons etc.
For example, check the [ngx-daterangepicker-material](https://www.npmjs.com/package/ngx-daterangepicker-material) package:
![image](https://user-images.githubusercontent.com/21097952/93769328-4f237480-fc23-11ea-9160-8cf8081bfdbd.png)

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia leggendo src/material/datepicker/datepicker-base.ts in _openAsDialog e _openAsPopup, quindi segui MatDatepickerContent e MatDatepickerContentBase. Definisci il punto di estensione del contenuto iniettabile e verifica che un componente personalizzato possa sostituire il contenuto hardcoded della finestra di dialogo o del popup mantenendo il comportamento del datepicker.

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

Valutazione

Stack tecnologico
angular, typescript
Ambito
frontend
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 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.