Skip to content
Draft
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
11 changes: 10 additions & 1 deletion src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ const ImageInternal: CompoundedComponent<ImageProps> = props => {
COMMON_PROPS.map(prop => props[prop]),
);

// Filter out img-specific props from wrapper div props
const wrapperProps = useMemo(() => {
const obj = { ...otherProps };
COMMON_PROPS.forEach((prop: any) => {
delete obj[prop];
});
return obj;
}, [otherProps]);

// ========================== Register ==========================
const registerData: ImageElementProps = useMemo(
() => ({
Expand Down Expand Up @@ -207,7 +216,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = props => {
return (
<>
<div
{...otherProps}
{...wrapperProps}
className={clsx(prefixCls, rootClassName, classNames.root, {
[`${prefixCls}-error`]: status === 'error',
})}
Expand Down
1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export const COMMON_PROPS: (keyof Omit<ImageElementProps, 'src'>)[] = [
'srcSet',
'useMap',
'alt',
'fetchPriority',
];
1 change: 1 addition & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type ImageElementProps = Pick<
| 'srcSet'
| 'useMap'
| 'alt'
| 'fetchPriority'
>;

export type PreviewImageElementProps = {
Expand Down
13 changes: 13 additions & 0 deletions tests/basic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ describe('Basic', () => {
expect(onClickMock).toHaveBeenCalledTimes(1);
});

it('fetchPriority should be passed to img element', () => {
const { container } = render(
<Image
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
fetchPriority="high"
/>,
);
const img = container.querySelector('img');
const wrapper = container.querySelector('.rc-image');
expect(img).toHaveAttribute('fetchpriority', 'high');
expect(wrapper).not.toHaveAttribute('fetchpriority');
});

it('className and style props should work on img element', () => {
const { container } = render(
<Image
Expand Down