-
Notifications
You must be signed in to change notification settings - Fork 82
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
refactor: handle user-selected date properly #3530
Conversation
Kudos, SonarCloud Quality Gate passed!
|
Would either of these (presumably smaller changes) work:
__onValueChangedEvent() {
if (this.__dispatchChange) {
this.dispatchEvent(new CustomEvent('change', { bubbles: true }));
this.__dispatchChange = false;
}
}
_valueChanged(value, oldValue) {
if (this.__dispatchChange) {
queueMicrotask(() => {
this.dispatchEvent(new CustomEvent('change', { bubbles: true }));
});
this.__dispatchChange = false;
}
this._handleDateChange('_selectedDate', value, oldValue);
this._toggleHasValue(!!value);
} |
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.
Well, this approach is still cleaner since it eliminates the hacky __userInputOccurred
flag
I wanted to avoid microtask timings because it's not how our Polymer based components work in general. |
Hi @web-padawan , this commit cannot be picked to 22.0 by this bot, can you take a look and pick it manually? |
This ticket/PR has been released with Vaadin 23.0.2. |
This ticket/PR has been released with Vaadin 23.1.0.alpha1 and is also targeting the upcoming stable 23.1.0 version. |
Description
This PR updates the date-picker logic in preparation for fixing events being fired in the wrong order.
Related to #3379
Problem
There are two different ways of how
vaadin-date-picker
value can be updated:value
property with JS,In the first case,
value
is set and then internal_selectedDate
property is updated accordingly. This works fine.In the second case,
_selectedDate
is set first, thenvalue
is updated and then_selectedDate
is set again:web-components/packages/date-picker/src/vaadin-date-picker-mixin.js
Line 672 in 4be73e8
This part of logic is problematic because of how internal flags are used. Currently, there are two of them:
__userInputOccured
- set when_focusedDate
changes (cover changing date in the overlay month calendar),__dispatchChange
- set inside the_selectedDateChanged
observer if__userInputOccured
is set totrue
.The actual problem with the current implementation is how these flags are reset in the second observer run.
change
event inside of the_valueChaned
observer, the flag is still there.change
event tovalue-changed
event listener, by that time the flag is already removed.This is understandable because Polymer runs
notify
events after the property observers.Solution
_selectedDate
property to use one-way data flow instead._selectDate
method to be called on user interactions only (e.g. selecting date with mouse or keyboard).__dispatchChange
flag to_selectDate
method to not modify it in_selectedDateChanged
.date-selected
event to be used for keys, similarly to howdate-tap
is used for mouse clicks.These changes would make it easier to move the logic for
change
event (will be done in a separate PR).Type of change