|
9 | 9 | import {Direction, Directionality} 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, merge} from 'rxjs'; |
13 | | -import {take, takeUntil} from 'rxjs/operators'; |
| 12 | +import {Observable, Subject, merge, fromEvent} from 'rxjs'; |
| 13 | +import {take, takeUntil, 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 | 17 | import {OverlayReference} from './overlay-reference'; |
| 18 | +import {BlockScrollStrategy} from './scroll/index'; |
18 | 19 |
|
19 | 20 |
|
20 | 21 | /** An object where all of its properties cannot be written. */ |
@@ -346,6 +347,19 @@ export class OverlayRef implements PortalOutlet, OverlayReference { |
346 | 347 | this._backdropElement.addEventListener('click', |
347 | 348 | (event: MouseEvent) => this._backdropClick.next(event)); |
348 | 349 |
|
| 350 | + if (!(this._config.scrollStrategy instanceof BlockScrollStrategy)) { |
| 351 | + // When the user starts scrolling by mouse, disable pointer events on the backdrop. This |
| 352 | + // allows for non-body scroll containers (e.g. a sidenav container), which would normally |
| 353 | + // be blocked due to the backdrop, to scroll. When the user has stopped scrolling for 100ms |
| 354 | + // restore the pointer events in order for the click handler to work. |
| 355 | + this._ngZone.runOutsideAngular(() => { |
| 356 | + fromEvent(this._backdropElement!, 'wheel').pipe( |
| 357 | + tap(() => this._backdropElement!.style.pointerEvents = 'none'), |
| 358 | + debounceTime(100) |
| 359 | + ).subscribe(() => this._backdropElement!.style.pointerEvents = ''); |
| 360 | + }); |
| 361 | + } |
| 362 | + |
349 | 363 | // Add class to fade-in the backdrop after one frame. |
350 | 364 | if (typeof requestAnimationFrame !== 'undefined') { |
351 | 365 | this._ngZone.runOutsideAngular(() => { |
|
0 commit comments