@@ -7,6 +7,7 @@ import {Platform} from '@angular/cdk/platform';
7
7
import {
8
8
createFakeEvent ,
9
9
createKeyboardEvent ,
10
+ createMouseEvent ,
10
11
dispatchEvent ,
11
12
dispatchFakeEvent ,
12
13
dispatchKeyboardEvent ,
@@ -237,6 +238,35 @@ describe('MDC-based MatTooltip', () => {
237
238
expect ( tooltipDirective . _getOverlayPosition ( ) . fallback . overlayX ) . toBe ( 'end' ) ;
238
239
} ) ) ;
239
240
241
+ it ( 'should be able to disable tooltip interactivity' , fakeAsync ( ( ) => {
242
+ TestBed . resetTestingModule ( )
243
+ . configureTestingModule ( {
244
+ imports : [ MatTooltipModule , OverlayModule , NoopAnimationsModule ] ,
245
+ declarations : [ TooltipDemoWithoutPositionBinding ] ,
246
+ providers : [
247
+ {
248
+ provide : MAT_TOOLTIP_DEFAULT_OPTIONS ,
249
+ useValue : { disableTooltipInteractivity : true } ,
250
+ } ,
251
+ ] ,
252
+ } )
253
+ . compileComponents ( ) ;
254
+
255
+ const newFixture = TestBed . createComponent ( TooltipDemoWithoutPositionBinding ) ;
256
+ newFixture . detectChanges ( ) ;
257
+ tooltipDirective = newFixture . debugElement
258
+ . query ( By . css ( 'button' ) ) !
259
+ . injector . get < MatTooltip > ( MatTooltip ) ;
260
+
261
+ tooltipDirective . show ( ) ;
262
+ newFixture . detectChanges ( ) ;
263
+ tick ( ) ;
264
+
265
+ expect ( tooltipDirective . _overlayRef ?. overlayElement . classList ) . toContain (
266
+ 'mat-mdc-tooltip-panel-non-interactive' ,
267
+ ) ;
268
+ } ) ) ;
269
+
240
270
it ( 'should set a css class on the overlay panel element' , fakeAsync ( ( ) => {
241
271
tooltipDirective . show ( ) ;
242
272
fixture . detectChanges ( ) ;
@@ -926,6 +956,91 @@ describe('MDC-based MatTooltip', () => {
926
956
expect ( tooltipElement . classList ) . toContain ( 'mdc-tooltip--multiline' ) ;
927
957
expect ( tooltipDirective . _tooltipInstance ?. _isMultiline ) . toBeTrue ( ) ;
928
958
} ) ) ;
959
+
960
+ it ( 'should hide on mouseleave on the trigger' , fakeAsync ( ( ) => {
961
+ // We don't bind mouse events on mobile devices.
962
+ if ( platform . IOS || platform . ANDROID ) {
963
+ return ;
964
+ }
965
+
966
+ dispatchMouseEvent ( fixture . componentInstance . button . nativeElement , 'mouseenter' ) ;
967
+ fixture . detectChanges ( ) ;
968
+ tick ( 0 ) ;
969
+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
970
+
971
+ dispatchMouseEvent ( fixture . componentInstance . button . nativeElement , 'mouseleave' ) ;
972
+ fixture . detectChanges ( ) ;
973
+ tick ( 0 ) ;
974
+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( false ) ;
975
+ } ) ) ;
976
+
977
+ it ( 'should not hide on mouseleave if the pointer goes from the trigger to the tooltip' , fakeAsync ( ( ) => {
978
+ // We don't bind mouse events on mobile devices.
979
+ if ( platform . IOS || platform . ANDROID ) {
980
+ return ;
981
+ }
982
+
983
+ dispatchMouseEvent ( fixture . componentInstance . button . nativeElement , 'mouseenter' ) ;
984
+ fixture . detectChanges ( ) ;
985
+ tick ( 0 ) ;
986
+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
987
+
988
+ const tooltipElement = overlayContainerElement . querySelector (
989
+ '.mat-mdc-tooltip' ,
990
+ ) as HTMLElement ;
991
+ const event = createMouseEvent ( 'mouseleave' ) ;
992
+ Object . defineProperty ( event , 'relatedTarget' , { value : tooltipElement } ) ;
993
+
994
+ dispatchEvent ( fixture . componentInstance . button . nativeElement , event ) ;
995
+ fixture . detectChanges ( ) ;
996
+ tick ( 0 ) ;
997
+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
998
+ } ) ) ;
999
+
1000
+ it ( 'should hide on mouseleave on the tooltip' , fakeAsync ( ( ) => {
1001
+ // We don't bind mouse events on mobile devices.
1002
+ if ( platform . IOS || platform . ANDROID ) {
1003
+ return ;
1004
+ }
1005
+
1006
+ dispatchMouseEvent ( fixture . componentInstance . button . nativeElement , 'mouseenter' ) ;
1007
+ fixture . detectChanges ( ) ;
1008
+ tick ( 0 ) ;
1009
+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
1010
+
1011
+ const tooltipElement = overlayContainerElement . querySelector (
1012
+ '.mat-mdc-tooltip' ,
1013
+ ) as HTMLElement ;
1014
+ dispatchMouseEvent ( tooltipElement , 'mouseleave' ) ;
1015
+ fixture . detectChanges ( ) ;
1016
+ tick ( 0 ) ;
1017
+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( false ) ;
1018
+ } ) ) ;
1019
+
1020
+ it ( 'should not hide on mouseleave if the pointer goes from the tooltip to the trigger' , fakeAsync ( ( ) => {
1021
+ // We don't bind mouse events on mobile devices.
1022
+ if ( platform . IOS || platform . ANDROID ) {
1023
+ return ;
1024
+ }
1025
+
1026
+ dispatchMouseEvent ( fixture . componentInstance . button . nativeElement , 'mouseenter' ) ;
1027
+ fixture . detectChanges ( ) ;
1028
+ tick ( 0 ) ;
1029
+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
1030
+
1031
+ const tooltipElement = overlayContainerElement . querySelector (
1032
+ '.mat-mdc-tooltip' ,
1033
+ ) as HTMLElement ;
1034
+ const event = createMouseEvent ( 'mouseleave' ) ;
1035
+ Object . defineProperty ( event , 'relatedTarget' , {
1036
+ value : fixture . componentInstance . button . nativeElement ,
1037
+ } ) ;
1038
+
1039
+ dispatchEvent ( tooltipElement , event ) ;
1040
+ fixture . detectChanges ( ) ;
1041
+ tick ( 0 ) ;
1042
+ expect ( tooltipDirective . _isTooltipVisible ( ) ) . toBe ( true ) ;
1043
+ } ) ) ;
929
1044
} ) ;
930
1045
931
1046
describe ( 'fallback positions' , ( ) => {
0 commit comments