diff --git a/packages/input-datepicker/src/LionInputDatepicker.js b/packages/input-datepicker/src/LionInputDatepicker.js index 98dbc49e8..48dbd12a3 100644 --- a/packages/input-datepicker/src/LionInputDatepicker.js +++ b/packages/input-datepicker/src/LionInputDatepicker.js @@ -287,7 +287,11 @@ export class LionInputDatepicker extends OverlayMixin(LionInputDate) { */ _onCalendarOverlayOpened() { if (this._focusCentralDateOnCalendarOpen) { - this._calendarElement.focusCentralDate(); + if (this._calendarElement.selectedDate) { + this._calendarElement.focusSelectedDate(); + } else { + this._calendarElement.focusCentralDate(); + } } } diff --git a/packages/input-datepicker/stories/index.stories.js b/packages/input-datepicker/stories/index.stories.js index 4a7974313..f0b0410a1 100644 --- a/packages/input-datepicker/stories/index.stories.js +++ b/packages/input-datepicker/stories/index.stories.js @@ -7,8 +7,7 @@ storiesOf('Forms|Input Datepicker', module) .add( 'Default', () => html` - - + `, ) .add( diff --git a/packages/input-datepicker/test/lion-input-datepicker.test.js b/packages/input-datepicker/test/lion-input-datepicker.test.js index 070a368a7..956b6621c 100644 --- a/packages/input-datepicker/test/lion-input-datepicker.test.js +++ b/packages/input-datepicker/test/lion-input-datepicker.test.js @@ -188,13 +188,23 @@ describe('', () => { expect(elObj.overlayController.isShown).to.equal(false); }); - it('focuses interactable date on opening of calendar', async () => { + it('focuses selected date on opening of calendar', async () => { + const el = await fixture(html` + + `); + const elObj = new DatepickerInputObject(el); + await elObj.openCalendar(); + await aTimeout(); + expect(isSameDate(elObj.calendarEl.focusedDate, elObj.calendarEl.selectedDate)).to.be.true; + }); + + it('focuses central date on opening of calendar if no date selected', async () => { const el = await fixture(html` `); const elObj = new DatepickerInputObject(el); await elObj.openCalendar(); - expect(elObj.calendarObj.focusedDayObj.el).not.to.equal(null); + expect(isSameDate(elObj.calendarEl.focusedDate, elObj.calendarEl.centralDate)).to.be.true; }); describe('Validators', () => {