2023-01-20 11:03:50 +08:00
|
|
|
import React from 'react';
|
2023-06-07 11:54:50 +08:00
|
|
|
import { TriggerMockContext } from '../../../tests/shared/demoTestContext';
|
|
|
|
|
|
|
|
const { default: OriginPortal } = await vi.importActual<typeof import('rc-util/es/Portal')>('rc-util/es/Portal');
|
2023-01-20 11:03:50 +08:00
|
|
|
|
|
|
|
class MockPortal extends React.Component<{ children?: React.ReactNode }> {
|
|
|
|
container: boolean;
|
|
|
|
|
|
|
|
static contextType = TriggerMockContext;
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.createContainer();
|
|
|
|
}
|
|
|
|
|
|
|
|
createContainer() {
|
|
|
|
this.container = true;
|
|
|
|
this.forceUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { children } = this.props;
|
|
|
|
if (this.container) {
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default React.forwardRef((props: any, ref: any) => {
|
|
|
|
const context = React.useContext(TriggerMockContext);
|
|
|
|
|
|
|
|
if (context?.mock === false) {
|
|
|
|
return <OriginPortal {...props} ref={ref} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <MockPortal {...props} />;
|
|
|
|
});
|