@@ -320,6 +320,34 @@ describe("calcite-tooltip", () => {
320
320
expect ( await positionContainer . isVisible ( ) ) . toBe ( true ) ;
321
321
} ) ;
322
322
323
+ it ( "should not open when hover event is prevented" , async ( ) => {
324
+ const page = await newE2EPage ( ) ;
325
+
326
+ await page . setContent (
327
+ `<calcite-tooltip reference-element="ref">content</calcite-tooltip><div id="ref">referenceElement</div>` ,
328
+ ) ;
329
+
330
+ await page . waitForChanges ( ) ;
331
+
332
+ const positionContainer = await page . find ( `calcite-tooltip >>> .${ CSS . positionContainer } ` ) ;
333
+
334
+ expect ( await positionContainer . isVisible ( ) ) . toBe ( false ) ;
335
+
336
+ await page . $eval ( "#ref" , ( ref ) => {
337
+ ref . addEventListener ( "pointermove" , ( event ) => {
338
+ event . preventDefault ( ) ;
339
+ } ) ;
340
+ } ) ;
341
+
342
+ const ref = await page . find ( "#ref" ) ;
343
+
344
+ await ref . hover ( ) ;
345
+
346
+ await page . waitForTimeout ( TOOLTIP_OPEN_DELAY_MS ) ;
347
+
348
+ expect ( await positionContainer . isVisible ( ) ) . toBe ( false ) ;
349
+ } ) ;
350
+
323
351
it ( "should honor hover interaction with span inside" , async ( ) => {
324
352
const page = await newE2EPage ( ) ;
325
353
@@ -426,6 +454,34 @@ describe("calcite-tooltip", () => {
426
454
expect ( await tooltip . getProperty ( "open" ) ) . toBe ( false ) ;
427
455
} ) ;
428
456
457
+ it ( "should not open if focus event is prevented" , async ( ) => {
458
+ const page = await newE2EPage ( ) ;
459
+
460
+ await page . setContent ( html `
461
+ < button id ="test "> test</ button >
462
+ < calcite-tooltip reference-element ="ref "> Content</ calcite-tooltip >
463
+ < button id ="ref "> Button</ button >
464
+ ` ) ;
465
+
466
+ await page . waitForChanges ( ) ;
467
+
468
+ const tooltip = await page . find ( "calcite-tooltip" ) ;
469
+
470
+ expect ( await tooltip . getProperty ( "open" ) ) . toBe ( false ) ;
471
+
472
+ await page . $eval ( "#ref" , ( ref ) => {
473
+ ref . addEventListener ( "focusin" , ( event ) => {
474
+ event . preventDefault ( ) ;
475
+ } ) ;
476
+
477
+ ref . dispatchEvent ( new FocusEvent ( "focusin" , { bubbles : true , cancelable : true } ) ) ;
478
+ } ) ;
479
+
480
+ await page . waitForChanges ( ) ;
481
+
482
+ expect ( await tooltip . getProperty ( "open" ) ) . toBe ( false ) ;
483
+ } ) ;
484
+
429
485
it ( "should handle mouse events" , async ( ) => {
430
486
const page = await newE2EPage ( ) ;
431
487
@@ -547,6 +603,45 @@ describe("calcite-tooltip", () => {
547
603
await assertEscapeKeyCanceled ( page , true ) ;
548
604
} ) ;
549
605
606
+ it ( "should not close with ESC key if event is prevented" , async ( ) => {
607
+ const page = await newE2EPage ( ) ;
608
+
609
+ await page . setContent ( html `
610
+ < calcite-tooltip reference-element ="ref "> Content</ calcite-tooltip >
611
+ < button id ="ref "> Button</ button >
612
+ ` ) ;
613
+
614
+ await page . waitForChanges ( ) ;
615
+
616
+ const tooltip = await page . find ( "calcite-tooltip" ) ;
617
+
618
+ expect ( await tooltip . getProperty ( "open" ) ) . toBe ( false ) ;
619
+
620
+ const referenceElement = await page . find ( "#ref" ) ;
621
+
622
+ await referenceElement . focus ( ) ;
623
+
624
+ await referenceElement . hover ( ) ;
625
+
626
+ await page . waitForTimeout ( TOOLTIP_OPEN_DELAY_MS ) ;
627
+
628
+ await page . waitForChanges ( ) ;
629
+
630
+ expect ( await tooltip . getProperty ( "open" ) ) . toBe ( true ) ;
631
+
632
+ await page . evaluate ( ( ) => {
633
+ document . body . addEventListener ( "keydown" , ( event ) => {
634
+ if ( event . key === "Escape" ) {
635
+ event . preventDefault ( ) ;
636
+ }
637
+ } ) ;
638
+ } ) ;
639
+
640
+ await dispatchKeydownEvent ( page , "#ref" , "Escape" ) ;
641
+
642
+ expect ( await tooltip . getProperty ( "open" ) ) . toBe ( true ) ;
643
+ } ) ;
644
+
550
645
it ( "should only open the last focused tooltip" , async ( ) => {
551
646
const page = await newE2EPage ( ) ;
552
647
@@ -1175,6 +1270,25 @@ describe("calcite-tooltip", () => {
1175
1270
expect ( await tooltip . getProperty ( "open" ) ) . toBe ( false ) ;
1176
1271
} ) ;
1177
1272
1273
+ it ( "should not open when click event is prevented" , async ( ) => {
1274
+ const page = await newE2EPage ( ) ;
1275
+ await page . setContent ( pageContent ) ;
1276
+ await skipAnimations ( page ) ;
1277
+ await page . waitForChanges ( ) ;
1278
+ const tooltip = await page . find ( "calcite-tooltip" ) ;
1279
+
1280
+ await page . $eval ( "#ref" , ( ref ) => {
1281
+ ref . addEventListener ( "click" , ( event ) => {
1282
+ event . preventDefault ( ) ;
1283
+ } ) ;
1284
+
1285
+ ref . dispatchEvent ( new MouseEvent ( "click" , { bubbles : true , cancelable : true } ) ) ;
1286
+ } ) ;
1287
+
1288
+ await page . waitForChanges ( ) ;
1289
+ expect ( await tooltip . getProperty ( "open" ) ) . toBe ( false ) ;
1290
+ } ) ;
1291
+
1178
1292
it ( "should work when focusing on a reference element first" , async ( ) => {
1179
1293
const page = await newE2EPage ( ) ;
1180
1294
await page . setContent ( pageContent ) ;
0 commit comments