对于像 Tooltip Popover Select TreeSelect Modal Drawer 等组件在滚动时可能会跟随鼠标进行滚动, 对于用户体验来说很不友好, 做一些简单的处理, 均提供了如: getContainer getPopupContainer API, 但针对 DatePicker 等日期组件使用之后貌似没什么反应, 而是通过 getCalendarContainer
**
/**
* 代替全局的 ConfigProvider
* getPopupContainer: https://3x.ant.design/components/config-provider-cn/#API
*/
import React, { ReactNode, FC } from 'react';
export interface TriggerContainerProps {
children: ReactNode;
}
export const getPopupContainer = (node: HTMLElement) => {
if (node) {
return node.parentNode as HTMLElement;
}
return document.body;
};
const TriggerContainer: FC<TriggerContainerProps> = props => {
const { children, ...restProps } = props;
const newProps = {
...restProps,
getPopupContainer,
getCalendarContainer: getPopupContainer,
};
// @ts-ignore
return React.cloneElement(children, newProps);
};
export default TriggerContainer;
也可以通过全局配置 ConfigProvider 提供的 getPopupContainer 进行配置