Skip to content

Commit 36b24de

Browse files
committed
improvements
1 parent 98406ae commit 36b24de

File tree

7 files changed

+49
-44
lines changed

7 files changed

+49
-44
lines changed

e2e/components/menu/menu-page.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ export class MenuPage {
1414

1515
body() { return element(by.tagName('body')); }
1616

17-
firstItem() { return element(by.id('one')); }
18-
19-
secondItem() { return element(by.id('two')); }
20-
21-
thirdItem() { return element(by.id('three')); }
17+
items(index: number) {
18+
return element.all(by.css('[md-menu-item]')).get(index);
19+
}
2220

2321
textArea() { return element(by.id('text')); }
2422

e2e/components/menu/menu.e2e.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
import { MenuPage } from './menu-page';
22

3-
describe('menu', function () {
3+
describe('menu', () => {
44
let page: MenuPage;
55

66
beforeEach(function() {
77
page = new MenuPage();
88
});
99

10-
it('should open menu when the trigger is clicked', function () {
10+
it('should open menu when the trigger is clicked', () => {
1111
page.expectMenuPresent(false);
1212
page.trigger().click();
1313

1414
page.expectMenuPresent(true);
1515
expect(page.menu().getText()).toEqual("One\nTwo\nThree");
1616
});
1717

18-
it('should close menu when area outside menu is clicked', function () {
18+
it('should close menu when area outside menu is clicked', () => {
1919
page.trigger().click();
2020
page.body().click();
2121
page.expectMenuPresent(false);
2222
});
2323

24-
it('should close menu when menu item is clicked', function () {
24+
it('should close menu when menu item is clicked', () => {
2525
page.trigger().click();
26-
page.firstItem().click();
26+
page.items(0).click();
2727
page.expectMenuPresent(false);
2828
});
2929

30-
it('should run click handlers on regular menu items', function() {
30+
it('should run click handlers on regular menu items', () => {
3131
page.trigger().click();
32-
page.firstItem().click();
32+
page.items(0).click();
3333
expect(page.getResultText()).toEqual('one');
3434

3535
page.trigger().click();
36-
page.secondItem().click();
36+
page.items(1).click();
3737
expect(page.getResultText()).toEqual('two');
3838
});
3939

40-
it('should run not run click handlers on disabled menu items', function() {
40+
it('should run not run click handlers on disabled menu items', () => {
4141
page.trigger().click();
42-
page.thirdItem().click();
42+
page.items(2).click();
4343
expect(page.getResultText()).toEqual('');
4444
});
4545

46-
it('should support multiple triggers opening the same menu', function() {
46+
it('should support multiple triggers opening the same menu', () => {
4747
page.triggerTwo().click();
4848
expect(page.menu().getText()).toEqual("One\nTwo\nThree");
4949
page.expectMenuAlignedWith(page.menu(), 'trigger-two');
@@ -68,7 +68,7 @@ describe('menu', function () {
6868

6969
describe('position - ', () => {
7070

71-
it('should default menu alignment to "after below" when not set', function() {
71+
it('should default menu alignment to "after below" when not set', () => {
7272
page.trigger().click();
7373

7474
// menu.x should equal trigger.x, menu.y should equal trigger.y

src/components/menu/menu-positions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export type MenuPositionX = 'before' | 'after';
3+
4+
export type MenuPositionY = 'above' | 'below';

src/components/menu/menu.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $md-menu-vertical-padding: 8px !default;
2323

2424
// max height must be 100% of the viewport height + one row height
2525
max-height: calc(100vh + 48px);
26-
overflow: scroll;
26+
overflow: auto;
2727
-webkit-overflow-scrolling: touch; // for momentum scroll on mobile
2828

2929
background: md-color($md-background, 'card');

src/components/menu/menu.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import {
66
Attribute,
77
Component,
88
EventEmitter,
9+
Input,
910
Output,
1011
TemplateRef,
1112
ViewChild,
1213
ViewEncapsulation
1314
} from '@angular/core';
15+
import {MenuPositionX, MenuPositionY} from './menu-positions';
1416
import {MdMenuInvalidPositionX, MdMenuInvalidPositionY} from './menu-errors';
1517

1618
@Component({
@@ -24,53 +26,54 @@ import {MdMenuInvalidPositionX, MdMenuInvalidPositionY} from './menu-errors';
2426
})
2527
export class MdMenu {
2628
private _showClickCatcher: boolean = false;
29+
30+
// config object to be passed into the menu's ngClass
2731
private _classList: Object;
28-
positionX: 'before' | 'after' = 'after';
29-
positionY: 'above' | 'below' = 'below';
3032

31-
@Output() close = new EventEmitter;
33+
positionX: MenuPositionX = 'after';
34+
positionY: MenuPositionY = 'below';
35+
3236
@ViewChild(TemplateRef) templateRef: TemplateRef<any>;
3337

34-
constructor(@Attribute('x-position') posX: 'before' | 'after',
35-
@Attribute('y-position') posY: 'above' | 'below',
36-
@Attribute('class') classes: string) {
38+
constructor(@Attribute('x-position') posX: MenuPositionX,
39+
@Attribute('y-position') posY: MenuPositionY) {
3740
if (posX) { this._setPositionX(posX); }
3841
if (posY) { this._setPositionY(posY); }
39-
this._mirrorHostClasses(classes);
40-
}
41-
42-
/**
43-
* This function toggles the display of the menu's click catcher element.
44-
* This element covers the viewport when the menu is open to detect clicks outside the menu.
45-
* TODO: internal
46-
*/
47-
_setClickCatcher(bool: boolean): void {
48-
this._showClickCatcher = bool;
4942
}
5043

5144
/**
5245
* This method takes classes set on the host md-menu element and applies them on the
5346
* menu template that displays in the overlay container. Otherwise, it's difficult
5447
* to style the containing menu from outside the component.
55-
* @param classes: list of class names
48+
* @param classes list of class names
5649
*/
57-
private _mirrorHostClasses(classes: string): void {
58-
if (!classes) { return; }
59-
50+
@Input('class')
51+
set classList(classes: string) {
6052
this._classList = classes.split(' ').reduce((obj: any, className: string) => {
6153
obj[className] = true;
6254
return obj;
6355
}, {});
6456
}
6557

66-
private _setPositionX(pos: 'before' | 'after'): void {
58+
@Output() close = new EventEmitter;
59+
60+
/**
61+
* This function toggles the display of the menu's click catcher element.
62+
* This element covers the viewport when the menu is open to detect clicks outside the menu.
63+
* TODO: internal
64+
*/
65+
_setClickCatcher(bool: boolean): void {
66+
this._showClickCatcher = bool;
67+
}
68+
69+
private _setPositionX(pos: MenuPositionX): void {
6770
if ( pos !== 'before' && pos !== 'after') {
6871
throw new MdMenuInvalidPositionX();
6972
}
7073
this.positionX = pos;
7174
}
7275

73-
private _setPositionY(pos: 'above' | 'below'): void {
76+
private _setPositionY(pos: MenuPositionY): void {
7477
if ( pos !== 'above' && pos !== 'below') {
7578
throw new MdMenuInvalidPositionY();
7679
}

src/core/style/_sidenav-mixins.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* This mixin ensures an element spans the whole viewport.*/
22
@mixin md-fullscreen {
3-
position: absolute;
3+
position: fixed;
44
top: 0;
55
left: 0;
66
right: 0;

src/e2e-app/menu/menu-e2e.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<button [md-menu-trigger-for]="menu" id="trigger-two">TRIGGER 2</button>
66

77
<md-menu #menu="mdMenu" class="custom">
8-
<button md-menu-item id="one" (click)="selected='one'">One</button>
9-
<button md-menu-item id="two" (click)="selected='two'">Two</button>
10-
<button md-menu-item id="three" (click)="selected='three'" disabled>Three</button>
8+
<button md-menu-item (click)="selected='one'">One</button>
9+
<button md-menu-item (click)="selected='two'">Two</button>
10+
<button md-menu-item (click)="selected='three'" disabled>Three</button>
1111
</md-menu>
1212

1313
<button [md-menu-trigger-for]="beforeMenu" id="before-t">

0 commit comments

Comments
 (0)