|
9 | 9 | import {Direction} from '@angular/cdk/bidi';
|
10 | 10 | import {ComponentPortal, Portal, PortalOutlet, TemplatePortal} from '@angular/cdk/portal';
|
11 | 11 | import {ComponentRef, EmbeddedViewRef, NgZone} from '@angular/core';
|
12 |
| -import {Observable, Subject} from 'rxjs'; |
13 |
| -import {take} from 'rxjs/operators'; |
| 12 | +import {Observable, Subject, fromEvent} from 'rxjs'; |
| 13 | +import {take, tap, debounceTime} from 'rxjs/operators'; |
14 | 14 | import {OverlayKeyboardDispatcher} from './keyboard/overlay-keyboard-dispatcher';
|
15 | 15 | import {OverlayConfig} from './overlay-config';
|
16 | 16 | import {coerceCssPixelValue, coerceArray} from '@angular/cdk/coercion';
|
| 17 | +import {BlockScrollStrategy} from './scroll/index'; |
17 | 18 |
|
18 | 19 |
|
19 | 20 | /** An object where all of its properties cannot be written. */
|
@@ -301,6 +302,19 @@ export class OverlayRef implements PortalOutlet {
|
301 | 302 | this._backdropElement.addEventListener('click',
|
302 | 303 | (event: MouseEvent) => this._backdropClick.next(event));
|
303 | 304 |
|
| 305 | + if (!(this._config.scrollStrategy instanceof BlockScrollStrategy)) { |
| 306 | + // When the user starts scrolling by mouse, disable pointer events on the backdrop. This |
| 307 | + // allows for non-body scroll containers (e.g. a sidenav container), which would normally |
| 308 | + // be blocked due to the backdrop, to scroll. When the user has stopped scrolling for 100ms |
| 309 | + // restore the pointer events in order for the click handler to work. |
| 310 | + this._ngZone.runOutsideAngular(() => { |
| 311 | + fromEvent(this._backdropElement!, 'wheel').pipe( |
| 312 | + tap(() => this._backdropElement!.style.pointerEvents = 'none'), |
| 313 | + debounceTime(100) |
| 314 | + ).subscribe(() => this._backdropElement!.style.pointerEvents = ''); |
| 315 | + }); |
| 316 | + } |
| 317 | + |
304 | 318 | // Add class to fade-in the backdrop after one frame.
|
305 | 319 | if (typeof requestAnimationFrame !== 'undefined') {
|
306 | 320 | this._ngZone.runOutsideAngular(() => {
|
|
0 commit comments