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

Commit 6e38d7c

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(datepicker): prevent scrolling within a dialog
* Fixes the datepicker not blocking scrolling when it is used within a dialog. * Moves the `.md-scroll-mask` z-index to the SASS files since the old value was being set with JS for no apparent reason and made it harder to override. * Adds a variable for the datepicker's z-index, since it was using the one for the menu. Fixes #8177. Closes #8292
1 parent efbbd37 commit 6e38d7c

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

src/components/datepicker/datePicker.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,14 @@
464464
/** Position and attach the floating calendar to the document. */
465465
DatePickerCtrl.prototype.attachCalendarPane = function() {
466466
var calendarPane = this.calendarPane;
467+
var body = document.body;
468+
467469
calendarPane.style.transform = '';
468470
this.$element.addClass('md-datepicker-open');
471+
angular.element(body).addClass('md-datepicker-is-showing');
469472

470473
var elementRect = this.inputContainer.getBoundingClientRect();
471-
var bodyRect = document.body.getBoundingClientRect();
474+
var bodyRect = body.getBoundingClientRect();
472475

473476
// Check to see if the calendar pane would go off the screen. If so, adjust position
474477
// accordingly to keep it within the viewport.
@@ -533,6 +536,7 @@
533536
/** Detach the floating calendar pane from the document. */
534537
DatePickerCtrl.prototype.detachCalendarPane = function() {
535538
this.$element.removeClass('md-datepicker-open');
539+
angular.element(document.body).removeClass('md-datepicker-is-showing');
536540
this.calendarPane.classList.remove('md-pane-open');
537541
this.calendarPane.classList.remove('md-datepicker-pos-adjusted');
538542

src/components/datepicker/datePicker.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ md-datepicker {
5454
}
5555
}
5656

57+
.md-datepicker-is-showing .md-scroll-mask {
58+
z-index: $z-index-calendar-pane - 1;
59+
}
5760

5861
// Floating pane that contains the calendar at the bottom of the input.
5962
.md-datepicker-calendar-pane {
6063
position: absolute;
6164
top: 0;
6265
left: 0;
63-
z-index: $z-index-menu;
66+
z-index: $z-index-calendar-pane;
6467

6568
border-width: 1px;
6669
border-style: solid;

src/core/style/structure.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,16 @@ input {
152152
right: 0;
153153
bottom: 0;
154154
left: 0;
155+
z-index: $z-index-scroll-mask;
156+
155157
> .md-scroll-mask-bar {
156158
display: block;
157159
position: absolute;
158160
background-color: #fafafa;
159161
right: 0;
160162
top: 0;
161163
bottom: 0;
162-
z-index: $z-index-scroll-mask;
164+
z-index: $z-index-scroll-mask-bar;
163165
box-shadow: inset 0px 0px 1px rgba(0, 0, 0, 0.3)
164166
}
165167
}

src/core/style/variables.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ $whiteframe-shadow-24dp: 0px 11px 15px -7px rgba(0, 0, 0, $shadow-key-umbra-opac
8383
$z-index-toast: 105 !default;
8484
$z-index-tooltip: 100 !default;
8585
$z-index-menu: 100 !default;
86+
$z-index-calendar-pane: 100 !default;
8687
$z-index-select: 90 !default;
8788
$z-index-dialog: 80 !default;
8889
$z-index-bottom-sheet: 70 !default;
89-
$z-index-scroll-mask: 65 !default;
90+
$z-index-scroll-mask: 50 !default;
91+
$z-index-scroll-mask-bar: 65 !default;
9092
$z-index-sidenav: 60 !default;
9193
$z-index-backdrop: 50 !default;
9294
$z-index-fab: 20 !default;

src/core/util/util.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,10 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
198198
// Creates a virtual scrolling mask to absorb touchmove, keyboard, scrollbar clicking, and wheel events
199199
function disableElementScroll(element) {
200200
element = angular.element(element || body)[0];
201-
var zIndex = 50;
202201
var scrollMask = angular.element(
203202
'<div class="md-scroll-mask">' +
204203
' <div class="md-scroll-mask-bar"></div>' +
205-
'</div>').css('z-index', zIndex);
204+
'</div>');
206205
element.appendChild(scrollMask[0]);
207206

208207
scrollMask.on('wheel', preventDefault);

0 commit comments

Comments
 (0)