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

Commit 918e335

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(backdrop): adjust the backdrop height when the viewport resizes
The backdrop's height was being set only on initialization, but this meant that it be clipped if the viewport got resized. Fixes #8155. Closes #8285
1 parent c513e49 commit 918e335

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/components/backdrop/backdrop.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,28 @@
1919

2020
angular
2121
.module('material.components.backdrop', ['material.core'])
22-
.directive('mdBackdrop', function BackdropDirective($mdTheming, $animate, $rootElement, $window, $log, $$rAF, $document) {
22+
.directive('mdBackdrop', function BackdropDirective($mdTheming, $mdUtil, $animate, $rootElement, $window, $log, $$rAF, $document) {
2323
var ERROR_CSS_POSITION = "<md-backdrop> may not work properly in a scrolled, static-positioned parent container.";
2424

2525
return {
2626
restrict: 'E',
2727
link: postLink
2828
};
2929

30-
function postLink(scope, element, attrs) {
30+
function postLink(scope, element) {
3131

3232
// If body scrolling has been disabled using mdUtil.disableBodyScroll(),
3333
// adjust the 'backdrop' height to account for the fixed 'body' top offset
3434
var body = $window.getComputedStyle($document[0].body);
35+
3536
if (body.position == 'fixed') {
36-
var hViewport = parseInt(body.height, 10) + Math.abs(parseInt(body.top, 10));
37-
element.css({
38-
height: hViewport + 'px'
37+
var debouncedResize = $mdUtil.debounce(resize, 60, null, false);
38+
39+
resize();
40+
angular.element($window).on('resize', debouncedResize);
41+
42+
scope.$on('$destroy', function() {
43+
angular.element($window).off('resize', debouncedResize);
3944
});
4045
}
4146

@@ -66,6 +71,13 @@ angular
6671
}
6772
});
6873

74+
function resize() {
75+
var hViewport = parseInt(body.height, 10) + Math.abs(parseInt(body.top, 10));
76+
element.css({
77+
height: hViewport + 'px'
78+
});
79+
}
80+
6981
}
7082

7183
});

0 commit comments

Comments
 (0)