Skip to content

Commit

Permalink
fix: prevent input blur on calendar icon click (#3398) (#3400)
Browse files Browse the repository at this point in the history
Co-authored-by: Diego Cardoso <diego@vaadin.com>
  • Loading branch information
web-padawan and DiegoCardoso committed Feb 7, 2022
1 parent c3d67dc commit 6a43be4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/date-picker/src/vaadin-date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ class DatePicker extends DatePickerMixin(
})
);
this.addController(new LabelledInputController(this.inputElement, this._labelController));

const toggleButton = this.shadowRoot.querySelector('[part="toggle-button"]');
toggleButton.addEventListener('mousedown', (e) => e.preventDefault());
}

/** @private */
Expand Down
7 changes: 7 additions & 0 deletions packages/date-picker/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ describe('basic features', () => {
expect(datepicker.hasAttribute('focused')).to.be.true;
});

it('should not blur when toggle button is clicked', async () => {
const e = new CustomEvent('mousedown', { bubbles: true });
const spy = sinon.spy(e, 'preventDefault');
toggleButton.dispatchEvent(e);
expect(spy.calledOnce).to.be.true;
});

it('should have focused attribute when closed and focused', async () => {
datepicker.focus();
await sendKeys({ press: 'ArrowDown' });
Expand Down

0 comments on commit 6a43be4

Please sign in to comment.