Merge pull request #1142 from jorgecasar/fix/calendar-previous-mext-month
fix(calendar): solve previousMonth and nextMonth conditions error
This commit is contained in:
commit
cf4848c53d
3 changed files with 41 additions and 4 deletions
5
.changeset/curly-ladybugs-grab.md
Normal file
5
.changeset/curly-ladybugs-grab.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@lion/calendar': patch
|
||||
---
|
||||
|
||||
solve previousMonth and nextMonth conditions error
|
||||
|
|
@ -515,9 +515,12 @@ export class LionCalendar extends LocalizeMixin(LitElement) {
|
|||
const day = createDay(new Date(_day.date), _day);
|
||||
const today = normalizeDateTime(new Date());
|
||||
day.central = isSameDate(day.date, this.centralDate);
|
||||
day.previousMonth = currentMonth && day.date.getMonth() < currentMonth.getMonth();
|
||||
day.currentMonth = currentMonth && day.date.getMonth() === currentMonth.getMonth();
|
||||
day.nextMonth = currentMonth && day.date.getMonth() > currentMonth.getMonth();
|
||||
const dayYearMonth = `${day.date.getFullYear()}${`0${day.date.getMonth() + 1}`.slice(-2)}`;
|
||||
const currentYearMonth =
|
||||
currentMonth && `${currentMonth.getFullYear()}${`0${currentMonth.getMonth() + 1}`.slice(-2)}`;
|
||||
day.previousMonth = currentMonth && dayYearMonth < currentYearMonth;
|
||||
day.currentMonth = currentMonth && dayYearMonth === currentYearMonth;
|
||||
day.nextMonth = currentMonth && dayYearMonth > currentYearMonth;
|
||||
day.selected = this.selectedDate ? isSameDate(day.date, this.selectedDate) : false;
|
||||
day.past = day.date < today;
|
||||
day.today = isSameDate(day.date, today);
|
||||
|
|
|
|||
|
|
@ -1206,7 +1206,6 @@ describe('<lion-calendar>', () => {
|
|||
`),
|
||||
);
|
||||
const { previousMonthDayObjs, nextMonthDayObjs } = elObj;
|
||||
|
||||
expect(previousMonthDayObjs.length).to.equal(3);
|
||||
expect(previousMonthDayObjs[0].cellIndex).to.equal(0);
|
||||
expect(previousMonthDayObjs[0].monthday).to.equal(29);
|
||||
|
|
@ -1222,6 +1221,36 @@ describe('<lion-calendar>', () => {
|
|||
expect(nextMonthDayObjs[1].monthday).to.equal(2);
|
||||
});
|
||||
|
||||
it('renders days for next months in the last month of the year', async () => {
|
||||
const elObj = new CalendarObject(
|
||||
await fixture(html`
|
||||
<lion-calendar .selectedDate="${new Date('2020/12/12')}"></lion-calendar>
|
||||
`),
|
||||
);
|
||||
const { nextMonthDayObjs } = elObj;
|
||||
expect(nextMonthDayObjs.length).to.equal(2);
|
||||
expect(nextMonthDayObjs[0].cellIndex).to.equal(5);
|
||||
expect(nextMonthDayObjs[0].monthday).to.equal(1);
|
||||
expect(nextMonthDayObjs[1].cellIndex).to.equal(6);
|
||||
expect(nextMonthDayObjs[1].monthday).to.equal(2);
|
||||
});
|
||||
|
||||
it('renders days for previous months in the first month of the year', async () => {
|
||||
const elObj = new CalendarObject(
|
||||
await fixture(html`
|
||||
<lion-calendar .selectedDate="${new Date('2020/01/12')}"></lion-calendar>
|
||||
`),
|
||||
);
|
||||
const { previousMonthDayObjs } = elObj;
|
||||
expect(previousMonthDayObjs.length).to.equal(3);
|
||||
expect(previousMonthDayObjs[0].cellIndex).to.equal(0);
|
||||
expect(previousMonthDayObjs[0].monthday).to.equal(29);
|
||||
expect(previousMonthDayObjs[1].cellIndex).to.equal(1);
|
||||
expect(previousMonthDayObjs[1].monthday).to.equal(30);
|
||||
expect(previousMonthDayObjs[2].cellIndex).to.equal(2);
|
||||
expect(previousMonthDayObjs[2].monthday).to.equal(31);
|
||||
});
|
||||
|
||||
it('sets aria-current="date" to todays button', async () => {
|
||||
const elObj = new CalendarObject(await fixture(html`<lion-calendar></lion-calendar>`));
|
||||
const hasAriaCurrent = /** @param {DayObject} d */ d =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue