mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-30 12:28:33 +08:00
14a1e6bd51
* feat: tsconfig enable strict * feat: add no-explicit-any * feat: strict * feat: as THEME * feat: 优化 keys 类型写法 * feat: demo remove any * feat: as number * feat: this any * feat: add eslint * feat: cascader * feat: props any * feat: remove any * feat: remove any * feat: any 提示错误 * feat: remove any * feat: add eslint * feat: 允许 T = any 存在 * feat: color funciton * feat: 恢复 lint * feat: merge master * feat: as ReactElement * feat: type
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import React from 'react';
|
|
import type { PortalProps, PortalRef } from 'rc-util/lib/Portal';
|
|
import { TriggerMockContext } from '../../../shared/demoTestContext';
|
|
|
|
let OriginPortal = jest.requireActual('rc-util/lib/Portal');
|
|
OriginPortal = OriginPortal.default ?? OriginPortal;
|
|
|
|
interface MockPortalProps {
|
|
children?: React.ReactNode
|
|
}
|
|
|
|
class MockPortal extends React.Component<MockPortalProps> {
|
|
container: boolean | undefined;
|
|
|
|
static contextType = TriggerMockContext;
|
|
|
|
componentDidMount() {
|
|
this.createContainer();
|
|
}
|
|
|
|
createContainer() {
|
|
this.container = true;
|
|
this.forceUpdate();
|
|
}
|
|
|
|
render() {
|
|
const { children } = this.props;
|
|
if (this.container) {
|
|
return children;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
const CustomPortal = React.forwardRef<PortalRef, PortalProps | MockPortalProps>((props, ref) => {
|
|
const context = React.useContext(TriggerMockContext);
|
|
if (context?.mock === false) {
|
|
return <OriginPortal {...props} ref={ref} />;
|
|
}
|
|
return <MockPortal {...props} />;
|
|
});
|
|
|
|
export default CustomPortal; |