Skip to content

Commit 2d52666

Browse files
strashkovAleksandr Strashkov
andauthored
PlaceholderWithoutTracking: removed default width and height values (#58)
Co-authored-by: Aleksandr Strashkov <[email protected]>
1 parent 46f30e7 commit 2d52666

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/components/PlaceholderWithoutTracking.jsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,24 @@ class PlaceholderWithoutTracking extends React.Component {
118118
});
119119
}
120120

121+
const styleProp = {
122+
display: 'inline-block',
123+
...style,
124+
};
125+
126+
if (typeof width !== 'undefined') {
127+
styleProp.width = width;
128+
}
129+
130+
if (typeof height !== 'undefined') {
131+
styleProp.height = height;
132+
}
133+
121134
return (
122135
<span
123136
className={className}
124137
ref={el => (this.placeholder = el)}
125-
style={{ display: 'inline-block', height, width, ...style }}
138+
style={styleProp}
126139
>
127140
{placeholder}
128141
</span>
@@ -133,24 +146,22 @@ class PlaceholderWithoutTracking extends React.Component {
133146
PlaceholderWithoutTracking.propTypes = {
134147
onVisible: PropTypes.func.isRequired,
135148
className: PropTypes.string,
136-
height: PropTypes.number,
149+
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
137150
placeholder: PropTypes.element,
138151
threshold: PropTypes.number,
139152
useIntersectionObserver: PropTypes.bool,
140153
scrollPosition: PropTypes.shape({
141154
x: PropTypes.number.isRequired,
142155
y: PropTypes.number.isRequired,
143156
}),
144-
width: PropTypes.number,
157+
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
145158
};
146159

147160
PlaceholderWithoutTracking.defaultProps = {
148161
className: '',
149-
height: 0,
150162
placeholder: null,
151163
threshold: 100,
152164
useIntersectionObserver: true,
153-
width: 0,
154165
};
155166

156167
export default PlaceholderWithoutTracking;

0 commit comments

Comments
 (0)