@@ -9,6 +9,7 @@ import { NzButtonModule } from 'ng-zorro-antd/button';
9
9
import { dispatchFakeEvent } from 'ng-zorro-antd/core/testing' ;
10
10
import { NzIconModule } from 'ng-zorro-antd/icon' ;
11
11
import { provideNzIconsTesting } from 'ng-zorro-antd/icon/testing' ;
12
+ import { NzSubmenuTrigger } from 'ng-zorro-antd/menu/menu.types' ;
12
13
13
14
import { NzMenuItemComponent } from './menu-item.component' ;
14
15
import { NzMenuDirective } from './menu.directive' ;
@@ -271,6 +272,42 @@ describe('menu', () => {
271
272
expect ( mouseenterCallback ) . toHaveBeenCalledWith ( true ) ;
272
273
expect ( mouseenterCallback ) . toHaveBeenCalledTimes ( 1 ) ;
273
274
} ) ;
275
+ it ( 'should have "hover" as default trigger' , ( ) => {
276
+ fixture . detectChanges ( ) ;
277
+ const mouseenterCallback = jasmine . createSpy ( 'mouseenter callback' ) ;
278
+ const subs = testComponent . subs . toArray ( ) ;
279
+ const title = submenu . nativeElement . querySelector ( '.ant-menu-submenu-title' ) ;
280
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
281
+ ( subs [ 0 ] . nzSubmenuService as any ) . isMouseEnterTitleOrOverlay$ . subscribe ( mouseenterCallback ) ;
282
+ dispatchFakeEvent ( title , 'mouseenter' ) ;
283
+ fixture . detectChanges ( ) ;
284
+ expect ( mouseenterCallback ) . toHaveBeenCalledWith ( true ) ;
285
+ expect ( mouseenterCallback ) . toHaveBeenCalledTimes ( 1 ) ;
286
+ } ) ;
287
+ it ( 'should have not open with mouse hover if trigger is set to "click"' , ( ) => {
288
+ testComponent . nzTriggerSubMenuAction = 'click' ;
289
+ fixture . detectChanges ( ) ;
290
+ const mouseenterCallback = jasmine . createSpy ( 'mouseenter callback' ) ;
291
+ const subs = testComponent . subs . toArray ( ) ;
292
+ const title = submenu . nativeElement . querySelector ( '.ant-menu-submenu-title' ) ;
293
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
294
+ ( subs [ 0 ] . nzSubmenuService as any ) . isMouseEnterTitleOrOverlay$ . subscribe ( mouseenterCallback ) ;
295
+ dispatchFakeEvent ( title , 'mouseenter' ) ;
296
+ fixture . detectChanges ( ) ;
297
+ expect ( mouseenterCallback ) . toHaveBeenCalledTimes ( 0 ) ;
298
+ } ) ;
299
+ it ( 'should open with mouse click if trigger is set to "click"' , ( ) => {
300
+ testComponent . nzTriggerSubMenuAction = 'click' ;
301
+ fixture . detectChanges ( ) ;
302
+ const mouseenterCallback = jasmine . createSpy ( 'mouseenter callback' ) ;
303
+ const subs = testComponent . subs . toArray ( ) ;
304
+ const title = submenu . nativeElement . querySelector ( '.ant-menu-submenu-title' ) ;
305
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
306
+ ( subs [ 0 ] . nzSubmenuService as any ) . isMouseEnterTitleOrOverlay$ . subscribe ( mouseenterCallback ) ;
307
+ title . click ( ) ;
308
+ fixture . detectChanges ( ) ;
309
+ expect ( mouseenterCallback ) . toHaveBeenCalledTimes ( 1 ) ;
310
+ } ) ;
274
311
it ( 'should submenu mouseleave work' , ( ) => {
275
312
fixture . detectChanges ( ) ;
276
313
const mouseleaveCallback = jasmine . createSpy ( 'mouseleave callback' ) ;
@@ -524,7 +561,13 @@ describe('menu', () => {
524
561
imports : [ NzIconModule , NzMenuModule ] ,
525
562
template : `
526
563
<ul nz-menu [nzMode]="'horizontal'">
527
- <li nz-submenu nzMenuClassName="submenu" [nzOpen]="open" [style.width.px]="width">
564
+ <li
565
+ nz-submenu
566
+ [nzTriggerSubMenuAction]="nzTriggerSubMenuAction"
567
+ nzMenuClassName="submenu"
568
+ [nzOpen]="open"
569
+ [style.width.px]="width"
570
+ >
528
571
<span title>
529
572
<span nz-icon nzType="setting"></span>
530
573
Navigation Three - Submenu
@@ -567,6 +610,7 @@ export class NzTestMenuHorizontalComponent {
567
610
width = 200 ;
568
611
open = false ;
569
612
disabled = false ;
613
+ nzTriggerSubMenuAction : NzSubmenuTrigger = 'hover' ;
570
614
@ViewChildren ( NzSubMenuComponent ) subs ! : QueryList < NzSubMenuComponent > ;
571
615
@ViewChild ( 'menuitem' , { static : false , read : ElementRef } ) menuitem ! : ElementRef ;
572
616
@ViewChild ( 'menuitem1' , { static : false , read : ElementRef } ) menuitem1 ! : ElementRef ;
0 commit comments