Skip to content

Commit a7c902d

Browse files
author
Matt Lewis
committed
fix(monthView): preserve classes when removing a days cssClass
Closes #210
1 parent 36346a8 commit a7c902d

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/components/month/calendarMonthCell.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { MonthViewDay, CalendarEvent } from 'calendar-utils';
4040
</ng-template>
4141
`,
4242
host: {
43-
'[class]': '"cal-cell cal-day-cell " + day?.cssClass',
43+
'class': 'cal-cell cal-day-cell',
4444
'[class.cal-past]': 'day.isPast',
4545
'[class.cal-today]': 'day.isToday',
4646
'[class.cal-future]': 'day.isFuture',

src/components/month/calendarMonthView.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { CalendarUtils } from '../../providers/calendarUtils.provider';
5656
<mwl-calendar-month-cell
5757
*ngFor="let day of view.days | slice : rowIndex : rowIndex + (view.totalDaysVisibleInWeek)"
5858
[class.cal-drag-over]="day.dragOver"
59+
[ngClass]="day?.cssClass"
5960
[day]="day"
6061
[openDay]="openDay"
6162
[locale]="locale"

test/calendarMonthView.component.spec.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
CalendarMomentDateFormatter,
1414
CalendarDateFormatter,
1515
CalendarModule,
16-
MOMENT
16+
MOMENT,
17+
CalendarMonthViewDay
1718
} from './../src';
1819
import { CalendarMonthViewComponent } from './../src/components/month/calendarMonthView.component';
1920
import { Subject } from 'rxjs/Subject';
@@ -127,6 +128,28 @@ describe('calendarMonthView component', () => {
127128
fixture.destroy();
128129
});
129130

131+
it('should not remove other classes when removing the cssClass', () => {
132+
const fixture: ComponentFixture<CalendarMonthViewComponent> = TestBed.createComponent(CalendarMonthViewComponent);
133+
fixture.componentInstance.viewDate = new Date('2016-06-27');
134+
let firstDay: CalendarMonthViewDay;
135+
fixture.componentInstance.dayModifier = (day) => {
136+
if (!firstDay) {
137+
firstDay = day;
138+
day.cssClass = 'foo';
139+
}
140+
};
141+
fixture.componentInstance.ngOnChanges({viewDate: {}, events: {}});
142+
fixture.detectChanges();
143+
const cell: HTMLElement = fixture.nativeElement.querySelector('.cal-days .cal-cell');
144+
expect(cell.classList.contains('foo')).to.equal(true);
145+
expect(cell.classList.contains('cal-out-month')).to.equal(true);
146+
delete firstDay.cssClass;
147+
fixture.detectChanges();
148+
expect(cell.classList.contains('foo')).to.equal(false);
149+
expect(cell.classList.contains('cal-out-month')).to.equal(true);
150+
fixture.destroy();
151+
});
152+
130153
it('should add the highlight class to events on mouse over', () => {
131154
const fixture: ComponentFixture<CalendarMonthViewComponent> = TestBed.createComponent(CalendarMonthViewComponent);
132155
fixture.componentInstance.viewDate = new Date('2016-06-27');

0 commit comments

Comments
 (0)