Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: commit focused date on outside click #5670

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/date-picker/src/vaadin-date-picker-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,10 @@ export const DatePickerMixin = (subclass) =>
this._close();
});

// User confirmed selected date by pressing Enter or Today.
// User confirmed selected date by pressing Enter, Space, or Today.
content.addEventListener('date-selected', (e) => {
this.__userConfirmedDate = true;
// Reset if a date is deselected.
this.__userConfirmedDate = !!e.detail.date;

this._selectDate(e.detail.date);
});
Expand Down
26 changes: 26 additions & 0 deletions packages/date-picker/test/dropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,32 @@ describe('dropdown', () => {
await aTimeout(0);
expect(datePicker.hasAttribute('focus-ring')).to.be.false;
});

it('should commit focused date on outside click', async () => {
datePicker.value = '2001-02-13';
vursen marked this conversation as resolved.
Show resolved Hide resolved
await open(datePicker);
// Move focus to the calendar
await sendKeys({ press: 'Tab' });
// Navigate to another date
await sendKeys({ press: 'ArrowDown' });
outsideClick();
await aTimeout(0);
expect(datePicker.value).to.equal('2001-02-20');
vursen marked this conversation as resolved.
Show resolved Hide resolved
});

it('should commit focused date on outside click after deselecting', async () => {
datePicker.value = '2001-02-13';
await open(datePicker);
// Move focus to the calendar
await sendKeys({ press: 'Tab' });
// De-select the selected date
await sendKeys({ press: 'Space' });
// Navigate to another date
await sendKeys({ press: 'ArrowDown' });
outsideClick();
await aTimeout(0);
expect(datePicker.value).to.equal('2001-02-20');
});
});

describe('date tap', () => {
Expand Down