@@ -20,6 +20,8 @@ import {
2020 Renderer2 ,
2121 OnChanges ,
2222 SimpleChanges ,
23+ InjectionToken ,
24+ Inject ,
2325} from '@angular/core' ;
2426import { Overlay , OVERLAY_PROVIDERS } from './overlay' ;
2527import { OverlayRef } from './overlay-ref' ;
@@ -32,16 +34,19 @@ import {
3234import { PortalModule } from '../portal/portal-directives' ;
3335import { ConnectedPositionStrategy } from './position/connected-position-strategy' ;
3436import { Dir , LayoutDirection } from '../rtl/dir' ;
35- import { Scrollable } from './scroll/scrollable' ;
36- import { ScrollStrategy } from './scroll/scroll-strategy' ;
3737import { coerceBooleanProperty } from '../coercion/boolean-property' ;
3838import { ESCAPE } from '../keyboard/keycodes' ;
3939import { Subscription } from 'rxjs/Subscription' ;
40- import { ScrollDispatchModule } from './scroll/index' ;
40+ import {
41+ ScrollStrategy ,
42+ RepositionScrollStrategy ,
43+ Scrollable ,
44+ ScrollDispatchModule ,
45+ } from './scroll/index' ;
4146
4247
4348/** Default set of positions for the overlay. Follows the behavior of a dropdown. */
44- let defaultPositionList = [
49+ const defaultPositionList = [
4550 new ConnectionPositionPair (
4651 { originX : 'start' , originY : 'bottom' } ,
4752 { overlayX : 'start' , overlayY : 'top' } ) ,
@@ -50,6 +55,23 @@ let defaultPositionList = [
5055 { overlayX : 'start' , overlayY : 'bottom' } ) ,
5156] ;
5257
58+ /** Injection token that determines the scroll handling while the connected overlay is open. */
59+ export const MD_CONNECTED_OVERLAY_SCROLL_STRATEGY =
60+ new InjectionToken < ( ) => ScrollStrategy > ( 'md-connected-overlay-scroll-strategy' ) ;
61+
62+ /** @docs -private */
63+ export function MD_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER_FACTORY ( overlay : Overlay ) {
64+ return ( ) => overlay . scrollStrategies . reposition ( ) ;
65+ }
66+
67+ /** @docs -private */
68+ export const MD_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER = {
69+ provide : MD_CONNECTED_OVERLAY_SCROLL_STRATEGY ,
70+ deps : [ Overlay ] ,
71+ useFactory : MD_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER_FACTORY ,
72+ } ;
73+
74+
5375
5476/**
5577 * Directive applied to an element to make it usable as an origin for an Overlay using a
@@ -131,7 +153,7 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {
131153 @Input ( ) backdropClass : string ;
132154
133155 /** Strategy to be used when handling scroll events while the overlay is open. */
134- @Input ( ) scrollStrategy : ScrollStrategy = this . _overlay . scrollStrategies . reposition ( ) ;
156+ @Input ( ) scrollStrategy : ScrollStrategy = this . _scrollStrategy ( ) ;
135157
136158 /** Whether the overlay is open. */
137159 @Input ( ) open : boolean = false ;
@@ -165,7 +187,8 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {
165187 private _renderer : Renderer2 ,
166188 templateRef : TemplateRef < any > ,
167189 viewContainerRef : ViewContainerRef ,
168- @Optional ( ) private _dir : Dir ) {
190+ @Optional ( ) private _dir : Dir ,
191+ @Inject ( MD_CONNECTED_OVERLAY_SCROLL_STRATEGY ) private _scrollStrategy ) {
169192 this . _templatePortal = new TemplatePortal ( templateRef , viewContainerRef ) ;
170193 }
171194
@@ -332,6 +355,6 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {
332355 imports : [ PortalModule , ScrollDispatchModule ] ,
333356 exports : [ ConnectedOverlayDirective , OverlayOrigin , ScrollDispatchModule ] ,
334357 declarations : [ ConnectedOverlayDirective , OverlayOrigin ] ,
335- providers : [ OVERLAY_PROVIDERS ] ,
358+ providers : [ OVERLAY_PROVIDERS , MD_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER ] ,
336359} )
337360export class OverlayModule { }
0 commit comments