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 alt overflow #4410

Merged
merged 1 commit into from
Jun 18, 2023
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
19 changes: 19 additions & 0 deletions src/mantine-core/src/Image/Image.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ describe('@mantine/core/Image', () => {
expect(container.querySelectorAll('.mantine-Image-placeholder')).toHaveLength(1);
});

it('sets overflow to hidden if withPlaceholder is true on img element', () => {
render(<Image src={null} alt="test-alt" withPlaceholder />);
const image = screen.getByRole('img');
expect(image).toHaveStyle({ overflow: 'hidden' });
});

it('uses a user-defined overflow if an imageProps style is set on img element', () => {
render(
<Image
src={null}
alt="test-alt"
withPlaceholder
imageProps={{ style: { overflow: 'unset' } }}
/>
);
const image = screen.getByRole('img');
expect(image).toHaveStyle({ overflow: 'unset' });
});

it('renders given caption', () => {
const { container: withoutCaption } = render(<Image src="test" />);
const { container: withCaption } = render(<Image src="test" caption="test-caption" />);
Expand Down
8 changes: 7 additions & 1 deletion src/mantine-core/src/Image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ export const Image = forwardRef<HTMLDivElement, ImageProps>((props: ImageProps,
setError(true);
typeof imageProps?.onError === 'function' && imageProps.onError(event);
}}
style={{ objectFit: fit, width: rem(width), height: rem(height), ...imageProps?.style }}
style={{
objectFit: fit,
width: rem(width),
height: rem(height),
...(isPlaceholder && { overflow: 'hidden' }),
...imageProps?.style,
}}
/>

{isPlaceholder && (
Expand Down