[date-picker] Invalid input does not clear on esc if value is selected
Description
If you type an invalid value to a date picker input and hit Esc, the value clears:
https://user-images.githubusercontent.com/1222264/184605819-e0965a18-02a2-40f6-8695-cc5d82e0f1a3.mp4
If the date picker has a value beforehand, the behavior is different on Esc: the field is marked invalid and the value is not cleared (even if clearButtonVisible is enabled):
https://user-images.githubusercontent.com/1222264/184606059-d150e602-2d03-4760-9604-d76abbf5dc41.mp4
Expected outcome
The behavior should be the same in both cases
Minimal reproducible example
<vaadin-date-picker></vaadin-date-picker>
Steps to reproduce
- Pick a value
- Type an invalid input value
- Press Esc
Environment
Not related to run environment
Browsers
Issue is not browser related
@vursen , has the behavior changed with the validation refactoring?
@vursen , has the behavior changed with the validation refactoring?
No, this issue has been outside the scope of the refactoring.
Regarding clearButtonVisible - this property isn't taken into account on Esc when date-picker overlay is opened.
There is even a test that checks for reverting value (rather than clearing it) with clearButtonVisible set to true:
https://github.com/vaadin/web-components/blob/d12e573af6fb4167bf5886371038fec0d3267c3c/packages/date-picker/test/events.common.js#L110
However, this is also how e.g. vaadin-combo-box and vaadin-time-picker work: Esc when opened is used to revert input value to value when opened and clear button is visible. So not clearing the old value seems to work as intended.
I will investigate further how to discard user input properly. Tried this._applyInputValue(this._selectedDate); but there are some tests in the value-commit suite that fail with this approach, especially clearing value and closing with Esc.