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

Commit 4d639b0

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 f790e93 commit 4d639b0

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
@@ -515,6 +515,35 @@ describe('md-date-picker', function() {
515515
expect(controller.calendarPaneOpenedFrom).toBe(null);
516516
expect(controller.isCalendarOpen).toBe(false);
517517
});
518+
519+
it('should re-enable scrolling probably', function() {
520+
var maskLength = getMaskLength();
521+
522+
controller.openCalendarPane({
523+
target: controller.inputElement
524+
});
525+
526+
expect(getMaskLength()).toBe(maskLength + 1);
527+
528+
controller.closeCalendarPane();
529+
530+
expect(getMaskLength()).toBe(maskLength);
531+
532+
controller.openCalendarPane({
533+
target: controller.inputElement
534+
});
535+
536+
expect(getMaskLength()).toBe(maskLength + 1);
537+
538+
// Trigger a scope destruction, like when a route changes.
539+
scope.$destroy();
540+
541+
expect(getMaskLength()).toBe(maskLength);
542+
543+
function getMaskLength() {
544+
return document.body.querySelectorAll('.md-scroll-mask').length;
545+
}
546+
});
518547
});
519548

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

0 commit comments

Comments
 (0)