Skip to content

Commit

Permalink
fix: onError add event and objectFit set default value
Browse files Browse the repository at this point in the history
  • Loading branch information
yugang.cao committed Jul 13, 2021
1 parent 84102f9 commit 08bfd3a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
19 changes: 13 additions & 6 deletions src/avatar/src/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ const avatarProps = {
default: false
},
color: String,
objectFit: String as PropType<
'fill' | 'contain' | 'cover' | 'none' | 'scale-down'
>,
objectFit: {
type: String as PropType<
'fill' | 'contain' | 'cover' | 'none' | 'scale-down'
>,
default: 'fill'
},
round: {
type: Boolean,
default: false
},
onError: Function as PropType<() => void>
onError: Function as PropType<(e: Event) => void>
} as const

export type AvatarProps = ExtractPublicPropTypes<typeof avatarProps>
Expand Down Expand Up @@ -85,8 +88,12 @@ export default defineComponent({
textRef,
selfRef,
mergedClsPrefix: mergedClsPrefixRef,
handleError: (e: Event) => {
const { onError } = props
onError?.(e)
},
cssVars: computed(() => {
const { size, round, circle, objectFit = 'fill' } = props
const { size, round, circle, objectFit } = props
const {
self: { borderRadius, fontSize, color },
common: { cubicBezierEaseInOut }
Expand Down Expand Up @@ -117,7 +124,7 @@ export default defineComponent({
style={this.cssVars as any}
>
{!$slots.default && src ? (
<img src={src} onError={this.onError} />
<img src={src} onError={this.handleError} />
) : (
<span
ref="textRef"
Expand Down
19 changes: 13 additions & 6 deletions src/image/src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ const imageProps = {
alt: String,
height: [String, Number] as PropType<string | number>,
imgProps: Object as PropType<imgProps>,
objectFit: String as PropType<
'fill' | 'contain' | 'cover' | 'none' | 'scale-down'
>,
objectFit: {
type: String as PropType<
'fill' | 'contain' | 'cover' | 'none' | 'scale-down'
>,
default: 'fill'
},
width: [String, Number] as PropType<string | number>,
src: String,
showToolbar: { type: Boolean, default: true },
onError: Function as PropType<() => void>
onError: Function as PropType<(e: Event) => void>
}

export type ImageProps = ExtractPublicPropTypes<typeof imageProps>
Expand Down Expand Up @@ -70,8 +73,12 @@ export default defineComponent({
previewInst.setThumbnailEl(imageRef.value)
previewInst.toggleShow()
},
handleError: (e: Event) => {
const { onError } = props
onError?.(e)
},
cssVars: computed(() => {
const { objectFit = 'fill' } = props
const { objectFit } = props
return {
'--object-fit': objectFit
}
Expand All @@ -98,7 +105,7 @@ export default defineComponent({
alt={this.alt ? this.alt : imgProps.alt}
aria-label={this.alt ? this.alt : imgProps.alt}
onClick={this.handleClick}
onError={this.onError}
onError={this.handleError}
/>
)

Expand Down

0 comments on commit 08bfd3a

Please sign in to comment.