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

Commit 412bc2c

Browse files
crisbetojelbourn
authored andcommitted
fix(datepicker): jumping forward if min date is in the same month as model (#9305)
Fixes the datepicker jumping forward if the current month is also the first one being rendered (e.g. when the min date is in the same month as the model). This was caused by an extra unnecessary call to `generateContent` which made the first month in the calendar to be re-rendered at the bottom after the user has scrolled past it. When the first month is at the bottom, the calendar tries to focus the active date, causing the browser to scroll to the bottom. Afterward the virtual repeater updates the view again, which makes the calendar skip a few months. Fixes #9284.
1 parent 6cfb542 commit 412bc2c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/components/datepicker/js/calendarMonthBody.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
monthBodyCtrl.calendarCtrl = calendarCtrl;
2929
monthBodyCtrl.monthCtrl = monthCtrl;
3030
monthBodyCtrl.arrowIcon = ARROW_ICON.cloneNode(true);
31-
monthBodyCtrl.generateContent();
3231

3332
// The virtual-repeat re-uses the same DOM elements, so there are only a limited number
3433
// of repeated items that are linked, and then those elements have their bindings updated.
@@ -81,8 +80,9 @@
8180
CalendarMonthBodyCtrl.prototype.generateContent = function() {
8281
var date = this.dateUtil.incrementMonths(this.monthCtrl.firstRenderableDate, this.offset);
8382

84-
this.$element.empty();
85-
this.$element.append(this.buildCalendarForMonth(date));
83+
this.$element
84+
.empty()
85+
.append(this.buildCalendarForMonth(date));
8686

8787
if (this.focusAfterAppend) {
8888
this.focusAfterAppend.classList.add(this.calendarCtrl.FOCUSED_DATE_CLASS);

src/components/datepicker/js/calendarYearBody.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222

2323
yearBodyCtrl.calendarCtrl = calendarCtrl;
2424
yearBodyCtrl.yearCtrl = yearCtrl;
25-
yearBodyCtrl.generateContent();
2625

2726
scope.$watch(function() { return yearBodyCtrl.offset; }, function(offset, oldOffset) {
28-
if (offset != oldOffset) {
27+
if (offset !== oldOffset) {
2928
yearBodyCtrl.generateContent();
3029
}
3130
});
@@ -71,8 +70,9 @@
7170
CalendarYearBodyCtrl.prototype.generateContent = function() {
7271
var date = this.dateUtil.incrementYears(this.yearCtrl.firstRenderableDate, this.offset);
7372

74-
this.$element.empty();
75-
this.$element.append(this.buildCalendarForYear(date));
73+
this.$element
74+
.empty()
75+
.append(this.buildCalendarForYear(date));
7676

7777
if (this.focusAfterAppend) {
7878
this.focusAfterAppend.classList.add(this.calendarCtrl.FOCUSED_DATE_CLASS);

0 commit comments

Comments
 (0)