Skip to content

Commit

Permalink
fix: revert input on overlay close by escape (#7293) (#7308)
Browse files Browse the repository at this point in the history
Co-authored-by: Ugur Saglam <106508695+ugur-vaadin@users.noreply.github.com>
  • Loading branch information
vaadin-bot and ugur-vaadin authored Apr 9, 2024
1 parent 0e465e8 commit 6de801a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/date-picker/src/vaadin-date-picker-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,9 @@ export const DatePickerMixin = (subclass) =>
/** @protected */
_onOverlayEscapePress() {
this._focusedDate = this._selectedDate;
this._closedByEscape = true;
this._close();
this._closedByEscape = false;
}

/** @protected */
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions packages/date-picker/test/value-commit.common.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
});
});

Expand Down Expand Up @@ -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);
});
});
});
Expand Down

0 comments on commit 6de801a

Please sign in to comment.