|
3 | 3 | import { act, cleanup, fireEvent, render } from '@testing-library/react';
|
4 | 4 | import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
|
5 | 5 | import React, { StrictMode, createRef } from 'react';
|
6 |
| -import ReactDOM from 'react-dom'; |
| 6 | +import ReactDOM, { createPortal } from 'react-dom'; |
7 | 7 | import Trigger from '../src';
|
8 | 8 | import { awaitFakeTimer, placementAlignMap } from './util';
|
9 | 9 |
|
@@ -107,7 +107,7 @@ describe('Trigger.Basic', () => {
|
107 | 107 | expect(document.querySelector('.x-content').textContent).toBe('tooltip2');
|
108 | 108 |
|
109 | 109 | trigger(container, '.target');
|
110 |
| - expect(isPopupHidden).toBeTruthy(); |
| 110 | + expect(isPopupHidden()).toBeTruthy(); |
111 | 111 | });
|
112 | 112 |
|
113 | 113 | it('click works with function', () => {
|
@@ -1198,4 +1198,35 @@ describe('Trigger.Basic', () => {
|
1198 | 1198 | trigger(container, '.target');
|
1199 | 1199 | expect(document.querySelector('.x-content').textContent).toBe('false');
|
1200 | 1200 | });
|
| 1201 | + |
| 1202 | + it('createPortal should not close', async () => { |
| 1203 | + const Portal = () => |
| 1204 | + createPortal(<div className="portal" />, document.body); |
| 1205 | + |
| 1206 | + const Demo = () => { |
| 1207 | + return ( |
| 1208 | + <> |
| 1209 | + <Trigger action="click" popup={<Portal />}> |
| 1210 | + <div className="target" /> |
| 1211 | + </Trigger> |
| 1212 | + <div className="outer" /> |
| 1213 | + </> |
| 1214 | + ); |
| 1215 | + }; |
| 1216 | + |
| 1217 | + const { container } = render(<Demo />); |
| 1218 | + fireEvent.click(container.querySelector('.target')); |
| 1219 | + await awaitFakeTimer(); |
| 1220 | + expect(isPopupHidden()).toBeFalsy(); |
| 1221 | + |
| 1222 | + // Click portal should not close |
| 1223 | + fireEvent.click(document.querySelector('.portal')); |
| 1224 | + await awaitFakeTimer(); |
| 1225 | + expect(isPopupHidden()).toBeFalsy(); |
| 1226 | + |
| 1227 | + // Click outside to close |
| 1228 | + fireEvent.mouseDown(container.querySelector('.outer')); |
| 1229 | + await awaitFakeTimer(); |
| 1230 | + expect(isPopupHidden()).toBeTruthy(); |
| 1231 | + }); |
1201 | 1232 | });
|
0 commit comments