-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(datepicker): notify cva for any input change #13474
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
Conversation
this._valueChange.emit(date); | ||
this.dateInput.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement)); | ||
} | ||
|
||
this._cvaOnChange(date); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to call _cvaOnChange
before emitting. How about doing it like this:
this._value = date;
this._cvaOnChange(date);
if (!this._dateAdapter.sameDate(date, this._value)) {
this._valueChange.emit(date);
this.dateInput.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this won't work. You will end up never calling the dateInput output since this._value will always be value date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yeah you can just move the check before
const shouldEmit = this._dateAdapter.sameDate(date, this._valie);
d26f52c
to
0d4474c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good, but it definitely needs a unit test, otherwise I can see the issue being reintroduced easily by somebody moving the function call a couple of lines down.
@crisbeto I think in order to correctly emit input change events, it needs to keep track of the input value in the component, and emit when that changes. As is, the code will not notify of input changes when the input value changes (i.e. the user types in a value 'bad' 'bad2', the date input event is not fired). As such, I think we should probably do something like: ...
private previousInputValue: string = '';
...
_onInput(value: string): void {
let date = this._dateAdapter.parse(value, this._dateFormats.parse.dateInput);
this._lastValueValid = !date || this._dateAdapter.isValid(date);
date = this._getValidDateOrNull(date);
const previousValue = this._value;
this._value = date;
this._cvaOnChange(date);
if (!this._dateAdapter.sameDate(date, previousValue)) {
this._valueChange.emit(date);
}
if (value !== this.previousInputValue) {
this.previousInputValue = value;
this.dateInput.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement));
}
} The reason we need to maintain a input value model on the class is because Thoughts? |
@alexluecke I do agree with moving the input event outside of that |
@mmalerba the reason I am trying to avoid that is @crisbeto had a specific PR for avoiding that behavior. I actually agree that the input should always emit anytime an input event occurs irrespective of whether or not the input value is actually different. At which time it just seems like we should revert the previous PR changes. |
|
I don't remember whether there was a specific bug, but aside the thing I mention in the PR description, there's also a bug on IE where the |
Could I get some steps to reproduce? |
You can see it by opening this one IE. It'll trigger an |
a9baacd
to
0b1ff90
Compare
@crisbeto That link in the comment to https://docs.microsoft.com/en-us/collaborate/connect-redirect seems to no longer be viable. I updated the PR to always emit events except when the input is not the active document element. |
0b1ff90
to
a0108f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. cc @mmalerba for final approval.
Marking this as |
Hi @alexluecke! This PR has merge conflicts due to recent upstream merges. |
a0108f9
to
5b124bd
Compare
66fe875
to
51f2729
Compare
@mmalerba added a few commits after needing to rebase a conflict. Any idea when this is going to get merged? |
We test all PRs against Google's codebase before merging. It looks like this one has several failures that will need to be investigated before it can be merged |
Closing since the attached issue appears to be fixed and this has not been rebased for a long time. If you find that this is still an issue, please feel free to re-open it with a new pull request |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
fixes #13410