@@ -232,6 +232,8 @@ function SidenavFocusDirective() {
232
232
* @param {expression= } md-is-locked-open When this expression evaluates to true,
233
233
* the sidenav 'locks open': it falls into the content's flow instead
234
234
* of appearing over it. This overrides the `md-is-open` attribute.
235
+ * @param {string= } md-disable-scroll-target Selector, pointing to an element, whose scrolling will
236
+ * be disabled when the sidenav is opened. By default this is the sidenav's direct parent.
235
237
*
236
238
* The $mdMedia() service is exposed to the is-locked-open attribute, which
237
239
* can be given a media query or one of the `sm`, `gt-sm`, `md`, `gt-md`, `lg` or `gt-lg` presets.
@@ -261,6 +263,7 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
261
263
function postLink ( scope , element , attr , sidenavCtrl ) {
262
264
var lastParentOverFlow ;
263
265
var backdrop ;
266
+ var disableScrollTarget = null ;
264
267
var triggeringElement = null ;
265
268
var previousContainerStyles ;
266
269
var promise = $q . when ( true ) ;
@@ -275,8 +278,23 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
275
278
} ) ;
276
279
} ;
277
280
281
+ if ( attr . mdDisableScrollTarget ) {
282
+ disableScrollTarget = $document [ 0 ] . querySelector ( attr . mdDisableScrollTarget ) ;
283
+
284
+ if ( disableScrollTarget ) {
285
+ disableScrollTarget = angular . element ( disableScrollTarget ) ;
286
+ } else {
287
+ $log . warn ( $mdUtil . supplant ( 'mdSidenav: couldn\'t find element matching ' +
288
+ 'selector "{selector}". Falling back to parent.' , { selector : attr . mdDisableScrollTarget } ) ) ;
289
+ }
290
+ }
291
+
292
+ if ( ! disableScrollTarget ) {
293
+ disableScrollTarget = element . parent ( ) ;
294
+ }
295
+
278
296
// Only create the backdrop if the backdrop isn't disabled.
279
- if ( ! angular . isDefined ( attr . mdDisableBackdrop ) ) {
297
+ if ( ! attr . hasOwnProperty ( ' mdDisableBackdrop' ) ) {
280
298
backdrop = $mdUtil . createBackdrop ( scope , "md-sidenav-backdrop md-opaque ng-enter" ) ;
281
299
}
282
300
@@ -393,25 +411,20 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
393
411
backdrop [ 0 ] . style . height = null ;
394
412
395
413
previousContainerStyles = null ;
396
- }
414
+ } ;
397
415
}
398
416
}
399
417
400
418
/**
401
419
* Prevent parent scrolling (when the SideNav is open)
402
420
*/
403
421
function disableParentScroll ( disabled ) {
404
- var parent = element . parent ( ) ;
405
422
if ( disabled && ! lastParentOverFlow ) {
406
-
407
- lastParentOverFlow = parent . css ( 'overflow' ) ;
408
- parent . css ( 'overflow' , 'hidden' ) ;
409
-
423
+ lastParentOverFlow = disableScrollTarget . css ( 'overflow' ) ;
424
+ disableScrollTarget . css ( 'overflow' , 'hidden' ) ;
410
425
} else if ( angular . isDefined ( lastParentOverFlow ) ) {
411
-
412
- parent . css ( 'overflow' , lastParentOverFlow ) ;
426
+ disableScrollTarget . css ( 'overflow' , lastParentOverFlow ) ;
413
427
lastParentOverFlow = undefined ;
414
-
415
428
}
416
429
}
417
430
0 commit comments