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

fix(calendar): revert removal of workaround for virtual repeat issue #11939

Merged
merged 1 commit into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/components/datepicker/js/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
angular.module('material.components.datepicker')
.directive('mdCalendar', calendarDirective);

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

/** @type {!ngModel.NgModelController} */
this.ngModelCtrl = null;
this.ngModelCtrl = undefined;

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

/** @final {number} Unique ID for this calendar instance. */
/**
* @final
* @type {number} Unique ID for this calendar instance.
*/
this.id = nextUniqueId++;

/**
Expand Down Expand Up @@ -203,16 +210,22 @@
*/
this.lastRenderableDate = null;

/**
* Used to toggle initialize the root element in the next digest.
* @type {boolean}
*/
this.isInitialized = false;

/**
* Cache for the width of the element without a scrollbar. Used to hide the scrollbar later on
* and to avoid extra reflows when switching between views.
* @type {Number}
* @type {number}
*/
this.width = 0;

/**
* Caches the width of the scrollbar in order to be used when hiding it and to avoid extra reflows.
* @type {Number}
* @type {number}
*/
this.scrollbarWidth = 0;

Expand Down Expand Up @@ -335,6 +348,10 @@
self.displayDate = self.selectedDate || self.today;
}
};

self.$mdUtil.nextTick(function() {
self.isInitialized = true;
});
};

/**
Expand Down
7 changes: 5 additions & 2 deletions src/components/datepicker/js/calendarMonthBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
* @ngInject @constructor
*/
function CalendarMonthBodyCtrl($element, $$mdDateUtil, $mdDateLocale) {
/** @final {!angular.JQLite} */
/**
* @final
* @type {!JQLite}
*/
this.$element = $element;

/** @final */
Expand All @@ -65,7 +68,7 @@
/**
* Number of months from the start of the month "items" that the currently rendered month
* occurs. Set via angular data binding.
* @type {number}
* @type {number|null}
*/
this.offset = null;

Expand Down
7 changes: 5 additions & 2 deletions src/components/datepicker/js/calendarYearBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
* @ngInject @constructor
*/
function CalendarYearBodyCtrl($element, $$mdDateUtil, $mdDateLocale) {
/** @final {!angular.JQLite} */
/**
* @final
* @type {!JQLite}
*/
this.$element = $element;

/** @final */
Expand All @@ -55,7 +58,7 @@
/**
* Number of months from the start of the month "items" that the currently rendered month
* occurs. Set via angular data binding.
* @type {number}
* @type {number|null}
*/
this.offset = null;

Expand Down