Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(MatDatePicker): Range end date fails to be set correctly when chaning end date value directly from component #19588

Closed
ahimik opened this issue Jun 10, 2020 · 3 comments · Fixed by #19593
Assignees
Labels
area: material/datepicker P2 The issue is important to a large percentage of users, with a workaround

Comments

@ahimik
Copy link

ahimik commented Jun 10, 2020

Reproduction

https://stackblitz.com/edit/angular-9-material-starter-shtplo

Steps to reproduce:

  1. Set up material date picker with range selection feature according to the regular example taken from docs: https://next.material.angular.io/components/datepicker/overview
  2. Bind matStartDate and matEndDate inputs to startDate and endDate component's variables using [(ngModel)]="startDate" and [(ngModel)]="endDate" accordingly.
  3. Change startDate and endDate variables from component to any new values(within one method call).

Steps to reproduce usign provided stackblitz emaple:

  1. Click on a 'change date(bug)' button.
  2. Observe end date has been set correctly to the last day of the current month while endDate component variable's value has been reverted back to the previous(current day) value.

Expected Behavior

What behavior were you expecting to see?

startDate component variable should be set to new value.
endDate component variable should be set to new value.

Actual Behavior

startDate component variable is set correctly.
endDate component variable is reverted back to previously selected value. However matEndDate range input itself shows the correct date value.

Temporal workaround

The workaround is to set timeout for setting end range value:

  changeDateBugWorkAround() {
      const date = new Date();
      this.startDate = new Date(date.getFullYear(), date.getMonth(), 1);
      setTimeout(() => {
        this.endDate = new Date(date.getFullYear(), date.getMonth() + 1, 0);
      }, 1);      
  }

Environment

  • 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
@ahimik ahimik added the needs triage This issue needs to be triaged by the team label Jun 10, 2020
@crisbeto
Copy link
Member

Thank you for the report, this is definitely a bug that we should resolve. One small note on your demo: you shouldn't put matInput on matStartDate and matEndDate, because it's not required and it ends up shifting your start input slightly up.

@crisbeto crisbeto self-assigned this Jun 10, 2020
@crisbeto crisbeto added area: material/datepicker P2 The issue is important to a large percentage of users, with a workaround and removed needs triage This issue needs to be triaged by the team labels Jun 10, 2020
@ahimik
Copy link
Author

ahimik commented Jun 10, 2020

Thanks for the quick reply!

One small note on your demo: you shouldn't put matInput on matStartDate and matEndDate, because it's not required and it ends up shifting your start input slightly up.

I've taken the example from the documentation:
image
, so I hope docs should be updated as well https://next.material.angular.io/components/datepicker/overview

Thanks a lot!

crisbeto added a commit to crisbeto/material2 that referenced this issue Jun 10, 2020
… changed at the same time

The date range picker inputs are set up so that they only respond to events outside of themselves so that we don't trigger duplicate events. In some cases this can be a problem, because the input can end up ignoring its own call to update the CVA value, causing it to be out of sync. These changes add an extra call that ensures that the model and CVA values are always in sync.

Fixes angular#19588.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jun 10, 2020
… changed at the same time

The date range picker inputs are set up so that they only respond to events outside of themselves so that we don't trigger duplicate events. In some cases this can be a problem, because the input can end up ignoring its own call to update the CVA value, causing it to be out of sync. These changes add an extra call that ensures that the model and CVA values are always in sync.

Fixes angular#19588.
mmalerba pushed a commit that referenced this issue Jun 15, 2020
… changed at the same time

The date range picker inputs are set up so that they only respond to events outside of themselves so that we don't trigger duplicate events. In some cases this can be a problem, because the input can end up ignoring its own call to update the CVA value, causing it to be out of sync. These changes add an extra call that ensures that the model and CVA values are always in sync.

Fixes #19588.
mmalerba pushed a commit that referenced this issue Jun 16, 2020
… changed at the same time (#19593)

The date range picker inputs are set up so that they only respond to events outside of themselves so that we don't trigger duplicate events. In some cases this can be a problem, because the input can end up ignoring its own call to update the CVA value, causing it to be out of sync. These changes add an extra call that ensures that the model and CVA values are always in sync.

Fixes #19588.
mmalerba pushed a commit that referenced this issue Jun 16, 2020
… changed at the same time (#19593)

The date range picker inputs are set up so that they only respond to events outside of themselves so that we don't trigger duplicate events. In some cases this can be a problem, because the input can end up ignoring its own call to update the CVA value, causing it to be out of sync. These changes add an extra call that ensures that the model and CVA values are always in sync.

Fixes #19588.
devversion pushed a commit to devversion/material2 that referenced this issue Jun 17, 2020
… changed at the same time (angular#19593)

The date range picker inputs are set up so that they only respond to events outside of themselves so that we don't trigger duplicate events. In some cases this can be a problem, because the input can end up ignoring its own call to update the CVA value, causing it to be out of sync. These changes add an extra call that ensures that the model and CVA values are always in sync.

Fixes angular#19588.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/datepicker P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
2 participants