mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-03 16:08:20 +08:00
1fc374495f
* chore: init test * test: rootClassName inject * test: part of test * chore: patch qrcode rootCls * chore: part rootClassName * chore: part rootClassName * test: more test * test: more test * test: more test * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * test: more test * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: fix lint * chore: fix lint * chore: ignore part of lint * test: update snapshot * test: fix test case * chore: fix node test * chore: adjust render logic * fix: test * test: update snapshot * test: update * refactor * chore: fix require module logic
38 lines
863 B
TypeScript
38 lines
863 B
TypeScript
import React from 'react';
|
|
import { TriggerMockContext } from '../../../shared/demoTestContext';
|
|
|
|
let OriginPortal = jest.requireActual('rc-util/lib/Portal');
|
|
OriginPortal = OriginPortal.default ?? OriginPortal;
|
|
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} />;
|
|
});
|