Skip to content

Commit

Permalink
Allow menu-trigger to take a menu interface.
Browse files Browse the repository at this point in the history
This should enable menus to be more easily extended for custom menu implementations.
  • Loading branch information
trshafer committed Oct 21, 2016
1 parent add0d23 commit 68e8c55
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/lib/menu/menu-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {MenuPositionX, MenuPositionY} from './menu-positions';
import {MdMenuInvalidPositionX, MdMenuInvalidPositionY} from './menu-errors';
import {MdMenuItem} from './menu-item';
import {UP_ARROW, DOWN_ARROW, TAB} from '../core';
import {MdMenuInterface} from './menu-interface';

@Component({
moduleId: module.id,
Expand All @@ -26,7 +27,7 @@ import {UP_ARROW, DOWN_ARROW, TAB} from '../core';
encapsulation: ViewEncapsulation.None,
exportAs: 'mdMenu'
})
export class MdMenu {
export class MdMenu implements MdMenuInterface {
private _focusedItemIndex: number = 0;

// config object to be passed into the menu's ngClass
Expand Down Expand Up @@ -58,7 +59,7 @@ export class MdMenu {
}, {});
}

@Output() close = new EventEmitter;
@Output() close = new EventEmitter<void>();

/**
* Focus the first item in the menu. This method is used by the menu trigger
Expand Down
10 changes: 10 additions & 0 deletions src/lib/menu/menu-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {EventEmitter, TemplateRef} from '@angular/core';
import {MenuPositionX, MenuPositionY} from './menu-positions';

export interface MdMenuInterface {
positionX: MenuPositionX;
positionY: MenuPositionY;
templateRef: TemplateRef<any>;
close: EventEmitter<void>;
_focusFirstItem: () => void;
}
6 changes: 3 additions & 3 deletions src/lib/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
OnDestroy,
Renderer
} from '@angular/core';
import {MdMenu} from './menu-directive';
import {MdMenuInterface} from './menu-interface';
import {MdMenuMissingError} from './menu-errors';
import {
ENTER,
Expand Down Expand Up @@ -47,7 +47,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
// the first item of the list when the menu is opened via the keyboard
private _openedFromKeyboard: boolean = false;

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

Expand Down Expand Up @@ -148,7 +148,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
* md-menu-trigger-for. If not, an exception is thrown.
*/
private _checkMenu() {
if (!this.menu || !(this.menu instanceof MdMenu)) {
if (!this.menu) {
throw new MdMenuMissingError();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {MdMenuTrigger} from './menu-trigger';
export {MdMenu} from './menu-directive';
export {MdMenuItem} from './menu-item';
export {MdMenuTrigger} from './menu-trigger';
export {MdMenuInterface} from './menu-interface';
export {MenuPositionX, MenuPositionY} from './menu-positions';


@NgModule({
Expand Down

0 comments on commit 68e8c55

Please sign in to comment.