Skip to content

Commit

Permalink
Fix invalid input on enter behaviour (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nii Yeboah authored and tomivirkki committed Mar 13, 2019
1 parent a30c31e commit 7da3791
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/vaadin-date-picker-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -777,12 +777,17 @@
}

break;
case 'enter':
if (this._overlayContent.focusedDate) {
case 'enter': {
const dateObject = this.i18n.parseDate(this._inputValue);
const parsedDate = dateObject &&
this._parseDate(dateObject.year + '-' + (dateObject.month + 1) + '-' + dateObject.day);

if (this._overlayContent.focusedDate && this._isValidDate(parsedDate)) {
this._selectedDate = this._overlayContent.focusedDate;
}
this.close();
break;
}
case 'esc':
this._focusedDate = this._selectedDate;
this._close();
Expand Down
13 changes: 13 additions & 0 deletions test/keyboard-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@
enter();
});

it('should not select a date on enter if input invalid', done => {
open(datepicker, () => {
inputText('foo');
enter();
});
datepicker.$.overlay.addEventListener('vaadin-overlay-close', () => {
expect(datepicker.invalid).to.be.true;
expect(datepicker.value).to.equal('');
expect(target.value).to.equal('foo');
done();
});
});

it('should display focused date while overlay focused', () => {
inputText('1/2/2000');
arrowDown();
Expand Down

0 comments on commit 7da3791

Please sign in to comment.