Skip to content

Commit 3ac4f64

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 99396a4 commit 3ac4f64

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-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
_showClickCatcher: boolean = false;
3132
private _focusedItemIndex: number = 0;
3233

@@ -59,7 +60,7 @@ export class MdMenu {
5960
}, {});
6061
}
6162

62-
@Output() close = new EventEmitter;
63+
@Output() close = new EventEmitter<void>();
6364

6465
/**
6566
* This function toggles the display of the menu's click catcher element.

src/lib/menu/menu-interface.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
_setClickCatcher: (bool: boolean) => void;
11+
}

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,
@@ -45,7 +45,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
4545
// the first item of the list when the menu is opened via the keyboard
4646
private _openedFromKeyboard: boolean = false;
4747

48-
@Input('md-menu-trigger-for') menu: MdMenu;
48+
@Input('md-menu-trigger-for') menu: MdMenuInterface;
4949
@Output() onMenuOpen = new EventEmitter();
5050
@Output() onMenuClose = new EventEmitter();
5151

@@ -129,7 +129,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
129129
* md-menu-trigger-for. If not, an exception is thrown.
130130
*/
131131
private _checkMenu() {
132-
if (!this.menu || !(this.menu instanceof MdMenu)) {
132+
if (!this.menu) {
133133
throw new MdMenuMissingError();
134134
}
135135
}

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)