File tree Expand file tree Collapse file tree 3 files changed +44
-10
lines changed Expand file tree Collapse file tree 3 files changed +44
-10
lines changed Original file line number Diff line number Diff line change 22
33.menu-item {
44 @include popover-menu-item ;
5+
6+ & .disabled {
7+ opacity : 0.4 ;
8+ cursor : not-allowed ;
9+ }
510}
Original file line number Diff line number Diff line change @@ -27,4 +27,24 @@ describe('Menu Item Component', () => {
2727 expect ( spectator . query ( IconComponent ) ?. icon ) . toBe ( IconType . MoreHorizontal ) ;
2828 expect ( spectator . query ( IconComponent ) ?. color ) . toBe ( Color . Gray1 ) ;
2929 } ) ) ;
30+
31+ test ( 'should disable menu item as expected' , fakeAsync ( ( ) => {
32+ const spectator = createHost (
33+ '<ht-menu-item [icon]="icon" [label]="label" [iconColor]="iconColor" [disabled]="disabled"></ht-menu-item>' ,
34+ {
35+ hostProps : {
36+ icon : IconType . MoreHorizontal ,
37+ label : 'Item' ,
38+ iconColor : Color . Gray1 ,
39+ disabled : true
40+ }
41+ }
42+ ) ;
43+ expect ( spectator . query ( '.menu-item' ) ) . toExist ( ) ;
44+ expect ( spectator . query ( '.icon' ) ) . toExist ( ) ;
45+ expect ( spectator . query ( '.label' ) ) . toHaveText ( 'Item' ) ;
46+ expect ( spectator . query ( IconComponent ) ?. icon ) . toBe ( IconType . MoreHorizontal ) ;
47+ expect ( spectator . query ( IconComponent ) ?. color ) . toBe ( Color . Gray1 ) ;
48+ expect ( spectator . query ( '.menu-item' ) ?. classList . contains ( 'disabled' ) ) . toBe ( true ) ;
49+ } ) ) ;
3050} ) ;
Original file line number Diff line number Diff line change @@ -6,16 +6,18 @@ import { IconSize } from '../../icon/icon-size';
66 selector : 'ht-menu-item' ,
77 changeDetection : ChangeDetectionStrategy . OnPush ,
88 styleUrls : [ './menu-item.component.scss' ] ,
9- template : `<div class="menu-item">
10- <ht-icon
11- class="icon"
12- *ngIf="this.icon"
13- [icon]="this.icon"
14- size="${ IconSize . Small } "
15- [color]="this.iconColor"
16- ></ht-icon>
17- <span class="label">{{ this.label }}</span>
18- </div>`
9+ template : `<ht-event-blocker event="click" class="menu-item-container" [enabled]="this.disabled"
10+ ><div class="menu-item" [ngClass]="this.getStyleClasses()">
11+ <ht-icon
12+ class="icon"
13+ *ngIf="this.icon"
14+ [icon]="this.icon"
15+ size="${ IconSize . Small } "
16+ [color]="this.iconColor"
17+ ></ht-icon>
18+ <span class="label">{{ this.label }}</span>
19+ </div></ht-event-blocker
20+ >`
1921} )
2022export class MenuItemComponent {
2123 @Input ( )
@@ -26,4 +28,11 @@ export class MenuItemComponent {
2628
2729 @Input ( )
2830 public iconColor ?: string ;
31+
32+ @Input ( )
33+ public disabled ?: boolean ;
34+
35+ public getStyleClasses ( ) : string [ ] {
36+ return this . disabled ? [ 'disabled' ] : [ ] ;
37+ }
2938}
You can’t perform that action at this time.
0 commit comments