diff --git a/packages/date-picker/src/vaadin-date-picker-mixin.js b/packages/date-picker/src/vaadin-date-picker-mixin.js index b572976a9b..c051c36419 100644 --- a/packages/date-picker/src/vaadin-date-picker-mixin.js +++ b/packages/date-picker/src/vaadin-date-picker-mixin.js @@ -885,7 +885,9 @@ export const DatePickerMixin = (subclass) => /** @protected */ _onOverlayEscapePress() { this._focusedDate = this._selectedDate; + this._closedByEscape = true; this._close(); + this._closedByEscape = false; } /** @protected */ @@ -974,6 +976,9 @@ export const DatePickerMixin = (subclass) => } window.removeEventListener('scroll', this._boundOnScroll, true); + if (this._closedByEscape) { + this._applyInputValue(this._selectedDate); + } this.__commitParsedOrFocusedDate(); if (this._nativeInput && this._nativeInput.selectionStart) { diff --git a/packages/date-picker/test/value-commit.common.js b/packages/date-picker/test/value-commit.common.js index cfd4a2484f..df0cd4b263 100644 --- a/packages/date-picker/test/value-commit.common.js +++ b/packages/date-picker/test/value-commit.common.js @@ -1,5 +1,5 @@ import { expect } from '@esm-bundle/chai'; -import { aTimeout, fixtureSync, nextRender, outsideClick, tap } from '@vaadin/testing-helpers'; +import { fixtureSync, nextRender, outsideClick, tap } from '@vaadin/testing-helpers'; import { sendKeys } from '@web/test-runner-commands'; import sinon from 'sinon'; import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js'; @@ -146,11 +146,11 @@ describe('value commit', () => { expectValueCommit(''); }); - it('should commit on close with Escape', async () => { + it('should revert on close with Escape', async () => { await sendKeys({ press: 'ArrowDown' }); await waitForOverlayRender(); await sendKeys({ press: 'Escape' }); - expectValueCommit(''); + expectNoValueCommit(); }); }); @@ -420,10 +420,10 @@ describe('value commit', () => { expect(datePicker.inputElement.value).to.equal('foo'); }); - it('should commit an empty value on close with Escape', async () => { + it('should revert on close with Escape', async () => { await sendKeys({ press: 'Escape' }); - expectValueCommit(''); - expect(datePicker.inputElement.value).to.equal('foo'); + expectNoValueCommit(); + expect(datePicker.inputElement.value).to.equal(initialInputElementValue); }); }); });