File tree Expand file tree Collapse file tree 5 files changed +59
-0
lines changed Expand file tree Collapse file tree 5 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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 { }
Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ export {MenuOverviewExample} from './menu-overview/menu-overview-example';
3
3
export { MenuPositionExample } from './menu-position/menu-position-example' ;
4
4
export { MenuNestedExample } from './menu-nested/menu-nested-example' ;
5
5
export { MenuHarnessExample } from './menu-harness/menu-harness-example' ;
6
+ export { ContextMenuExample } from './context-menu/context-menu-example' ;
Original file line number Diff line number Diff line change @@ -49,6 +49,16 @@ that should trigger the sub-menu:
49
49
"file": "menu-nested-example.html",
50
50
"region": "sub-menu"}) -->
51
51
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
+
52
62
### Lazy rendering
53
63
By default, the menu content will be initialized even when the panel is closed. To defer
54
64
initialization until the menu is open, the content can be provided as an ` ng-template `
You can’t perform that action at this time.
0 commit comments