From a82054bdd7594787eaa80c0d7fc67790f27186a7 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 27 Aug 2021 16:23:20 +0800 Subject: [PATCH] fix:useMessage() should use getPopupContainer from #31841 --- components/message/hooks/useMessage.tsx | 4 +++- components/message/index.tsx | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/components/message/hooks/useMessage.tsx b/components/message/hooks/useMessage.tsx index 995b953e5914..b36ddbb05b53 100644 --- a/components/message/hooks/useMessage.tsx +++ b/components/message/hooks/useMessage.tsx @@ -24,6 +24,7 @@ export default function createUseMessage( const useMessage = (): [MessageInstance, React.ReactElement] => { // We can only get content by render let getPrefixCls: ConfigConsumerProps['getPrefixCls']; + let getPopupContainer: ConfigConsumerProps['getPopupContainer']; // We create a proxy to handle delay created instance let innerInstance: RCNotificationInstance | null = null; @@ -52,6 +53,7 @@ export default function createUseMessage( ...args, prefixCls: mergedPrefixCls, rootPrefixCls, + getPopupContainer, }, ({ prefixCls, instance }) => { innerInstance = instance; @@ -83,7 +85,7 @@ export default function createUseMessage( hookApiRef.current, {(context: ConfigConsumerProps) => { - ({ getPrefixCls } = context); + ({ getPrefixCls, getPopupContainer } = context); return holder; }} , diff --git a/components/message/index.tsx b/components/message/index.tsx index 1638baedd733..c5512051fdc7 100755 --- a/components/message/index.tsx +++ b/components/message/index.tsx @@ -77,7 +77,7 @@ function getRCNotificationInstance( instance: RCNotificationInstance; }) => void, ) { - const { prefixCls: customizePrefixCls } = args; + const { prefixCls: customizePrefixCls, getPopupContainer: getContextPopupContainer } = args; const { getPrefixCls, getRootPrefixCls } = globalConfig(); const prefixCls = getPrefixCls('message', customizePrefixCls || localPrefixCls); const rootPrefixCls = getRootPrefixCls(args.rootPrefixCls, prefixCls); @@ -91,7 +91,7 @@ function getRCNotificationInstance( prefixCls, transitionName: hasTransitionName ? transitionName : `${rootPrefixCls}-${transitionName}`, style: { top: defaultTop }, // 覆盖原来的样式 - getContainer, + getContainer: getContainer || getContextPopupContainer, maxCount, }; @@ -131,6 +131,7 @@ export interface ArgsProps { type: NoticeType; prefixCls?: string; rootPrefixCls?: string; + getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement; onClose?: () => void; icon?: React.ReactNode; key?: string | number;