Skip to content

Commit

Permalink
fix: Image inline rendering not work when getContainer is false (#47034)
Browse files Browse the repository at this point in the history
* fix: Image 组件 preview.getContainer=false 内联渲染不生效

* refactor: Image.preview.getContainer 空值合并逻辑

---------

Co-authored-by: 莫青 <zhengyudong.zyd@alibaba-inc.com>
  • Loading branch information
2 people authored and MadCcc committed Jan 29, 2024
1 parent 4536c31 commit 0fb1249
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion components/image/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,19 @@ describe('Image', () => {
const { container, baseElement } = render(
<Image
src={src}
preview={{ visible: true, transitionName: 'abc', maskTransitionName: 'def' }}
preview={{
visible: true,
transitionName: 'abc',
maskTransitionName: 'def',
getContainer: false,
}}
/>,
);

fireEvent.click(container.querySelector('.ant-image')!);

expect(container.querySelector('.ant-image-preview-root')).not.toBe(null);

expect(baseElement.querySelector('.ant-image-preview')).toHaveClass('abc');
expect(baseElement.querySelector('.ant-image-preview-mask')).toHaveClass('def');
});
Expand Down
4 changes: 2 additions & 2 deletions components/image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const Image: CompositionImage<ImageProps> = (props) => {
typeof preview === 'object' ? preview.zIndex : undefined,
);

const mergedPreview = React.useMemo(() => {
const mergedPreview = React.useMemo<ImageProps['preview']>(() => {
if (preview === false) {
return preview;
}
Expand All @@ -64,7 +64,7 @@ const Image: CompositionImage<ImageProps> = (props) => {
),
icons,
...restPreviewProps,
getContainer: getContainer || getContextPopupContainer,
getContainer: getContainer ?? getContextPopupContainer,
transitionName: getTransitionName(rootPrefixCls, 'zoom', _preview.transitionName),
maskTransitionName: getTransitionName(rootPrefixCls, 'fade', _preview.maskTransitionName),
zIndex,
Expand Down

0 comments on commit 0fb1249

Please sign in to comment.