Skip to content

help(MatDatePicker): Implementing range date picker with custom header: problems and suggestions #19589

@ahimik

Description

@ahimik

What are you trying to do?

I am trying to build a date picker with the custom header which includes date presets like 'last month, this month, last 7 days, etc..' and date range selection feature.
I am close to be done there but I had to use several workarounds to bypass the following issues:

  1. I cound't find a way to determine when date range selection is completed via calendar selection. This is important for me to know this since I have two sources of date range changes:
  • custom header when user clicks on date range preset(dates need to be set according to selected preset which causes unwanted (dateChange) event to be fired on date input)
  • regular date range selection using calendar(preset needs to be cleared)

When I use (dateChange) event on matEndDate input like this:

    <mat-date-range-input [rangePicker]="picker">
          <input [(ngModel)]="startDate" matStartDate matInput>
          <input [(ngModel)]="endDate" (dateChange)="handle($event)" matEndDate matInput>
    </mat-date-range-input>

I noticed the following issues:

  • my IDE(IntelliJ 2020.1) complains about (dateChange) event: Event dateChange is not emitted by any applicable directives nor by input element
  • dateChange event gets fired twice during date range selection via calendar: first time with null value and second time with the selected value.

since dateChange gets fired whenever date input changes no matter where this change comes from I wonder if it is possible to have something like this:

       <mat-date-range-picker #picker (dateRangeSelected)="handleDateRangeSelected($event)">
       </mat-date-range-picker>

, where (dateRangeSelected) gets fired when user completes range selection using calendar only?

Currenly I subscribe to calendar.selectedChange event and bypass this event through my custom header to workaround this issue.

  1. I do believe that class MatDateRangePicker must support DateRange selection, but currently it allows only single selection which comes from it's parent class:
/** Selects the given date */
select(date: D): void;
  • Angular: 9.1.9
  • CDK/Material: 10.0.0-rc.1
  • Browser(s): Chrome v83.0.4103.97
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 64bit

Metadata

Metadata

Assignees

Labels

area: material/datepickerneeds: clarificationThe issue does not contain enough information for the team to determine if it is a real bugtroubleshootingThis issue is not reporting an issue, but just asking for help

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions