fix(datepicker): focus on selected date on opening
This commit is contained in:
parent
d66a90566c
commit
d29d9db754
3 changed files with 18 additions and 5 deletions
|
|
@ -287,7 +287,11 @@ export class LionInputDatepicker extends OverlayMixin(LionInputDate) {
|
||||||
*/
|
*/
|
||||||
_onCalendarOverlayOpened() {
|
_onCalendarOverlayOpened() {
|
||||||
if (this._focusCentralDateOnCalendarOpen) {
|
if (this._focusCentralDateOnCalendarOpen) {
|
||||||
this._calendarElement.focusCentralDate();
|
if (this._calendarElement.selectedDate) {
|
||||||
|
this._calendarElement.focusSelectedDate();
|
||||||
|
} else {
|
||||||
|
this._calendarElement.focusCentralDate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@ storiesOf('Forms|Input Datepicker', module)
|
||||||
.add(
|
.add(
|
||||||
'Default',
|
'Default',
|
||||||
() => html`
|
() => html`
|
||||||
<lion-input-datepicker label="Date" .modelValue=${new Date('2017/06/15')}>
|
<lion-input-datepicker label="Date"> </lion-input-datepicker>
|
||||||
</lion-input-datepicker>
|
|
||||||
`,
|
`,
|
||||||
)
|
)
|
||||||
.add(
|
.add(
|
||||||
|
|
|
||||||
|
|
@ -188,13 +188,23 @@ describe('<lion-input-datepicker>', () => {
|
||||||
expect(elObj.overlayController.isShown).to.equal(false);
|
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`
|
||||||
|
<lion-input-datepicker .modelValue="${new Date()}"></lion-input-datepicker>
|
||||||
|
`);
|
||||||
|
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 el = await fixture(html`
|
||||||
<lion-input-datepicker></lion-input-datepicker>
|
<lion-input-datepicker></lion-input-datepicker>
|
||||||
`);
|
`);
|
||||||
const elObj = new DatepickerInputObject(el);
|
const elObj = new DatepickerInputObject(el);
|
||||||
await elObj.openCalendar();
|
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', () => {
|
describe('Validators', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue