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

Commit 6f64da6

Browse files
committed
fix(calendar): revert removal of workaround for virtual repeat issue
- #8585 turned out to not be a bug - this restored code is not actually a workaround for a bug - but actually part of the implementation needed for `md-calendar` - improve some types and JSDoc Fixes #11919
1 parent 98e259b commit 6f64da6

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/components/datepicker/js/calendar.js

+23-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
angular.module('material.components.datepicker')
3737
.directive('mdCalendar', calendarDirective);
3838

39-
// POST RELEASE
4039
// TODO(jelbourn): Mac Cmd + left / right == Home / End
4140
// TODO(jelbourn): Refactor month element creation to use cloneNode (performance).
4241
// TODO(jelbourn): Define virtual scrolling constants (compactness) users can override.
@@ -52,8 +51,13 @@
5251
function calendarDirective(inputDirective) {
5352
return {
5453
template: function(tElement, tAttr) {
54+
// This allows the calendar to work, without a datepicker. This ensures that the virtual
55+
// repeater scrolls to the proper place on load by deferring the execution until the next
56+
// digest. It's necessary only if the calendar is used without a datepicker, otherwise it's
57+
// already wrapped in an ngIf.
58+
var extraAttrs = tAttr.hasOwnProperty('ngIf') ? '' : 'ng-if="calendarCtrl.isInitialized"';
5559
return '' +
56-
'<div ng-switch="calendarCtrl.currentView">' +
60+
'<div ng-switch="calendarCtrl.currentView" ' + extraAttrs + '>' +
5761
'<md-calendar-year ng-switch-when="year"></md-calendar-year>' +
5862
'<md-calendar-month ng-switch-default></md-calendar-month>' +
5963
'</div>';
@@ -151,7 +155,7 @@
151155
this.today = this.dateUtil.createDateAtMidnight();
152156

153157
/** @type {!ngModel.NgModelController} */
154-
this.ngModelCtrl = null;
158+
this.ngModelCtrl = undefined;
155159

156160
/** @type {string} Class applied to the selected date cell. */
157161
this.SELECTED_DATE_CLASS = 'md-calendar-selected-date';
@@ -162,7 +166,10 @@
162166
/** @type {string} Class applied to the focused cell. */
163167
this.FOCUSED_DATE_CLASS = 'md-focus';
164168

165-
/** @final {number} Unique ID for this calendar instance. */
169+
/**
170+
* @final
171+
* @type {number} Unique ID for this calendar instance.
172+
*/
166173
this.id = nextUniqueId++;
167174

168175
/**
@@ -203,16 +210,22 @@
203210
*/
204211
this.lastRenderableDate = null;
205212

213+
/**
214+
* Used to toggle initialize the root element in the next digest.
215+
* @type {boolean}
216+
*/
217+
this.isInitialized = false;
218+
206219
/**
207220
* Cache for the width of the element without a scrollbar. Used to hide the scrollbar later on
208221
* and to avoid extra reflows when switching between views.
209-
* @type {Number}
222+
* @type {number}
210223
*/
211224
this.width = 0;
212225

213226
/**
214227
* Caches the width of the scrollbar in order to be used when hiding it and to avoid extra reflows.
215-
* @type {Number}
228+
* @type {number}
216229
*/
217230
this.scrollbarWidth = 0;
218231

@@ -335,6 +348,10 @@
335348
self.displayDate = self.selectedDate || self.today;
336349
}
337350
};
351+
352+
self.$mdUtil.nextTick(function() {
353+
self.isInitialized = true;
354+
});
338355
};
339356

340357
/**

src/components/datepicker/js/calendarMonthBody.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
* @ngInject @constructor
4848
*/
4949
function CalendarMonthBodyCtrl($element, $$mdDateUtil, $mdDateLocale) {
50-
/** @final {!angular.JQLite} */
50+
/**
51+
* @final
52+
* @type {!JQLite}
53+
*/
5154
this.$element = $element;
5255

5356
/** @final */
@@ -65,7 +68,7 @@
6568
/**
6669
* Number of months from the start of the month "items" that the currently rendered month
6770
* occurs. Set via angular data binding.
68-
* @type {number}
71+
* @type {number|null}
6972
*/
7073
this.offset = null;
7174

src/components/datepicker/js/calendarYearBody.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
* @ngInject @constructor
3838
*/
3939
function CalendarYearBodyCtrl($element, $$mdDateUtil, $mdDateLocale) {
40-
/** @final {!angular.JQLite} */
40+
/**
41+
* @final
42+
* @type {!JQLite}
43+
*/
4144
this.$element = $element;
4245

4346
/** @final */
@@ -55,7 +58,7 @@
5558
/**
5659
* Number of months from the start of the month "items" that the currently rendered month
5760
* occurs. Set via angular data binding.
58-
* @type {number}
61+
* @type {number|null}
5962
*/
6063
this.offset = null;
6164

0 commit comments

Comments
 (0)