Skip to content

Commit 572167e

Browse files
Merge pull request #329 from ianhu92/master
2 parents f7ee0a7 + 20bc096 commit 572167e

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ The `classNamePrefix` prop allows the user to supply their own custom class pref
200200

201201
These being:
202202
# A wrapper div, which is present at all times (default )
203+
204+
### style
205+
206+
Type: Object Default: undefined
207+
208+
Similar to [classNamePrefix](#classNamePrefix), the `style` prop allows users to pass custom CSS styles to wrapper div.
203209

204210
### wheel
205211

src/index.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,12 @@ class LazyLoad extends Component {
333333
height,
334334
children,
335335
placeholder,
336-
classNamePrefix
336+
classNamePrefix,
337+
style
337338
} = this.props;
338339

339340
return (
340-
<div className={`${classNamePrefix}-wrapper`} ref={this.setRef}>
341+
<div className={`${classNamePrefix}-wrapper`} ref={this.setRef} style={style}>
341342
{this.visible ? (
342343
children
343344
) : placeholder ? (
@@ -369,7 +370,8 @@ LazyLoad.propTypes = {
369370
debounce: PropTypes.oneOfType([PropTypes.number, PropTypes.bool]),
370371
placeholder: PropTypes.node,
371372
scrollContainer: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
372-
unmountIfInvisible: PropTypes.bool
373+
unmountIfInvisible: PropTypes.bool,
374+
style: PropTypes.object
373375
};
374376

375377
LazyLoad.defaultProps = {

test/specs/lazyload.spec.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('LazyLoad', () => {
4747
expect(document.querySelector('.lazyload-placeholder')).to.exist;
4848
expect(document.querySelector('.treasure')).to.not.exist;
4949
});
50-
50+
5151
it('should NOT update when invisble', (done) => {
5252
ReactDOM.render(
5353
<div>
@@ -145,6 +145,16 @@ describe('LazyLoad', () => {
145145
expect(document.querySelector('.custom-lazyload-wrapper')).to.exist;
146146
expect(document.querySelector('.custom-lazyload-placeholder')).to.exist;
147147
});
148+
it('should render wrapper with `style` when provided', () => {
149+
ReactDOM.render(
150+
<div>
151+
<LazyLoad height={9999} classNamePrefix="custom-lazyload" style={{height: 200}}>
152+
<span>123</span>
153+
</LazyLoad>
154+
</div>, div);
155+
console.log(div.innerHTML);
156+
expect(document.querySelector('.custom-lazyload-wrapper').getBoundingClientRect().height).to.equal(200);
157+
})
148158
});
149159

150160
describe('Checking visibility', () => {

0 commit comments

Comments
 (0)