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(mat-datepicker): value change firing on filter re assign #20967

Closed
pgg opened this issue Nov 4, 2020 · 4 comments · Fixed by #20970
Closed

bug(mat-datepicker): value change firing on filter re assign #20967

pgg opened this issue Nov 4, 2020 · 4 comments · Fixed by #20970
Assignees
Labels
area: material/datepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@pgg
Copy link

pgg commented Nov 4, 2020

Reproduction

https://stackblitz.com/edit/angular-ivy-eaktsw?devtoolsheight=33&file=src/app/app.component.ts

Steps to reproduce:
open stackblitz, look at console output, value change triggered incorrectly

Expected Behavior

value change to fire only when value has changed, not when filter changes

Actual Behavior

value change firing for same values

Environment

  • Angular: 10.2.1
  • CDK/Material: 10.2.7
  • Browser(s): Version 86.0.4240.111 (Official Build) (x86_64)
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS
@pgg pgg added the needs triage This issue needs to be triaged by the team label Nov 4, 2020
@crisbeto crisbeto self-assigned this Nov 5, 2020
@crisbeto crisbeto added area: material/datepicker has pr P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Nov 5, 2020
crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 5, 2020
…swapped out if result is the same

Doesn't invoke the `ControlValueAccessor` change function when a new date filter
is assigned, if the result wouldn't have change the validation state.

Fixes angular#20967.
crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 5, 2020
…swapped out if result is the same

Doesn't invoke the `ControlValueAccessor` change function when a new date filter
is assigned, if the result wouldn't have change the validation state.

Fixes angular#20967.
@crisbeto
Copy link
Member

crisbeto commented Nov 5, 2020

We can't do a whole lot here, because we only tell the validator to revalidate and then it determines on its own whether to dispatch the change event. I've submitted #20970 which will prevent the event from firing if a new function with the same result is called, but that won't fix your example, because the validation state changes on each assignment (false -> true -> false).

@pgg
Copy link
Author

pgg commented Nov 5, 2020

still does not make sense that a change event is fired for the same value regardless of validation result? fyi (dateChange) event is not triggered for the same. as a side note: [matDatepickerFilter] does not work with the async pipe: Type '((date: Date | null) => boolean) | null' is not assignable to type 'DateFilterFn<Date | null>'

@crisbeto
Copy link
Member

crisbeto commented Nov 5, 2020

We have control over dateChange so we can dispatch it only when it changes, but the valueChange event is handled by @angular/forms so all we can do is tell it that the validation state has changed and then it decides which events to trigger. You can file an issue on angular/angular if you think the behavior should be changed.

crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 6, 2020
…swapped out if result is the same

Doesn't invoke the `ControlValueAccessor` change function when a new date filter
is assigned, if the result wouldn't have change the validation state.

Fixes angular#20967.
annieyw pushed a commit that referenced this issue Nov 24, 2020
…swapped out if result is the same (#20970)

Doesn't invoke the `ControlValueAccessor` change function when a new date filter
is assigned, if the result wouldn't have change the validation state.

Fixes #20967.
annieyw pushed a commit that referenced this issue Nov 24, 2020
…swapped out if result is the same (#20970)

Doesn't invoke the `ControlValueAccessor` change function when a new date filter
is assigned, if the result wouldn't have change the validation state.

Fixes #20967.

(cherry picked from commit 975fbb3)
@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 Dec 25, 2020
wagnermaciel pushed a commit to wagnermaciel/components that referenced this issue Jan 14, 2021
…swapped out if result is the same (angular#20970)

Doesn't invoke the `ControlValueAccessor` change function when a new date filter
is assigned, if the result wouldn't have change the validation state.

Fixes angular#20967.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/datepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
2 participants