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

[@mantine/core] Image: Fix image component update bug with placeholder #3098

Merged
merged 1 commit into from Dec 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/mantine-core/src/Image/Image.test.tsx
Expand Up @@ -45,6 +45,13 @@ describe('@mantine/core/Image', () => {
expect(withoutPlaceholder.querySelectorAll('.mantine-Image-placeholder')).toHaveLength(0);
});

it('renders a placeholder after having src updated to null', () => {
const { rerender, container } = render(<Image src="test-src" withPlaceholder />);
expect(container.querySelectorAll('.mantine-Image-placeholder')).toHaveLength(0);
rerender(<Image src={null} withPlaceholder />);
expect(container.querySelectorAll('.mantine-Image-placeholder')).toHaveLength(1);
});

it('renders given caption', () => {
const { container: withoutCaption } = render(<Image src="test" />);
const { container: withCaption } = render(<Image src="test" caption="test-caption" />);
Expand Down
2 changes: 1 addition & 1 deletion src/mantine-core/src/Image/Image.tsx
Expand Up @@ -82,7 +82,7 @@ export const Image = forwardRef<HTMLDivElement, ImageProps>((props: ImageProps,
const isPlaceholder = withPlaceholder && error;

useDidUpdate(() => {
setError(false);
setError(!src);
}, [src]);

return (
Expand Down