@@ -19,6 +19,8 @@ import {
1919 Renderer2 ,
2020 OnChanges ,
2121 SimpleChanges ,
22+ InjectionToken ,
23+ Inject ,
2224} from '@angular/core' ;
2325import { Overlay } from './overlay' ;
2426import { OverlayRef } from './overlay-ref' ;
@@ -33,14 +35,14 @@ import {
3335} from './position/connected-position' ;
3436import { ConnectedPositionStrategy } from './position/connected-position-strategy' ;
3537import { Directionality , Direction } from '../bidi/index' ;
36- import { ScrollStrategy } from './scroll/scroll-strategy' ;
3738import { coerceBooleanProperty } from '@angular/cdk' ;
39+ import { ScrollStrategy , RepositionScrollStrategy } from './scroll/index' ;
3840import { ESCAPE } from '../keyboard/keycodes' ;
3941import { Subscription } from 'rxjs/Subscription' ;
4042
4143
4244/** Default set of positions for the overlay. Follows the behavior of a dropdown. */
43- let defaultPositionList = [
45+ const defaultPositionList = [
4446 new ConnectionPositionPair (
4547 { originX : 'start' , originY : 'bottom' } ,
4648 { overlayX : 'start' , overlayY : 'top' } ) ,
@@ -49,6 +51,23 @@ let defaultPositionList = [
4951 { overlayX : 'start' , overlayY : 'bottom' } ) ,
5052] ;
5153
54+ /** Injection token that determines the scroll handling while the connected overlay is open. */
55+ export const MD_CONNECTED_OVERLAY_SCROLL_STRATEGY =
56+ new InjectionToken < ( ) => ScrollStrategy > ( 'md-connected-overlay-scroll-strategy' ) ;
57+
58+ /** @docs -private */
59+ export function MD_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER_FACTORY ( overlay : Overlay ) {
60+ return ( ) => overlay . scrollStrategies . reposition ( ) ;
61+ }
62+
63+ /** @docs -private */
64+ export const MD_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER = {
65+ provide : MD_CONNECTED_OVERLAY_SCROLL_STRATEGY ,
66+ deps : [ Overlay ] ,
67+ useFactory : MD_CONNECTED_OVERLAY_SCROLL_STRATEGY_PROVIDER_FACTORY ,
68+ } ;
69+
70+
5271
5372/**
5473 * Directive applied to an element to make it usable as an origin for an Overlay using a
@@ -130,7 +149,7 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {
130149 @Input ( ) backdropClass : string ;
131150
132151 /** Strategy to be used when handling scroll events while the overlay is open. */
133- @Input ( ) scrollStrategy : ScrollStrategy = this . _overlay . scrollStrategies . reposition ( ) ;
152+ @Input ( ) scrollStrategy : ScrollStrategy = this . _scrollStrategy ( ) ;
134153
135154 /** Whether the overlay is open. */
136155 @Input ( ) open : boolean = false ;
@@ -164,6 +183,7 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {
164183 private _renderer : Renderer2 ,
165184 templateRef : TemplateRef < any > ,
166185 viewContainerRef : ViewContainerRef ,
186+ @Inject ( MD_CONNECTED_OVERLAY_SCROLL_STRATEGY ) private _scrollStrategy ,
167187 @Optional ( ) private _dir : Directionality ) {
168188 this . _templatePortal = new TemplatePortal ( templateRef , viewContainerRef ) ;
169189 }
0 commit comments