|
1 | 1 | import { |
| 2 | + AfterViewInit, |
2 | 3 | Directive, |
3 | 4 | ElementRef, |
| 5 | + EventEmitter, |
4 | 6 | Input, |
| 7 | + OnDestroy, |
| 8 | + Optional, |
5 | 9 | Output, |
6 | | - EventEmitter, |
| 10 | + Renderer, |
7 | 11 | ViewContainerRef, |
8 | | - AfterViewInit, |
9 | | - OnDestroy, |
10 | | - Renderer |
11 | 12 | } from '@angular/core'; |
12 | 13 | import {MdMenuPanel} from './menu-panel'; |
13 | 14 | import {MdMenuMissingError} from './menu-errors'; |
14 | 15 | import { |
| 16 | + Dir, |
| 17 | + LayoutDirection, |
15 | 18 | ENTER, |
16 | 19 | SPACE, |
17 | 20 | Overlay, |
@@ -52,7 +55,8 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy { |
52 | 55 | @Output() onMenuClose = new EventEmitter<void>(); |
53 | 56 |
|
54 | 57 | constructor(private _overlay: Overlay, private _element: ElementRef, |
55 | | - private _viewContainerRef: ViewContainerRef, private _renderer: Renderer) {} |
| 58 | + private _viewContainerRef: ViewContainerRef, private _renderer: Renderer, |
| 59 | + @Optional() private _dir: Dir) {} |
56 | 60 |
|
57 | 61 | ngAfterViewInit() { |
58 | 62 | this._checkMenu(); |
@@ -99,6 +103,11 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy { |
99 | 103 | this._renderer.invokeElementMethod(this._element.nativeElement, 'focus'); |
100 | 104 | } |
101 | 105 |
|
| 106 | + /** The text direction of the containing app. */ |
| 107 | + get dir(): LayoutDirection { |
| 108 | + return this._dir && this._dir.value === 'rtl' ? 'rtl' : 'ltr'; |
| 109 | + } |
| 110 | + |
102 | 111 | /** |
103 | 112 | * This method ensures that the menu closes when the overlay backdrop is clicked. |
104 | 113 | * We do not use first() here because doing so would not catch clicks from within |
@@ -169,9 +178,11 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy { |
169 | 178 | */ |
170 | 179 | private _getOverlayConfig(): OverlayState { |
171 | 180 | const overlayState = new OverlayState(); |
172 | | - overlayState.positionStrategy = this._getPosition(); |
| 181 | + overlayState.positionStrategy = this._getPosition() |
| 182 | + .withDirection(this.dir); |
173 | 183 | overlayState.hasBackdrop = true; |
174 | 184 | overlayState.backdropClass = 'md-overlay-transparent-backdrop'; |
| 185 | + overlayState.direction = this.dir; |
175 | 186 | return overlayState; |
176 | 187 | } |
177 | 188 |
|
|
0 commit comments