Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should hide preview mask when Image is hidden #123

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,14 @@ const ImageInternal: CompoundedComponent<ImageProps> = ({

{/* Preview Click Mask */}
{previewMask && canPreview && (
<div className={cn(`${prefixCls}-mask`, maskClassName)}>{previewMask}</div>
<div
className={cn(`${prefixCls}-mask`, maskClassName)}
style={{
display: imgCommonProps.style?.display === 'none' ? 'none' : undefined,
}}
>
{previewMask}
</div>
)}
</div>
{!isPreviewGroup && canPreview && (
Expand Down
21 changes: 19 additions & 2 deletions tests/basic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ describe('Basic', () => {

expect(onClickMock).toHaveBeenCalledTimes(1);
});
test('className and style props should work on img element', () => {

it('className and style props should work on img element', () => {
const { container } = render(
<Image
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
Expand All @@ -56,7 +57,8 @@ describe('Basic', () => {
expect(img).toHaveClass('img');
expect(img).toHaveStyle({ objectFit: 'cover' });
});
test('wrapperClassName and wrapperStyle should work on image wrapper element', () => {

it('wrapperClassName and wrapperStyle should work on image wrapper element', () => {
const { container } = render(
<Image
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
Expand All @@ -70,4 +72,19 @@ describe('Basic', () => {
expect(wrapperElement).toHaveClass('wrapper');
expect(wrapperElement).toHaveStyle({ objectFit: 'cover' });
});

// https://github.com/ant-design/ant-design/issues/36680
it('preview mask should be hidden when image has style { display: "none" }', () => {
const { container } = render(
<Image
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
style={{
display: 'none',
}}
preview={{ mask: 'Click to Preview' }}
/>,
);
const maskElement = container.querySelector('.rc-image-mask');
expect(maskElement).toHaveStyle({ display: 'none' });
});
});