angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.31k stars 6.72k forks source link

bug(datepicker): Date range picker emit repeated events after the first date is selected #27322

Open robmv opened 1 year ago

robmv commented 1 year ago

Is this a regression?

The previous version in which this bug was not present was

No response

Description

When a date range picker is opened and the start date is selected, two consecutive valueChanges event are triggered, and after the end date is selected the final event is triggered, in total 3 events happens instead of only two.

Reproduction

StackBlitz link: https://stackblitz.com/edit/shrtut? Steps to reproduce:

  1. Click on the mat-datepicker-toggle button.
  2. Select a start date like: 6/18/2023
  3. Notice on the Changes section below that two events were triggered.
  4. Select the end date: 6/24/2023.
  5. A final event in logged on the Changes section.

Expected Behavior

After selecting the first date only a single valueChanges event should be triggered.

The expected behavior is show on the Workaround Changes section where a debounceTime(0) is forced in order to remove the spurious repeated event.

Actual Behavior

Two events are triggered after selecting the start date

Environment

robmv commented 1 year ago

Let me add that if I modify the Moment.js example and log the valueChanges, there are spurious events too if I write 'a', then 'aa' and 'aaa' on the input field, the first one is the change of the value to null, but the other two should not be triggered IMHO because the value hasn't changed, it still is null.

I don't know if it should be interpreted as normal a valueChange event when the value didn't change or if it should be interpreted as a bug. In all ControlValueAccessor I have implemented, no matter what the user interaction with the control, if the result value is the same as the current one, I don't call the onChange callback, so I am inclined to think that it is a bug on the date and date range pickers.