avatar img add "alt" prop (#10798)

This commit is contained in:
陈帅 2018-06-07 11:36:16 +08:00 committed by Wei Zhu
parent e51b043737
commit 2025a10a06
3 changed files with 5 additions and 1 deletions

View File

@ -14,3 +14,4 @@ Avatars can be used to represent people or objects. It supports images, `Icon`s,
| shape | the shape of avatar | `circle` \| `square` | `circle` |
| size | the size of the avatar | `large` \| `small` \| `default` | `default` |
| src | the address of the image for an image avatar | string | - |
| alt | This attribute defines the alternative text describing the image | string | - |

View File

@ -16,6 +16,7 @@ export interface AvatarProps {
prefixCls?: string;
className?: string;
children?: any;
alt?: string;
}
export interface AvatarState {
@ -75,7 +76,7 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
render() {
const {
prefixCls, shape, size, src, icon, className, ...others
prefixCls, shape, size, src, icon, className, alt, ...others
} = this.props;
const sizeCls = classNames({
@ -95,6 +96,7 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
<img
src={src}
onError={this.handleImgLoadError}
alt={alt}
/>
);
} else if (icon) {

View File

@ -15,3 +15,4 @@ title: Avatar
| shape | 指定头像的形状 | Enum{ 'circle', 'square' } | `circle` |
| size | 设置头像的大小 | Enum{ 'large', 'small', 'default' } | `default` |
| src | 图片类头像的资源地址 | string | - |
| alt | 图像无法显示时的替代文本 | string | - |