Skip to content

Commit 982cdaa

Browse files
karajelbourn
authored andcommitted
feat(menu): support icons (#1702)
1 parent 7e08468 commit 982cdaa

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

src/demo-app/menu/menu-demo.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
</md-toolbar>
4040

4141
<md-menu x-position="before" #posXMenu="mdMenu" class="before">
42-
<button md-menu-item *ngFor="let item of items" [disabled]="item.disabled">
42+
<button md-menu-item *ngFor="let item of iconItems" [disabled]="item.disabled">
43+
<md-icon>{{ item.icon }}</md-icon>
4344
{{ item.text }}
4445
</button>
4546
</md-menu>

src/demo-app/menu/menu-demo.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ export class MenuDemo {
1616
{text: 'Sign Out'}
1717
];
1818

19+
iconItems = [
20+
{text: 'Redial', icon: 'dialpad'},
21+
{text: 'Check voicemail', icon: 'voicemail', disabled: true},
22+
{text: 'Disable alerts', icon: 'notifications_off'}
23+
];
24+
1925
select(text: string) { this.selected = text; }
2026
}

src/lib/core/style/_menu-common.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,12 @@ $md-menu-vertical-padding: 8px !default;
4242
&[disabled] {
4343
cursor: default;
4444
}
45+
46+
md-icon {
47+
margin-right: 16px;
48+
49+
[dir='rtl'] & {
50+
margin-left: 16px;
51+
}
52+
}
4553
}

src/lib/menu/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,34 @@ class MyComp {
8484
</md-menu>
8585
```
8686

87+
### Adding an icon
88+
89+
Menus also support displaying `md-icon` elements before the menu item text.
90+
91+
*my-comp.html*
92+
```html
93+
<md-menu #menu="mdMenu">
94+
<button md-menu-item>
95+
<md-icon> dialpad </md-icon>
96+
<span> Redial </span>
97+
</button>
98+
<button md-menu-item disabled>
99+
<md-icon> voicemail </md-icon>
100+
<span> Check voicemail </span>
101+
</button>
102+
<button md-menu-item>
103+
<md-icon> notifications_off </md-icon>
104+
<span> Disable alerts </span>
105+
</button>
106+
</md-menu>
107+
```
108+
109+
Output:
110+
111+
<img src="https://material.angularjs.org/material2_assets/menu/icon_menu_closed.png">
112+
<img src="https://material.angularjs.org/material2_assets/menu/icon_menu_open.png">
113+
114+
87115
### Customizing menu position
88116

89117
By default, the menu will display after and below its trigger. You can change this display position

src/lib/menu/_menu-theme.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
color: md-color($foreground, 'disabled');
1919
}
2020

21+
md-icon {
22+
color: md-color($foreground, 'icon');
23+
}
24+
2125
&:hover:not([disabled]), &:focus:not([disabled]) {
2226
background: md-color($background, 'hover');
2327
}

0 commit comments

Comments
 (0)