1+ /* eslint-disable max-classes-per-file */
2+
13import React from 'react' ;
4+ import ReactDOM from 'react-dom' ;
25import { mount } from 'enzyme' ;
36import { act } from 'react-dom/test-utils' ;
47import { spyElementPrototypes } from 'rc-util/lib/test/domHook' ;
58import Portal from 'rc-util/lib/Portal' ;
69import Trigger from '../src' ;
7-
8- const autoAdjustOverflow = {
9- adjustX : 1 ,
10- adjustY : 1 ,
11- } ;
12-
13- const targetOffsetG = [ 0 , 0 ] ;
14-
15- export const placementAlignMap = {
16- left : {
17- points : [ 'cr' , 'cl' ] ,
18- overflow : autoAdjustOverflow ,
19- offset : [ - 3 , 0 ] ,
20- targetOffsetG,
21- } ,
22- right : {
23- points : [ 'cl' , 'cr' ] ,
24- overflow : autoAdjustOverflow ,
25- offset : [ 3 , 0 ] ,
26- targetOffsetG,
27- } ,
28- top : {
29- points : [ 'bc' , 'tc' ] ,
30- overflow : autoAdjustOverflow ,
31- offset : [ 0 , - 3 ] ,
32- targetOffsetG,
33- } ,
34- bottom : {
35- points : [ 'tc' , 'bc' ] ,
36- overflow : autoAdjustOverflow ,
37- offset : [ 0 , 3 ] ,
38- targetOffsetG,
39- } ,
40- topLeft : {
41- points : [ 'bl' , 'tl' ] ,
42- overflow : autoAdjustOverflow ,
43- offset : [ 0 , - 3 ] ,
44- targetOffsetG,
45- } ,
46- topRight : {
47- points : [ 'br' , 'tr' ] ,
48- overflow : autoAdjustOverflow ,
49- offset : [ 0 , - 3 ] ,
50- targetOffsetG,
51- } ,
52- bottomRight : {
53- points : [ 'tr' , 'br' ] ,
54- overflow : autoAdjustOverflow ,
55- offset : [ 0 , 3 ] ,
56- targetOffsetG,
57- } ,
58- bottomLeft : {
59- points : [ 'tl' , 'bl' ] ,
60- overflow : autoAdjustOverflow ,
61- offset : [ 0 , 3 ] ,
62- targetOffsetG,
63- } ,
64- } ;
10+ import { placementAlignMap } from './util' ;
6511
6612describe ( 'Trigger.Basic' , ( ) => {
6713 beforeEach ( ( ) => {
@@ -147,12 +93,7 @@ describe('Trigger.Basic', () => {
14793 ) ;
14894
14995 wrapper . trigger ( ) ;
150- expect (
151- wrapper
152- . find ( 'Popup' )
153- . find ( '.x-content' )
154- . text ( ) ,
155- ) . toBe ( 'tooltip2' ) ;
96+ expect ( wrapper . find ( 'Popup' ) . find ( '.x-content' ) . text ( ) ) . toBe ( 'tooltip2' ) ;
15697
15798 wrapper . trigger ( ) ;
15899 expect ( wrapper . isHidden ( ) ) . toBeTruthy ( ) ;
@@ -173,12 +114,7 @@ describe('Trigger.Basic', () => {
173114 ) ;
174115
175116 wrapper . trigger ( ) ;
176- expect (
177- wrapper
178- . find ( 'Popup' )
179- . find ( '.x-content' )
180- . text ( ) ,
181- ) . toBe ( 'tooltip3' ) ;
117+ expect ( wrapper . find ( 'Popup' ) . find ( '.x-content' ) . text ( ) ) . toBe ( 'tooltip3' ) ;
182118
183119 wrapper . trigger ( ) ;
184120 expect ( wrapper . isHidden ( ) ) . toBeTruthy ( ) ;
@@ -509,7 +445,7 @@ describe('Trigger.Basic', () => {
509445 } ) ;
510446
511447 describe ( 'stretch' , ( ) => {
512- const createTrigger = stretch =>
448+ const createTrigger = ( stretch ) =>
513449 mount (
514450 < Trigger
515451 action = { [ 'click' ] }
@@ -542,7 +478,7 @@ describe('Trigger.Basic', () => {
542478 domSpy . mockRestore ( ) ;
543479 } ) ;
544480
545- [ 'width' , 'height' , 'minWidth' , 'minHeight' ] . forEach ( prop => {
481+ [ 'width' , 'height' , 'minWidth' , 'minHeight' ] . forEach ( ( prop ) => {
546482 it ( prop , ( ) => {
547483 const wrapper = createTrigger ( prop ) ;
548484
@@ -643,7 +579,7 @@ describe('Trigger.Basic', () => {
643579 < div >
644580 < button
645581 type = "button"
646- onMouseDown = { e => {
582+ onMouseDown = { ( e ) => {
647583 e . preventDefault ( ) ;
648584 e . stopPropagation ( ) ;
649585 } }
@@ -687,7 +623,7 @@ describe('Trigger.Basic', () => {
687623
688624 describe ( 'getContainer' , ( ) => {
689625 it ( 'not trigger when dom not ready' , ( ) => {
690- const getPopupContainer = jest . fn ( node => node . parentElement ) ;
626+ const getPopupContainer = jest . fn ( ( node ) => node . parentElement ) ;
691627
692628 function Demo ( ) {
693629 return (
@@ -740,4 +676,65 @@ describe('Trigger.Basic', () => {
740676 wrapper . unmount ( ) ;
741677 } ) ;
742678 } ) ;
679+
680+ // https://github.com/ant-design/ant-design/issues/30116
681+ it ( 'createPortal should also work with stopPropagation' , ( ) => {
682+ const root = document . createElement ( 'div' ) ;
683+ document . body . appendChild ( root ) ;
684+
685+ const div = document . createElement ( 'div' ) ;
686+ document . body . appendChild ( div ) ;
687+
688+ const OuterContent = ( { container } ) => {
689+ return ReactDOM . createPortal (
690+ < button
691+ onMouseDown = { ( e ) => {
692+ e . stopPropagation ( ) ;
693+ } }
694+ >
695+ Stop Pop
696+ </ button > ,
697+ container ,
698+ ) ;
699+ } ;
700+
701+ const Demo = ( ) => {
702+ return (
703+ < Trigger
704+ action = { [ 'click' ] }
705+ popup = {
706+ < strong className = "x-content" >
707+ tooltip2
708+ < OuterContent container = { div } />
709+ </ strong >
710+ }
711+ >
712+ < div className = "target" > click</ div >
713+ </ Trigger >
714+ ) ;
715+ } ;
716+
717+ const wrapper = mount ( < Demo /> , { attachTo : root } ) ;
718+
719+ wrapper . find ( '.target' ) . simulate ( 'click' ) ;
720+ expect ( wrapper . isHidden ( ) ) . toBeFalsy ( ) ;
721+
722+ // Click should not close
723+ wrapper . find ( 'button' ) . simulate ( 'mouseDown' ) ;
724+
725+ // Mock document mouse click event
726+ act ( ( ) => {
727+ const mouseEvent = new MouseEvent ( 'mousedown' ) ;
728+ document . dispatchEvent ( mouseEvent ) ;
729+ wrapper . update ( ) ;
730+ } ) ;
731+
732+ wrapper . update ( ) ;
733+ expect ( wrapper . isHidden ( ) ) . toBeFalsy ( ) ;
734+
735+ wrapper . unmount ( ) ;
736+
737+ document . body . removeChild ( div ) ;
738+ document . body . removeChild ( root ) ;
739+ } ) ;
743740} ) ;
0 commit comments