@@ -203,6 +203,8 @@ function MdDialogDirective($$rAF, $mdTheming) {
203
203
* - `targetEvent` - `{DOMClickEvent=}`: A click's event object. When passed in as an option,
204
204
* the location of the click will be used as the starting point for the opening animation
205
205
* of the the dialog.
206
+ * - `disableParentScroll` - `{boolean=}`: Whether to disable scrolling while the dialog is open.
207
+ * Default true.
206
208
* - `hasBackdrop` - `{boolean=}`: Whether there should be an opaque backdrop behind the dialog.
207
209
* Default true.
208
210
* - `clickOutsideToClose` - `{boolean=}`: Whether the user can click outside the dialog to
@@ -254,7 +256,7 @@ function MdDialogProvider($$interimElementProvider) {
254
256
255
257
return $$interimElementProvider ( '$mdDialog' )
256
258
. setDefaults ( {
257
- methods : [ 'hasBackdrop' , 'clickOutsideToClose' , 'escapeToClose' , 'targetEvent' ] ,
259
+ methods : [ 'disableParentScroll' , ' hasBackdrop', 'clickOutsideToClose' , 'escapeToClose' , 'targetEvent' ] ,
258
260
options : dialogDefaultOptions
259
261
} )
260
262
. addPreset ( 'alert' , {
@@ -309,11 +311,13 @@ function MdDialogProvider($$interimElementProvider) {
309
311
clickOutsideToClose : true ,
310
312
escapeToClose : true ,
311
313
targetEvent : null ,
314
+ disableParentScroll : true ,
312
315
transformTemplate : function ( template ) {
313
316
return '<div class="md-dialog-container">' + template + '</div>' ;
314
317
}
315
318
} ;
316
319
320
+
317
321
// On show method for dialogs
318
322
function onShow ( scope , element , options ) {
319
323
// Incase the user provides a raw dom element, always wrap it in jqLite
@@ -330,6 +334,11 @@ function MdDialogProvider($$interimElementProvider) {
330
334
$animate . enter ( options . backdrop , options . parent ) ;
331
335
}
332
336
337
+ if ( options . disableParentScroll ) {
338
+ options . oldOverflowStyle = options . parent . css ( 'overflow' ) ;
339
+ options . parent . css ( 'overflow' , 'hidden' ) ;
340
+ }
341
+
333
342
return dialogPopIn (
334
343
element ,
335
344
options . parent ,
@@ -377,6 +386,10 @@ function MdDialogProvider($$interimElementProvider) {
377
386
if ( options . backdrop ) {
378
387
$animate . leave ( options . backdrop ) ;
379
388
}
389
+ if ( options . disableParentScroll ) {
390
+ options . parent . css ( 'overflow' , options . oldOverflowStyle ) ;
391
+ $document [ 0 ] . removeEventListener ( 'scroll' , options . captureScroll , true ) ;
392
+ }
380
393
if ( options . escapeToClose ) {
381
394
$rootElement . off ( 'keyup' , options . rootElementKeyupCallback ) ;
382
395
}
0 commit comments