angular / angular/components

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

Offen
#20,613 9 Kommentare 9 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: material/datepicker feature P2
Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
91

Beschreibung

#### 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)

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit dem Lesen von src/material/datepicker/datepicker-base.ts bei _openAsDialog und _openAsPopup und verfolge dann MatDatepickerContent und MatDatepickerContentBase. Definiere den injizierbaren Erweiterungspunkt für Inhalte und überprüfe, dass eine benutzerdefinierte Komponente den fest codierten Dialog- oder Popup-Inhalt ersetzen kann und dabei das datepicker-Verhalten beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
frontend
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.