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(material/datepicker): There is no way to deselect the selected date(s) while a calendar is open #29877

Open
1 task
pranavirabatti opened this issue Oct 15, 2024 · 1 comment
Labels
area: material/datepicker P2 The issue is important to a large percentage of users, with a workaround

Comments

@pranavirabatti
Copy link

pranavirabatti commented Oct 15, 2024

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

I have a reset button in the date range picker, but when I try to reset the selected dates using the reset button, it resets the models but not the selection in the date range picker widget.

Image

Reproduction

StackBlitz link: https://stackblitz.com/edit/4wfp1v-mbnz3s?file=src%2Fexample%2Fdate-range-picker-overview-example.html

Steps to reproduce:

  1. Open the date range picker widget.
  2. Select a date range.
  3. Click the reset button.
  4. Observe that while the underlying models are reset, the date selection in the date range picker widget remains unchanged.

Expected Behavior

I was expecting the date range picker widget to completely clear the selected dates and reset to its default state when the reset button is clicked, along with resetting the underlying models.

Actual Behavior

The actual behavior is that when the reset button is clicked, the underlying models are reset, but the selected dates in the date range picker widget remain highlighted and do not clear.

Environment

  • Angular: ^19.0.0-next.2
  • CDK/Material: ^19.0.0-next.2
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows and Ubuntu
@pranavirabatti pranavirabatti added the needs triage This issue needs to be triaged by the team label Oct 15, 2024
@wagnermaciel wagnermaciel added P2 The issue is important to a large percentage of users, with a workaround area: material/datepicker and removed needs triage This issue needs to be triaged by the team labels Oct 18, 2024
@wagnermaciel wagnermaciel changed the title Reset Button Not Clearing Date Selection in Date Range Picker Widget bug(material/datepicker): There is no way to deselect the selected date(s) while a calendar is open Oct 18, 2024
@imerljak
Copy link

Did some investigation on this and found the reason why resetting the FormControl won't clear the DatePickerContent.

this._model = portal ? this._globalModel.clone() : this._globalModel;

When DatePickerContent is assigned a TemplatePortal for actions, it clones the model to allow cancelling, otherwise any changes on the input (e.g: selecting a date) will be immediately reflected to the FormControl.

I am not sure how we could fix this without causing more issues since there's no way (other than inspecting the input value for nulls) to determine if we're doing a reset, or assigning a new value, but even that could lead to false positives.

If FormControl would expose an event for when reset() is invoked, we could wire it up.

I am open for suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/datepicker P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

No branches or pull requests

3 participants