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

Commit 0e8be31

Browse files
committed
feat(calendar): cleanup and i18n
1 parent a3786ce commit 0e8be31

File tree

9 files changed

+133
-119
lines changed

9 files changed

+133
-119
lines changed

src/components/autocomplete/autocomplete.scss

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,11 @@ md-autocomplete {
9797
}
9898
}
9999
input:not(.md-input) {
100+
@include md-flat-input();
100101
width: 100%;
101-
box-sizing: border-box;
102-
border: none;
103-
box-shadow: none;
104102
padding: 0 15px;
105-
font-size: 14px;
106103
line-height: 40px;
107104
height: 40px;
108-
outline: none;
109-
background: transparent;
110-
&::-ms-clear {
111-
display: none;
112-
}
113105
}
114106
button {
115107
position: relative;

src/components/calendar/calendar-theme.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Theme styles for mdCalendar.
1+
/** Theme styles for mdCalendar. */
22

33
.md-calendar {
44
color: '{{foreground-2}}';
@@ -17,6 +17,8 @@
1717
color: '{{primary-500}}'; // blue-500
1818
}
1919

20+
// The CSS class `md-focus` is used instead of real browser focus for accessibility reasons
21+
// (the root md-calendar holds browser focus).
2022
.md-calendar-date.md-focus {
2123
.md-calendar-date-selection-indicator {
2224
background-color: '{{background-300}}'; // grey-300

src/components/calendar/calendar.js

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
// PRE RELEASE
17-
// TODO(jelbourn): Date "isComplete" logic
17+
// TODO(mchen): Date "isComplete" logic
1818
// TODO(jelbourn): Fix NVDA stealing key presses (IE) ???
1919

2020
// POST RELEASE
@@ -41,10 +41,10 @@
4141
function calendarDirective() {
4242
return {
4343
template:
44-
'<table class="md-calendar-day-header"><thead></thead></table>' +
45-
'<div class="md-calendar-scroll-mask">' +
46-
'<md-virtual-repeat-container class="md-calendar-scroller">' +
47-
'<table role="grid" class="md-calendar">' +
44+
'<table aria-hidden="true" class="md-calendar-day-header"><thead></thead></table>' +
45+
'<div aria-hidden="true" class="md-calendar-scroll-mask">' +
46+
'<md-virtual-repeat-container class="md-calendar-scroll-container">' +
47+
'<table class="md-calendar">' +
4848
'<tbody role="rowgroup" md-virtual-repeat="i in ctrl.items" md-calendar-month ' +
4949
'md-month-offset="$index" class="md-calendar-month" aria-hidden="true" ' +
5050
'md-start-index="ctrl.getSelectedMonthIndex()" ' +
@@ -83,7 +83,10 @@
8383
function CalendarCtrl($element, $attrs, $scope, $animate, $q, $mdConstant,
8484
$$mdDateUtil, $$mdDateLocale, $mdInkRipple, $mdUtil) {
8585

86-
/** @type {Array<number>} Dummy array-like object for virtual-repeat to iterate over. */
86+
/** @type {Array<number>}
87+
* Dummy array-like object for virtual-repeat to iterate over. The length is the total
88+
* number of months that can be viewed.
89+
* */
8790
this.items = {length: 2000};
8891

8992
/** @final {!angular.$animate} */
@@ -192,9 +195,6 @@
192195
};
193196

194197
this.attachCalendarEventListeners();
195-
196-
// DEBUG
197-
window.ctrl = this;
198198
}
199199

200200

@@ -225,14 +225,6 @@
225225
this.isInitialized = true;
226226
};
227227

228-
/**
229-
* Gets the "index" of the currently selected date as it would be in the virtual-repeat.
230-
* @returns {number}
231-
*/
232-
CalendarCtrl.prototype.getSelectedMonthIndex = function() {
233-
return this.dateUtil.getMonthDistance(firstRenderableDate, this.selectedDate || this.today);
234-
};
235-
236228
/**
237229
* Hides the vertical scrollbar on the calendar scroller by setting the width on the
238230
* calendar scroller and the `overflow: hidden` wrapper around the scroller, and then setting
@@ -254,22 +246,8 @@
254246
scroller.style.paddingRight = scrollbarWidth + 'px';
255247
};
256248

257-
/**
258-
* Scrolls to the month of the given date.
259-
* @param {Date} date
260-
*/
261-
CalendarCtrl.prototype.scrollToMonth = function(date) {
262-
if (!this.dateUtil.isValidDate(date)) {
263-
return;
264-
}
265249

266-
var monthDistance = this.dateUtil.getMonthDistance(firstRenderableDate, date);
267-
this.calendarScroller.scrollTop = monthDistance * TBODY_HEIGHT;
268-
};
269-
270-
/**
271-
* Attach event listeners for the calendar.
272-
*/
250+
/** Attach event listeners for the calendar. */
273251
CalendarCtrl.prototype.attachCalendarEventListeners = function() {
274252
// Keyboard interaction.
275253
this.$element.on('keydown', this.handleKeyEvent.bind(this));
@@ -340,6 +318,27 @@
340318
}
341319
};
342320

321+
/**
322+
* Gets the "index" of the currently selected date as it would be in the virtual-repeat.
323+
* @returns {number}
324+
*/
325+
CalendarCtrl.prototype.getSelectedMonthIndex = function() {
326+
return this.dateUtil.getMonthDistance(firstRenderableDate, this.selectedDate || this.today);
327+
};
328+
329+
/**
330+
* Scrolls to the month of the given date.
331+
* @param {Date} date
332+
*/
333+
CalendarCtrl.prototype.scrollToMonth = function(date) {
334+
if (!this.dateUtil.isValidDate(date)) {
335+
return;
336+
}
337+
338+
var monthDistance = this.dateUtil.getMonthDistance(firstRenderableDate, date);
339+
this.calendarScroller.scrollTop = monthDistance * TBODY_HEIGHT;
340+
};
341+
343342
/**
344343
* Sets the ng-model value for the calendar and emits a change event.
345344
* @param {Date} date
@@ -356,6 +355,7 @@
356355
*/
357356
CalendarCtrl.prototype.focus = function(opt_date) {
358357
this.$element[0].focus();
358+
this.announceDisplayDateChange(null, opt_date);
359359

360360
var previousFocus = this.calendarElement.querySelector('.md-focus');
361361
if (previousFocus) {
@@ -372,19 +372,6 @@
372372
}
373373
};
374374

375-
/*** Animation ***/
376-
377-
/**
378-
* Animates the transition from the calendar's current month to the given month.
379-
* @param date
380-
* @returns {angular.$q.Promise} The animation promise.
381-
*/
382-
CalendarCtrl.prototype.animateDateChange = function(date) {
383-
this.scrollToMonth(date);
384-
return this.$q.when();
385-
};
386-
387-
388375
/*** Updating the displayed / selected date ***/
389376

390377
/**
@@ -454,6 +441,16 @@
454441
return animationPromise;
455442
};
456443

444+
/**
445+
* Animates the transition from the calendar's current month to the given month.
446+
* @param {Date} date
447+
* @returns {angular.$q.Promise} The animation promise.
448+
*/
449+
CalendarCtrl.prototype.animateDateChange = function(date) {
450+
this.scrollToMonth(date);
451+
return this.$q.when();
452+
};
453+
457454
/**
458455
* Announces a change in date to the calendar's aria-live region.
459456
* @param {Date} previousDate

src/components/calendar/calendar.scss

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Styles for mdCalendar.
1+
/** Styles for mdCalendar. */
22
$md-calendar-cell-size: 44px !default;
33
$md-calendar-header-height: 40px;
44
$md-calendar-cell-emphasis-size: 40px !default;
@@ -52,44 +52,47 @@ md-calendar {
5252
}
5353

5454
// Wrap the scroll with overflow: hidden in order to hide the scrollbar.
55-
// The inner .md-calendar-scroller will using a padding-right to push the
55+
// The inner .md-calendar-scroll-container will using a padding-right to push the
5656
// scrollbar into the hidden area (done with javascript).
5757
.md-calendar-scroll-mask {
5858
display: inline-block;
5959
overflow: hidden;
6060
height: $md-calendar-weeks-to-show * $md-calendar-cell-size;
6161

62+
// The actual scrolling element.
6263
.md-virtual-repeat-scroller {
64+
// These two properties are needed to get touch momentum to work.
65+
// See https://css-tricks.com/snippets/css/momentum-scrolling-on-ios-overflow-elements
6366
overflow-y: scroll;
6467
-webkit-overflow-scrolling: touch;
68+
69+
&::-webkit-scrollbar {
70+
display: none;
71+
}
6572
}
6673

74+
// Offsetter is the element that is translateY'ed into view of the user and contains the
75+
// calendar content.
6776
.md-virtual-repeat-offsetter {
6877
width: 100%;
6978
}
7079
}
7180

72-
// Scrolling element (the md-virtual-repeat-container).
73-
.md-calendar-scroller {
81+
// Contains the scrolling element (this is the md-virtual-repeat-container).
82+
.md-calendar-scroll-container {
7483
display: inline-block;
7584
height: $md-calendar-weeks-to-show * $md-calendar-cell-size;
7685
width: $md-calendar-width;
77-
78-
&::-webkit-scrollbar {
79-
display: none;
80-
}
8186
}
8287

8388
// A single date cell in the calendar table.
8489
.md-calendar-date {
8590
@include md-calendar-cell();
8691
}
8792

88-
// Element inside of every date cell that can indicate that the date is selected.
93+
// Circle element inside of every date cell used to indicate selection or focus.
8994
.md-calendar-date-selection-indicator {
90-
transition-property: background-color, color;
91-
transition-duration: $swift-ease-out-duration;
92-
transition-timing-function: $swift-ease-out-timing-function;
95+
transition: background-color, color $swift-ease-out-duration $swift-ease-out-timing-function;
9396

9497
border-radius: 50%;
9598
display: inline-block;
@@ -129,7 +132,7 @@ md-calendar {
129132
border-bottom-style: solid;
130133
}
131134

132-
// The divider between months doesn't actualyl change the height of the tbody in which the
135+
// The divider between months doesn't actually change the height of the tbody in which the
133136
// border appear; it changes the height of the following tbody. The causes the first-child to be
134137
// 1px shorter than the other months. We fix this by adding an invisible border-top.
135138
&:first-child {

src/components/calendar/dateLocaleProvider.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@
5656
* @type {function(Date): string}
5757
*/
5858
this.longAnnounceFormatter = null;
59+
60+
/**
61+
* ARIA label for the calendar "dialog" used in the datepicker.
62+
* @type {string}
63+
*/
64+
this.msgCalendar = '';
65+
66+
/**
67+
* ARIA label for the datepicker's "Open calendar" buttons.
68+
* @type {string}
69+
*/
70+
this.msgOpenCalendar = '';
5971
}
6072

6173
/**
@@ -64,7 +76,7 @@
6476
* @param $locale
6577
* @returns {DateLocale}
6678
*/
67-
DateLocaleProvider.prototype.$get = function($locale) {
79+
DateLocaleProvider.prototype.$get = function($locale, $filter) {
6880
/**
6981
* Default date-to-string formatting function.
7082
* @param {!Date} date
@@ -99,7 +111,7 @@
99111
*/
100112
function defaultShortAnnounceFormatter(date) {
101113
// Example: 'Tuesday 12'
102-
return service.days[date.getDay()] + ' ' + service.dates[date.getDate()];
114+
return $filter('date')(date, 'EEEE d');
103115
}
104116

105117
/**
@@ -108,13 +120,8 @@
108120
* @returns {string}
109121
*/
110122
function defaultLongAnnounceFormatter(date) {
111-
// Example: '2015 June Thursday 18'
112-
return [
113-
date.getFullYear(),
114-
service.months[date.getMonth()],
115-
service.days[date.getDay()],
116-
service.dates[date.getDate()]
117-
].join(' ');
123+
// Example: 'Thursday June 18 2015'
124+
return $filter('date')(date, 'fulldate');
118125
}
119126

120127
// The default "short" day strings are the first character of each day,
@@ -129,8 +136,11 @@
129136
defaultDates[i] = i;
130137
}
131138

132-
// TODO(jelbourn): Freeze this object.
133-
var service = {
139+
// Default ARIA messages are in English (US).
140+
var defaultMsgCalendar = 'Calendar';
141+
var defaultMsgOpenCalendar = 'Open calendar';
142+
143+
var service = Object.freeze({
134144
months: this.months || $locale.DATETIME_FORMATS.MONTH,
135145
shortMonths: this.shortMonths || $locale.DATETIME_FORMATS.SHORTMONTH,
136146
days: this.days || $locale.DATETIME_FORMATS.DAY,
@@ -140,8 +150,10 @@
140150
parseDate: this.parseDate || defaultParseDate,
141151
monthHeaderFormatter: this.monthHeaderFormatter || defaultMonthHeaderFormatter,
142152
shortAnnounceFormatter: this.shortAnnounceFormatter || defaultShortAnnounceFormatter,
143-
longAnnounceFormatter: this.longAnnounceFormatter || defaultLongAnnounceFormatter
144-
};
153+
longAnnounceFormatter: this.longAnnounceFormatter || defaultLongAnnounceFormatter,
154+
msgCalendar: this.msgCalendar || defaultMsgCalendar,
155+
msgOpenCalendar: this.msgOpenCalendar || defaultMsgOpenCalendar
156+
});
145157

146158
return service;
147159
};

src/components/calendar/datePicker-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** Theme styles for mdDatepicker. */
2+
13
md-datepicker.md-THEME_NAME-theme {
24
background: white;
35
}

0 commit comments

Comments
 (0)