Skip to content

Commit c15bad2

Browse files
crisbetojosephperrott
authored andcommittedOct 19, 2018
fix(datepicker): don't allow clicks on disabled cells in year and multi-year views (#13448)
1 parent a7df1d0 commit c15bad2

File tree

4 files changed

+2
-59
lines changed

4 files changed

+2
-59
lines changed
 

‎src/lib/datepicker/calendar-body.spec.ts

-51
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ describe('MatCalendarBody', () => {
1212

1313
// Test components.
1414
StandardCalendarBody,
15-
CalendarBodyWithDisabledCells,
1615
],
1716
});
1817

@@ -101,37 +100,6 @@ describe('MatCalendarBody', () => {
101100
});
102101
});
103102

104-
describe('calendar body with disabled cells', () => {
105-
let fixture: ComponentFixture<CalendarBodyWithDisabledCells>;
106-
let testComponent: CalendarBodyWithDisabledCells;
107-
let calendarBodyNativeElement: Element;
108-
let cellEls: HTMLElement[];
109-
110-
beforeEach(() => {
111-
fixture = TestBed.createComponent(CalendarBodyWithDisabledCells);
112-
fixture.detectChanges();
113-
114-
const calendarBodyDebugElement = fixture.debugElement.query(By.directive(MatCalendarBody));
115-
calendarBodyNativeElement = calendarBodyDebugElement.nativeElement;
116-
testComponent = fixture.componentInstance;
117-
cellEls = Array.from(calendarBodyNativeElement.querySelectorAll('.mat-calendar-body-cell'));
118-
});
119-
120-
it('should only allow selection of disabled cells when allowDisabledSelection is true', () => {
121-
cellEls[0].click();
122-
fixture.detectChanges();
123-
124-
expect(testComponent.selected).toBeFalsy();
125-
126-
testComponent.allowDisabledSelection = true;
127-
fixture.detectChanges();
128-
129-
cellEls[0].click();
130-
fixture.detectChanges();
131-
132-
expect(testComponent.selected).toBe(1);
133-
});
134-
});
135103
});
136104

137105

@@ -160,25 +128,6 @@ class StandardCalendarBody {
160128
}
161129
}
162130

163-
164-
@Component({
165-
template: `<table mat-calendar-body
166-
[rows]="rows"
167-
[allowDisabledSelection]="allowDisabledSelection"
168-
(selectedValueChange)="selected = $event">
169-
</table>`
170-
})
171-
class CalendarBodyWithDisabledCells {
172-
rows = [[1, 2, 3, 4]].map(r => r.map(d => {
173-
let cell = createCell(d);
174-
cell.enabled = d % 2 == 0;
175-
return cell;
176-
}));
177-
allowDisabledSelection = false;
178-
selected: number;
179-
}
180-
181-
182131
function createCell(value: number) {
183132
return new MatCalendarCell(value, `${value}`, `${value}-label`, true);
184133
}

‎src/lib/datepicker/calendar-body.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ export class MatCalendarBody {
6767
/** The number of columns in the table. */
6868
@Input() numCols = 7;
6969

70-
/** Whether to allow selection of disabled cells. */
71-
@Input() allowDisabledSelection = false;
72-
7370
/** The cell number of the active cell in the table. */
7471
@Input() activeCell = 0;
7572

@@ -85,10 +82,9 @@ export class MatCalendarBody {
8582
constructor(private _elementRef: ElementRef<HTMLElement>, private _ngZone: NgZone) { }
8683

8784
_cellClicked(cell: MatCalendarCell): void {
88-
if (!this.allowDisabledSelection && !cell.enabled) {
89-
return;
85+
if (cell.enabled) {
86+
this.selectedValueChange.emit(cell.value);
9087
}
91-
this.selectedValueChange.emit(cell.value);
9288
}
9389

9490
/** The number of blank cells to put at the beginning for the first row. */

‎src/lib/datepicker/multi-year-view.html

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<tr><th class="mat-calendar-table-header-divider" colspan="4"></th></tr>
44
</thead>
55
<tbody mat-calendar-body
6-
allowDisabledSelection="true"
76
[rows]="_years"
87
[todayValue]="_todayYear"
98
[selectedValue]="_selectedYear"

‎src/lib/datepicker/year-view.html

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<tr><th class="mat-calendar-table-header-divider" colspan="4"></th></tr>
44
</thead>
55
<tbody mat-calendar-body
6-
allowDisabledSelection="true"
76
[label]="_yearLabel"
87
[rows]="_months"
98
[todayValue]="_todayMonth"

0 commit comments

Comments
 (0)
Please sign in to comment.