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