Skip to content

Commit 44fcde8

Browse files
committed
docs(material/menu): add docs for context menu
Sets up a live example showing how the context menu works.
1 parent 84ce6c4 commit 44fcde8

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.example-context-menu-area {
2+
display: flex;
3+
align-items: center;
4+
justify-content: center;
5+
width: 100%;
6+
height: 300px;
7+
max-width: 300px;
8+
border: dashed 1px;
9+
text-align: center;
10+
padding: 30px;
11+
box-sizing: border-box;
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<div class="example-context-menu-area" [matContextMenuTriggerFor]="contextMenu">
2+
Right click here to trigger a context menu
3+
</div>
4+
5+
<mat-menu #contextMenu>
6+
<button mat-menu-item>
7+
<mat-icon>content_cut</mat-icon>
8+
Cut
9+
</button>
10+
<button mat-menu-item>
11+
<mat-icon>content_copy</mat-icon>
12+
Copy
13+
</button>
14+
<button mat-menu-item>
15+
<mat-icon>content_paste</mat-icon>
16+
Paste
17+
</button>
18+
<button mat-menu-item>
19+
<mat-icon>print</mat-icon>
20+
Print
21+
</button>
22+
</mat-menu>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Component} from '@angular/core';
2+
import {MatMenuModule} from '@angular/material/menu';
3+
import {MatIconModule} from '@angular/material/icon';
4+
5+
/**
6+
* @title Context menu
7+
*/
8+
@Component({
9+
selector: 'context-menu-example',
10+
templateUrl: 'context-menu-example.html',
11+
styleUrl: './context-menu-example.css',
12+
imports: [MatMenuModule, MatIconModule],
13+
})
14+
export class ContextMenuExample {}

src/components-examples/material/menu/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export {MenuOverviewExample} from './menu-overview/menu-overview-example';
33
export {MenuPositionExample} from './menu-position/menu-position-example';
44
export {MenuNestedExample} from './menu-nested/menu-nested-example';
55
export {MenuHarnessExample} from './menu-harness/menu-harness-example';
6+
export {ContextMenuExample} from './context-menu/context-menu-example';

src/material/menu/menu.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ that should trigger the sub-menu:
4949
"file": "menu-nested-example.html",
5050
"region": "sub-menu"}) -->
5151

52+
### Context menu
53+
A context menu is menu that is triggered by right-clicking in a specific area, rather than
54+
clicking on a trigger element. It is re-positioned if the user right-clicks somewhere else in the
55+
area and will be closed if the user clicks away.
56+
57+
You can set up a `mat-menu` as a context menu by adding the `matContextMenuTriggerFor` directive
58+
to your container and binding it to a menu instance.
59+
60+
<!-- example(context-menu) -->
61+
5262
### Lazy rendering
5363
By default, the menu content will be initialized even when the panel is closed. To defer
5464
initialization until the menu is open, the content can be provided as an `ng-template`

0 commit comments

Comments
 (0)