Skip to content

Commit

Permalink
[@mantine/core] Image: Fix image alt overflow in Firefox (#4410)
Browse files Browse the repository at this point in the history
  • Loading branch information
comphonia committed Jun 18, 2023
1 parent 8c12a76 commit 708340b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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

0 comments on commit 708340b

Please sign in to comment.