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: Image component props support native img element attributes #2427

Merged
merged 2 commits into from
Aug 20, 2024
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
2 changes: 2 additions & 0 deletions content/show/image/index-en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ import { Image, ImagePreview } from '@douyinfe/semi-ui';
| width | Image display width | number | - | |
| setDownloadName | Set the name of the downloaded image | (src: string) => string | - | 2.40.0 |

Other attributes same as [img](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes)。Other attributes will be transmitted to the underlying img node.

### ImagePreview

| Properties | Instructions | Type | Default | Version |
Expand Down
2 changes: 2 additions & 0 deletions content/show/image/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ import { Image, ImagePreview } from '@douyinfe/semi-ui';
| width | 图片显示宽度 | number | - | |
| setDownloadName | 设置图片下载名称 | (src: string) => string | - | 2.40.0 |

其他支持的属性同 [img](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes)。其他属性将透传至底层的 img 节点。

### ImagePreview

| 属性 | 说明 | 类型 | 默认值 | 版本 |
Expand Down
3 changes: 2 additions & 1 deletion packages/semi-ui/image/_story/image.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ export const BasicPreview = () => {
{srcList1.map((src, index) => {
return (
<Image
key={index}
key={`${index}`}
src={src}
width={200}
loading='lazy'
alt={`lamp${index + 1}`}
data-test={'data-test'}
onClick={()=>{}}
Expand Down
4 changes: 2 additions & 2 deletions packages/semi-ui/image/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ImageStates {
previewVisible: boolean
}

export interface ImageProps extends BaseProps {
export interface ImageProps extends BaseProps, Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'onLoad' | 'onError'> {
src?: string;
width?: string | number;
height?: string | number;
Expand Down Expand Up @@ -190,7 +190,7 @@ export interface PreviewImageStates {
width: number;
height: number;
translate: ImageTranslate;
currZoom: number;
currZoom: number
}

export interface DragDirection {
Expand Down
Loading