You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
870 B
38 lines
870 B
2 years ago
|
import React from 'react';
|
||
1 year ago
|
import { TriggerMockContext } from '../../../tests/shared/demoTestContext';
|
||
|
|
||
|
const { default: OriginPortal } = await vi.importActual<typeof import('rc-util/es/Portal')>('rc-util/es/Portal');
|
||
2 years ago
|
|
||
|
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} />;
|
||
|
});
|