Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit f61d53e

Browse files
crisbetoThomasBurleson
authored andcommitted
feat(datepicker): add indicator that month headers are clickable
Adds an indicator to the month headers, showing the users that the header is clickable. Fixes #9128. Closes #9142
1 parent 8568cee commit f61d53e

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/components/datepicker/calendar.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ md-calendar {
131131
md-calendar-month &:not(.md-calendar-month-label-disabled) {
132132
cursor: pointer;
133133
}
134+
135+
md-icon {
136+
transform: rotate(180deg);
137+
}
138+
139+
span {
140+
vertical-align: middle;
141+
}
134142
}
135143

136144
// Table containing the day-of-the-week header.

src/components/datepicker/js/calendar.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ describe('md-calendar', function() {
225225
});
226226

227227
var expectedDates = [
228-
['May 2014', '', '', '1', '2', '3'],
228+
['May 2014', '', '1', '2', '3'],
229229
['4', '5', '6', '7', '8', '9', '10'],
230230
['11', '12', '13', '14', '15', '16', '17'],
231231
['18', '19', '20', '21', '22', '23', '24'],
@@ -248,7 +248,7 @@ describe('md-calendar', function() {
248248
});
249249

250250
var expectedDates = [
251-
['May 2014', '', '1', '2', '3', '4'],
251+
['May 2014', '1', '2', '3', '4'],
252252
['5', '6', '7', '8', '9', '10', '11'],
253253
['12', '13', '14', '15', '16', '17', '18'],
254254
['19', '20', '21', '22', '23', '24', '25'],

src/components/datepicker/js/calendarMonthBody.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
* Private directive consumed by md-calendar-month. Having this directive lets the calender use
99
* md-virtual-repeat and also cleanly separates the month DOM construction functions from
1010
* the rest of the calendar controller logic.
11+
* @ngInject
1112
*/
12-
function mdCalendarMonthBodyDirective() {
13+
function mdCalendarMonthBodyDirective($compile, $$mdSvgRegistry) {
14+
var ARROW_ICON = $compile('<md-icon md-svg-src="' +
15+
$$mdSvgRegistry.mdTabsArrow + '"></md-icon>')({})[0];
16+
1317
return {
1418
require: ['^^mdCalendar', '^^mdCalendarMonth', 'mdCalendarMonthBody'],
1519
scope: { offset: '=mdMonthOffset' },
@@ -23,14 +27,15 @@
2327

2428
monthBodyCtrl.calendarCtrl = calendarCtrl;
2529
monthBodyCtrl.monthCtrl = monthCtrl;
30+
monthBodyCtrl.arrowIcon = ARROW_ICON.cloneNode(true);
2631
monthBodyCtrl.generateContent();
2732

2833
// The virtual-repeat re-uses the same DOM elements, so there are only a limited number
29-
// of repeated items that are linked, and then those elements have their bindings updataed.
34+
// of repeated items that are linked, and then those elements have their bindings updated.
3035
// Since the months are not generated by bindings, we simply regenerate the entire thing
3136
// when the binding (offset) changes.
3237
scope.$watch(function() { return monthBodyCtrl.offset; }, function(offset, oldOffset) {
33-
if (offset != oldOffset) {
38+
if (offset !== oldOffset) {
3439
monthBodyCtrl.generateContent();
3540
}
3641
});
@@ -203,7 +208,10 @@
203208
// two cells of the first row.
204209
var blankCellOffset = 0;
205210
var monthLabelCell = document.createElement('td');
206-
monthLabelCell.textContent = this.dateLocale.monthHeaderFormatter(date);
211+
var monthLabelCellContent = document.createElement('span');
212+
213+
monthLabelCellContent.textContent = this.dateLocale.monthHeaderFormatter(date);
214+
monthLabelCell.appendChild(monthLabelCellContent);
207215
monthLabelCell.classList.add('md-calendar-month-label');
208216
// If the entire month is after the max date, render the label as a disabled state.
209217
if (this.calendarCtrl.maxDate && firstDayOfMonth > this.calendarCtrl.maxDate) {
@@ -212,6 +220,7 @@
212220
monthLabelCell.addEventListener('click', this.monthCtrl.headerClickHandler);
213221
monthLabelCell.setAttribute('data-timestamp', firstDayOfMonth.getTime());
214222
monthLabelCell.setAttribute('aria-label', this.dateLocale.monthFormatter(date));
223+
monthLabelCell.appendChild(this.arrowIcon.cloneNode(true));
215224
}
216225

217226
if (firstDayOfTheWeek <= 2) {
@@ -225,8 +234,8 @@
225234
return monthBody;
226235
}
227236
} else {
228-
blankCellOffset = 2;
229-
monthLabelCell.setAttribute('colspan', '2');
237+
blankCellOffset = 3;
238+
monthLabelCell.setAttribute('colspan', '3');
230239
row.appendChild(monthLabelCell);
231240
}
232241

0 commit comments

Comments
 (0)