Skip to content

Commit 68e8c55

Browse files
committed
Allow menu-trigger to take a menu interface.
This should enable menus to be more easily extended for custom menu implementations.
1 parent add0d23 commit 68e8c55

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/lib/menu/menu-directive.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {MenuPositionX, MenuPositionY} from './menu-positions';
1616
import {MdMenuInvalidPositionX, MdMenuInvalidPositionY} from './menu-errors';
1717
import {MdMenuItem} from './menu-item';
1818
import {UP_ARROW, DOWN_ARROW, TAB} from '../core';
19+
import {MdMenuInterface} from './menu-interface';
1920

2021
@Component({
2122
moduleId: module.id,
@@ -26,7 +27,7 @@ import {UP_ARROW, DOWN_ARROW, TAB} from '../core';
2627
encapsulation: ViewEncapsulation.None,
2728
exportAs: 'mdMenu'
2829
})
29-
export class MdMenu {
30+
export class MdMenu implements MdMenuInterface {
3031
private _focusedItemIndex: number = 0;
3132

3233
// config object to be passed into the menu's ngClass
@@ -58,7 +59,7 @@ export class MdMenu {
5859
}, {});
5960
}
6061

61-
@Output() close = new EventEmitter;
62+
@Output() close = new EventEmitter<void>();
6263

6364
/**
6465
* Focus the first item in the menu. This method is used by the menu trigger

src/lib/menu/menu-interface.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {EventEmitter, TemplateRef} from '@angular/core';
2+
import {MenuPositionX, MenuPositionY} from './menu-positions';
3+
4+
export interface MdMenuInterface {
5+
positionX: MenuPositionX;
6+
positionY: MenuPositionY;
7+
templateRef: TemplateRef<any>;
8+
close: EventEmitter<void>;
9+
_focusFirstItem: () => void;
10+
}

src/lib/menu/menu-trigger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
OnDestroy,
1111
Renderer
1212
} from '@angular/core';
13-
import {MdMenu} from './menu-directive';
13+
import {MdMenuInterface} from './menu-interface';
1414
import {MdMenuMissingError} from './menu-errors';
1515
import {
1616
ENTER,
@@ -47,7 +47,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
4747
// the first item of the list when the menu is opened via the keyboard
4848
private _openedFromKeyboard: boolean = false;
4949

50-
@Input('md-menu-trigger-for') menu: MdMenu;
50+
@Input('md-menu-trigger-for') menu: MdMenuInterface;
5151
@Output() onMenuOpen = new EventEmitter();
5252
@Output() onMenuClose = new EventEmitter();
5353

@@ -148,7 +148,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
148148
* md-menu-trigger-for. If not, an exception is thrown.
149149
*/
150150
private _checkMenu() {
151-
if (!this.menu || !(this.menu instanceof MdMenu)) {
151+
if (!this.menu) {
152152
throw new MdMenuMissingError();
153153
}
154154
}

src/lib/menu/menu.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {MdMenuTrigger} from './menu-trigger';
77
export {MdMenu} from './menu-directive';
88
export {MdMenuItem} from './menu-item';
99
export {MdMenuTrigger} from './menu-trigger';
10+
export {MdMenuInterface} from './menu-interface';
11+
export {MenuPositionX, MenuPositionY} from './menu-positions';
1012

1113

1214
@NgModule({

0 commit comments

Comments
 (0)