angular / angular/components

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

Open
#20,613 9 comments 9 reactions 0 assignees View on GitHub
area: material/datepicker feature P2
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

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

Contributor guide

Open the contributing guide

Research direction

Start by reading src/material/datepicker/datepicker-base.ts at _openAsDialog and _openAsPopup, then trace MatDatepickerContent and MatDatepickerContentBase. Define the injectable content extension point and verify that a custom component can replace the hardcoded dialog or popup content while retaining datepicker behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.