@@ -10,7 +10,8 @@ import {
10
10
Output ,
11
11
ViewChild ,
12
12
ViewContainerRef ,
13
- ViewEncapsulation
13
+ ViewEncapsulation ,
14
+ NgZone ,
14
15
} from '@angular/core' ;
15
16
import { Overlay } from '../core/overlay/overlay' ;
16
17
import { OverlayRef } from '../core/overlay/overlay-ref' ;
@@ -20,18 +21,15 @@ import {Dir} from '../core/rtl/dir';
20
21
import { MdDialog } from '../dialog/dialog' ;
21
22
import { MdDialogRef } from '../dialog/dialog-ref' ;
22
23
import { PositionStrategy } from '../core/overlay/position/position-strategy' ;
23
- import {
24
- OriginConnectionPosition ,
25
- OverlayConnectionPosition
26
- } from '../core/overlay/position/connected-position' ;
24
+ import { RepositionScrollStrategy , ScrollDispatcher } from '../core/overlay/index' ;
27
25
import { MdDatepickerInput } from './datepicker-input' ;
28
- import 'rxjs/add/operator/first' ;
29
26
import { Subscription } from 'rxjs/Subscription' ;
30
27
import { MdDialogConfig } from '../dialog/dialog-config' ;
31
28
import { DateAdapter } from '../core/datetime/index' ;
32
29
import { createMissingDateImplError } from './datepicker-errors' ;
33
30
import { ESCAPE } from '../core/keyboard/keycodes' ;
34
31
import { MdCalendar } from './calendar' ;
32
+ import 'rxjs/add/operator/first' ;
35
33
36
34
37
35
/** Used to generate a unique ID for each datepicker instance. */
@@ -155,8 +153,11 @@ export class MdDatepicker<D> implements OnDestroy {
155
153
156
154
private _inputSubscription : Subscription ;
157
155
158
- constructor ( private _dialog : MdDialog , private _overlay : Overlay ,
156
+ constructor ( private _dialog : MdDialog ,
157
+ private _overlay : Overlay ,
158
+ private _ngZone : NgZone ,
159
159
private _viewContainerRef : ViewContainerRef ,
160
+ private _scrollDispatcher : ScrollDispatcher ,
160
161
@Optional ( ) private _dateAdapter : DateAdapter < D > ,
161
162
@Optional ( ) private _dir : Dir ) {
162
163
if ( ! this . _dateAdapter ) {
@@ -253,6 +254,9 @@ export class MdDatepicker<D> implements OnDestroy {
253
254
let componentRef : ComponentRef < MdDatepickerContent < D > > =
254
255
this . _popupRef . attach ( this . _calendarPortal ) ;
255
256
componentRef . instance . datepicker = this ;
257
+
258
+ // Update the position once the calendar has rendered.
259
+ this . _ngZone . onStable . first ( ) . subscribe ( ( ) => this . _popupRef . updatePosition ( ) ) ;
256
260
}
257
261
258
262
this . _popupRef . backdropClick ( ) . first ( ) . subscribe ( ( ) => this . close ( ) ) ;
@@ -265,15 +269,29 @@ export class MdDatepicker<D> implements OnDestroy {
265
269
overlayState . hasBackdrop = true ;
266
270
overlayState . backdropClass = 'md-overlay-transparent-backdrop' ;
267
271
overlayState . direction = this . _dir ? this . _dir . value : 'ltr' ;
272
+ overlayState . scrollStrategy = new RepositionScrollStrategy ( this . _scrollDispatcher ) ;
268
273
269
274
this . _popupRef = this . _overlay . create ( overlayState ) ;
270
275
}
271
276
272
277
/** Create the popup PositionStrategy. */
273
278
private _createPopupPositionStrategy ( ) : PositionStrategy {
274
- let origin = { originX : 'start' , originY : 'bottom' } as OriginConnectionPosition ;
275
- let overlay = { overlayX : 'start' , overlayY : 'top' } as OverlayConnectionPosition ;
276
- return this . _overlay . position ( ) . connectedTo (
277
- this . _datepickerInput . getPopupConnectionElementRef ( ) , origin , overlay ) ;
279
+ return this . _overlay . position ( )
280
+ . connectedTo ( this . _datepickerInput . getPopupConnectionElementRef ( ) ,
281
+ { originX : 'start' , originY : 'bottom' } ,
282
+ { overlayX : 'start' , overlayY : 'top' }
283
+ )
284
+ . withFallbackPosition (
285
+ { originX : 'start' , originY : 'top' } ,
286
+ { overlayX : 'start' , overlayY : 'bottom' }
287
+ )
288
+ . withFallbackPosition (
289
+ { originX : 'end' , originY : 'bottom' } ,
290
+ { overlayX : 'end' , overlayY : 'top' }
291
+ )
292
+ . withFallbackPosition (
293
+ { originX : 'end' , originY : 'top' } ,
294
+ { overlayX : 'end' , overlayY : 'bottom' }
295
+ ) ;
278
296
}
279
297
}
0 commit comments