diff --git a/components/image/__tests__/index.test.js b/components/image/__tests__/index.test.js
index 91093149ed..873be7e01b 100644
--- a/components/image/__tests__/index.test.js
+++ b/components/image/__tests__/index.test.js
@@ -1,8 +1,9 @@
import React from 'react';
-import { render, fireEvent } from '../../../tests/utils';
import Image from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
+import { fireEvent, render } from '../../../tests/utils';
+import ConfigProvider from '../../config-provider';
const src = 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png';
@@ -76,4 +77,17 @@ describe('Image', () => {
expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('abc');
expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('def');
});
+ it('ConfigProvider getPopupContainer', () => {
+ const { container: wrapper, baseElement } = render(
+ <>
+
+ document.querySelector('.container')}>
+
+
+ >,
+ );
+ fireEvent.click(wrapper.querySelector('.ant-image'));
+ const containerElement = baseElement.querySelector('.container');
+ expect(containerElement.children.length).not.toBe(0);
+ });
});
diff --git a/components/image/index.tsx b/components/image/index.tsx
index 17405cfc5e..f62b00cf3c 100644
--- a/components/image/index.tsx
+++ b/components/image/index.tsx
@@ -16,7 +16,12 @@ const Image: CompositionImage = ({
preview,
...otherProps
}) => {
- const { getPrefixCls, locale: contextLocale = defaultLocale } = useContext(ConfigContext);
+ const {
+ getPrefixCls,
+ locale: contextLocale = defaultLocale,
+ getPopupContainer: getContextPopupContainer,
+ } = useContext(ConfigContext);
+
const prefixCls = getPrefixCls('image', customizePrefixCls);
const rootPrefixCls = getPrefixCls();
@@ -27,7 +32,7 @@ const Image: CompositionImage = ({
return preview;
}
const _preview = typeof preview === 'object' ? preview : {};
-
+ const { getContainer, ...restPreviewProps } = _preview;
return {
mask: (
@@ -36,7 +41,8 @@ const Image: CompositionImage = ({
),
icons,
- ..._preview,
+ ...restPreviewProps,
+ getContainer: getContainer || getContextPopupContainer,
transitionName: getTransitionName(rootPrefixCls, 'zoom', _preview.transitionName),
maskTransitionName: getTransitionName(rootPrefixCls, 'fade', _preview.maskTransitionName),
};