Skip to content

Commit

Permalink
fix: do not prevent touchend for clear button
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Oct 14, 2019
1 parent 0255184 commit 855b252
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/vaadin-date-picker-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,31 @@
this._boundFocus = this._focus.bind(this);
this._boundUpdateAlignmentAndPosition = this._updateAlignmentAndPosition.bind(this);

const isClearButton = e => {
const path = e.composedPath();
const inputIndex = path.indexOf(this._inputElement);
return path.slice(0, inputIndex)
.filter(el => el.getAttribute && el.getAttribute('part') === 'clear-button')
.length === 1;
};

Polymer.Gestures.addListener(this, 'tap', e => {
// FIXME(platosha): use preventDefault in the text field clear button,
// then the following composedPath check could be simplified down
// to `if (!e.defaultPrevented)`.
// https://github.com/vaadin/vaadin-text-field/issues/352
const inputIndex = e.composedPath().indexOf(this._inputElement);
if (
e.composedPath().slice(0, inputIndex)
.filter(el => el.getAttribute && el.getAttribute('part') === 'clear-button')
.length === 0
) {
this.open();
} else {
if (isClearButton(e)) {
this.validate();
} else {
this.open();
}
});

this.addEventListener('touchend', this._preventDefault.bind(this));
this.addEventListener('touchend', e => {
if (!isClearButton(e)) {
e.preventDefault();
}
});
this.addEventListener('keydown', this._onKeydown.bind(this));
this.addEventListener('input', this._onUserInput.bind(this));
this.addEventListener('focus', e => this._noInput && e.target.blur());
Expand Down
7 changes: 7 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,13 @@
expect(datepicker.value).to.equal('');
});

it('should not prevent touchend event on clear button', () => {
datepicker.value = '2000-02-01';
const e = new CustomEvent('touchend', {cancelable: true});
clearButton.dispatchEvent(e);
expect(e.defaultPrevented).to.be.false;
});

it('should validate on clear', () => {
datepicker.required = true;
datepicker.value = '1991-20-12';
Expand Down

0 comments on commit 855b252

Please sign in to comment.