Skip to content

Commit 1643379

Browse files
author
Mikhail Bashkirov
committed
fix(calendar): init centralDate from selectedDate when today is disabled
1 parent a9bda5a commit 1643379

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/calendar/src/LionCalendar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ export class LionCalendar extends LocalizeMixin(LitElement) {
374374
}
375375

376376
__disableDatesChanged() {
377-
this.__ensureValidCentralDate();
377+
if (this.__connectedCallbackDone) {
378+
this.__ensureValidCentralDate();
379+
}
378380
}
379381

380382
__dateSelectedByUser(selectedDate) {

packages/calendar/test/lion-calendar.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,22 @@ describe('<lion-calendar>', () => {
306306
expect(new DayObject(d).isDisabled).to.equal(shouldBeDisabled);
307307
});
308308
});
309+
310+
it('does not prevent initializing "centralDate" from "selectedDate" when today is disabled', async () => {
311+
const clock = sinon.useFakeTimers({ now: new Date('2019/06/03').getTime() });
312+
313+
const el = await fixture(html`
314+
<lion-calendar
315+
.selectedDate="${new Date('2001/01/08')}"
316+
.disableDates=${day => day.getDate() === 3}
317+
></lion-calendar>
318+
`);
319+
const elObj = new CalendarObject(el);
320+
expect(isSameDate(el.centralDate, new Date('2001/01/08'))).to.be.true;
321+
expect(elObj.activeMonthAndYear).to.equal('January 2001');
322+
323+
clock.restore();
324+
});
309325
});
310326
});
311327

0 commit comments

Comments
 (0)