@@ -4,29 +4,20 @@ import {
44 HostListener ,
55 Input ,
66 SimpleChanges ,
7- OnChanges
7+ OnChanges ,
8+ HostBinding
89} from "@angular/core" ;
910
1011@Component ( {
1112 selector : "ibm-context-menu" ,
1213 template : `
13- <ul
14- class="cds--context-menu cds--menu"
15- [ngClass]="{
16- 'cds--context-menu--root': root,
17- 'cds--menu--root': root,
18- 'cds--context-menu--open': open,
19- 'cds--menu--open': open
20- }"
21- role="menu"
22- tabindex="-1"
23- [ngStyle]="{
24- 'left.px': position.left,
25- 'top.px': position.top
26- }">
2714 <ng-content></ng-content>
28- </ul>
29- `
15+ ` ,
16+ styles : [ `
17+ :host {
18+ display: block;
19+ }
20+ ` ]
3021} )
3122export class ContextMenuComponent implements OnChanges {
3223 @Input ( ) root = true ;
@@ -36,6 +27,17 @@ export class ContextMenuComponent implements OnChanges {
3627 top : 0
3728 } ;
3829
30+ @HostBinding ( "class.cds--context-menu" ) contextMenu = true ;
31+ @HostBinding ( "class.cds--menu" ) menu = true ;
32+ @HostBinding ( "class.cds--context-menu--root" ) get contextMenuRoot ( ) { return this . root ; }
33+ @HostBinding ( "class.cds--menu--root" ) get menuRoot ( ) { return this . root ; }
34+ @HostBinding ( "class.cds--context-menu--open" ) get contextMenuOpen ( ) { return this . open ; }
35+ @HostBinding ( "class.cds--menu--open" ) get menuOpen ( ) { return this . open ; }
36+ @HostBinding ( "attr.role" ) role = "menu" ;
37+ @HostBinding ( "attr.tabindex" ) tabindex = "-1" ;
38+ @HostBinding ( "style.left.px" ) get leftPosition ( ) { return this . position . left ; }
39+ @HostBinding ( "style.top.px" ) get topPosition ( ) { return this . position . top ; }
40+
3941 constructor ( protected elementRef : ElementRef ) { }
4042
4143 ngOnChanges ( changes : SimpleChanges ) {
@@ -46,7 +48,7 @@ export class ContextMenuComponent implements OnChanges {
4648
4749 focusMenu ( ) {
4850 // wait until the next tick to let the DOM settle before changing the focus
49- const list = this . elementRef . nativeElement . querySelector ( "ul" ) as HTMLElement ;
51+ const list : HTMLElement = this . elementRef . nativeElement ;
5052 setTimeout ( ( ) => {
5153 if ( this . root ) {
5254 list . focus ( ) ;
@@ -59,8 +61,8 @@ export class ContextMenuComponent implements OnChanges {
5961
6062 @HostListener ( "keydown" , [ "$event" ] )
6163 handleNavigation ( event : KeyboardEvent ) {
62- const list : HTMLElement = this . elementRef . nativeElement . querySelector ( "ul" ) ;
63- const subMenus : HTMLElement [ ] = Array . from ( list . querySelectorAll ( "ul [role=menu]" ) ) ;
64+ const list : HTMLElement = this . elementRef . nativeElement ;
65+ const subMenus : HTMLElement [ ] = Array . from ( list . querySelectorAll ( "ibm-context-menu [role=menu]" ) ) ;
6466 const menuItems : HTMLElement [ ] = (
6567 Array . from ( list . querySelectorAll ( ".cds--context-menu-option, .cds--menu-option" ) ) as HTMLElement [ ] )
6668 . filter ( menuItem => ! subMenus . some ( subMenu => subMenu . contains ( menuItem ) )
0 commit comments