Skip to content

Commit

Permalink
fix width and height issue for children
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Feb 8, 2019
1 parent 067f0b6 commit b638ac0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/simpleImg.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class SimpleImg extends React.PureComponent<Props, State> {
animationDuration,
animationEndStyle = defaultDisappearStyle,
placeholder = defaultPlaceholderColor,
wrapperStyle,
wrapperStyle = {},
...restProps
} = this.props;
const { loaded } = this.state;
Expand All @@ -169,6 +169,10 @@ export class SimpleImg extends React.PureComponent<Props, State> {
removeImgLoadingRef,
...restImgProps
} = restProps;
const heightWidth = {
...(height ? { height: wrapperStyle.height || height } : null),
...(width ? { width: wrapperStyle.width || width } : null),
};
return (
<span
Expand All @@ -190,8 +194,8 @@ export class SimpleImg extends React.PureComponent<Props, State> {
data-srcset={srcSet}
style={{
...(!isValidImgSrc && !loaded && !isSrcSetFulfilled
? { ...expendWidthHeight, height, width, ...hiddenStyle }
: { ...expendWidthHeight, height, width }),
? { ...expendWidthHeight, ...heightWidth, ...hiddenStyle }
: { ...expendWidthHeight, ...heightWidth }),
}}
{...restImgProps}
/>
Expand All @@ -201,8 +205,7 @@ export class SimpleImg extends React.PureComponent<Props, State> {
endStyle={{
...inlineStyle,
...animationEndStyle,
height,
width,
...heightWidth,
}}
onCompleteStyle={onCompleteStyle}
render={({ style }) => {
Expand All @@ -214,12 +217,11 @@ export class SimpleImg extends React.PureComponent<Props, State> {
style={combinedStyle}
alt={alt}
src={placeholder}
height={height}
width={width}
{...heightWidth}
{...restImgProps}
/>
) : (
<div className={className} style={combinedStyle} height={height} width={width} />
<div className={className} style={combinedStyle} {...heightWidth} />
);
}}
/>
Expand Down

0 comments on commit b638ac0

Please sign in to comment.