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

Commit b8c2d51

Browse files
devversionThomasBurleson
authored andcommitted
fix(datepicker): enable scrolling when scope destroyed.
When we change the route while the calendar pane is open, the scroll mask won't be removed. We need to re-enable scrolling on scope destruction. In this case, we also have to check for the pane to be open, because otherwise we may accidentally remove another scroll mask. Fixes #7542. Closes #7544.
1 parent 06e4ef9 commit b8c2d51

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/components/datepicker/datePicker.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@
527527
this.calendarPane.classList.remove('md-pane-open');
528528
this.calendarPane.classList.remove('md-datepicker-pos-adjusted');
529529

530+
if (this.isCalendarOpen) {
531+
this.$mdUtil.enableScrolling();
532+
}
533+
530534
if (this.calendarPane.parentNode) {
531535
// Use native DOM removal because we do not want any of the angular state of this element
532536
// to be disposed.
@@ -570,11 +574,10 @@
570574
/** Close the floating calendar pane. */
571575
DatePickerCtrl.prototype.closeCalendarPane = function() {
572576
if (this.isCalendarOpen) {
573-
this.isCalendarOpen = false;
574577
this.detachCalendarPane();
578+
this.isCalendarOpen = false;
575579
this.calendarPaneOpenedFrom.focus();
576580
this.calendarPaneOpenedFrom = null;
577-
this.$mdUtil.enableScrolling();
578581

579582
this.ngModelCtrl.$setTouched();
580583

src/components/datepicker/datePicker.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,35 @@ describe('md-date-picker', function() {
481481
expect(controller.calendarPaneOpenedFrom).toBe(null);
482482
expect(controller.isCalendarOpen).toBe(false);
483483
});
484+
485+
it('should re-enable scrolling probably', function() {
486+
var maskLength = getMaskLength();
487+
488+
controller.openCalendarPane({
489+
target: controller.inputElement
490+
});
491+
492+
expect(getMaskLength()).toBe(maskLength + 1);
493+
494+
controller.closeCalendarPane();
495+
496+
expect(getMaskLength()).toBe(maskLength);
497+
498+
controller.openCalendarPane({
499+
target: controller.inputElement
500+
});
501+
502+
expect(getMaskLength()).toBe(maskLength + 1);
503+
504+
// Trigger a scope destruction, like when a route changes.
505+
scope.$destroy();
506+
507+
expect(getMaskLength()).toBe(maskLength);
508+
509+
function getMaskLength() {
510+
return document.body.querySelectorAll('.md-scroll-mask').length;
511+
}
512+
});
484513
});
485514

486515
describe('md-calendar-change', function() {

0 commit comments

Comments
 (0)