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

fix(datepicker): prevent scrolling within a dialog #8292

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 9 additions & 5 deletions src/components/datepicker/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@
var maxDate = this.dateUtil.createDateAtMidnight(this.maxDate);
this.ngModelCtrl.$setValidity('maxdate', date <= maxDate);
}

if (angular.isFunction(this.dateFilter)) {
this.ngModelCtrl.$setValidity('filtered', this.dateFilter(date));
}
Expand Down Expand Up @@ -441,25 +441,28 @@

this.updateErrorState(parsedDate);
};

/**
* Check whether date is in range and enabled
* @param {Date=} opt_date
* @return {boolean} Whether the date is enabled.
*/
DatePickerCtrl.prototype.isDateEnabled = function(opt_date) {
return this.dateUtil.isDateWithinRange(opt_date, this.minDate, this.maxDate) &&
return this.dateUtil.isDateWithinRange(opt_date, this.minDate, this.maxDate) &&
(!angular.isFunction(this.dateFilter) || this.dateFilter(opt_date));
};

/** Position and attach the floating calendar to the document. */
DatePickerCtrl.prototype.attachCalendarPane = function() {
var calendarPane = this.calendarPane;
var body = document.body;

calendarPane.style.transform = '';
this.$element.addClass('md-datepicker-open');
angular.element(body).addClass('md-datepicker-is-showing');

var elementRect = this.inputContainer.getBoundingClientRect();
var bodyRect = document.body.getBoundingClientRect();
var bodyRect = body.getBoundingClientRect();

// Check to see if the calendar pane would go off the screen. If so, adjust position
// accordingly to keep it within the viewport.
Expand Down Expand Up @@ -524,6 +527,7 @@
/** Detach the floating calendar pane from the document. */
DatePickerCtrl.prototype.detachCalendarPane = function() {
this.$element.removeClass('md-datepicker-open');
angular.element(document.body).removeClass('md-datepicker-is-showing');
this.calendarPane.classList.remove('md-pane-open');
this.calendarPane.classList.remove('md-datepicker-pos-adjusted');

Expand Down
5 changes: 4 additions & 1 deletion src/components/datepicker/datePicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ md-datepicker {
}
}

.md-datepicker-is-showing .md-scroll-mask {
z-index: $z-index-calendar-pane - 1;
}

// Floating pane that contains the calendar at the bottom of the input.
.md-datepicker-calendar-pane {
position: absolute;
top: 0;
left: 0;
z-index: $z-index-menu;
z-index: $z-index-calendar-pane;

border-width: 1px;
border-style: solid;
Expand Down
4 changes: 3 additions & 1 deletion src/core/style/structure.scss
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,16 @@ input {
right: 0;
bottom: 0;
left: 0;
z-index: $z-index-scroll-mask;

> .md-scroll-mask-bar {
display: block;
position: absolute;
background-color: #fafafa;
right: 0;
top: 0;
bottom: 0;
z-index: $z-index-scroll-mask;
z-index: $z-index-scroll-mask-bar;
box-shadow: inset 0px 0px 1px rgba(0, 0, 0, 0.3)
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/style/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ $whiteframe-shadow-24dp: 0px 11px 15px -7px rgba(0, 0, 0, $shadow-key-umbra-opac
$z-index-toast: 105 !default;
$z-index-tooltip: 100 !default;
$z-index-menu: 100 !default;
$z-index-calendar-pane: 100 !default;
$z-index-select: 90 !default;
$z-index-dialog: 80 !default;
$z-index-bottom-sheet: 70 !default;
$z-index-scroll-mask: 65 !default;
$z-index-scroll-mask: 50 !default;
$z-index-scroll-mask-bar: 65 !default;
$z-index-sidenav: 60 !default;
$z-index-backdrop: 50 !default;
$z-index-fab: 20 !default;
Expand Down
3 changes: 1 addition & 2 deletions src/core/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,10 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
// Creates a virtual scrolling mask to absorb touchmove, keyboard, scrollbar clicking, and wheel events
function disableElementScroll(element) {
element = angular.element(element || body)[0];
var zIndex = 50;
var scrollMask = angular.element(
'<div class="md-scroll-mask">' +
' <div class="md-scroll-mask-bar"></div>' +
'</div>').css('z-index', zIndex);
'</div>');
element.appendChild(scrollMask[0]);

scrollMask.on('wheel', preventDefault);
Expand Down