Skip to content

Commit

Permalink
feat(menu): support icons
Browse files Browse the repository at this point in the history
  • Loading branch information
kara committed Nov 3, 2016
1 parent 1e86066 commit 03e38d1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/demo-app/menu/menu-demo.html
Expand Up @@ -39,7 +39,8 @@
</md-toolbar>

<md-menu x-position="before" #posXMenu="mdMenu" class="before">
<button md-menu-item *ngFor="let item of items" [disabled]="item.disabled">
<button md-menu-item *ngFor="let item of iconItems" [disabled]="item.disabled">
<md-icon>{{ item.icon }}</md-icon>
{{ item.text }}
</button>
</md-menu>
Expand Down
6 changes: 6 additions & 0 deletions src/demo-app/menu/menu-demo.ts
Expand Up @@ -16,5 +16,11 @@ export class MenuDemo {
{text: 'Sign Out'}
];

iconItems = [
{text: 'Redial', icon: 'dialpad'},
{text: 'Check voicemail', icon: 'voicemail', disabled: true},
{text: 'Disable alerts', icon: 'notifications_off'}
];

select(text: string) { this.selected = text; }
}
8 changes: 8 additions & 0 deletions src/lib/core/style/_menu-common.scss
Expand Up @@ -42,4 +42,12 @@ $md-menu-vertical-padding: 8px !default;
&[disabled] {
cursor: default;
}

md-icon {
margin-right: 16px;

[dir='rtl'] & {
margin-left: 16px;
}
}
}
28 changes: 28 additions & 0 deletions src/lib/menu/README.md
Expand Up @@ -84,6 +84,34 @@ class MyComp {
</md-menu>
```

### Adding an icon

Menus also support displaying `md-icon` elements before the menu item text.

*my-comp.html*
```html
<md-menu #menu="mdMenu">
<button md-menu-item>
<md-icon> dialpad </md-icon>
<span> Redial </span>
</button>
<button md-menu-item disabled>
<md-icon> voicemail </md-icon>
<span> Check voicemail </span>
</button>
<button md-menu-item>
<md-icon> notifications_off </md-icon>
<span> Disable alerts </span>
</button>
</md-menu>
```

Output:

<img src="https://material.angularjs.org/material2_assets/menu/icon_menu_closed.png">
<img src="https://material.angularjs.org/material2_assets/menu/icon_menu_open.png">


### Customizing menu position

By default, the menu will display after and below its trigger. You can change this display position
Expand Down
4 changes: 4 additions & 0 deletions src/lib/menu/_menu-theme.scss
Expand Up @@ -18,6 +18,10 @@
color: md-color($foreground, 'disabled');
}

md-icon {
color: md-color($foreground, 'icon');
}

&:hover:not([disabled]), &:focus:not([disabled]) {
background: md-color($background, 'hover');
}
Expand Down

0 comments on commit 03e38d1

Please sign in to comment.