Skip to content

Commit 50390bd

Browse files
committed
wrapchildren
1 parent b12dedc commit 50390bd

4 files changed

Lines changed: 35 additions & 27 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ render() {
9595
...
9696
```
9797

98-
### Sample 2: (Using `display: flex`)
98+
### Sample 2: Recommended(Using `display: flex`)
9999

100100
```js
101101
import Scrollbar from 'smooth-scrollbar-react';

examples/App.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import Scrollbar from '..';
3+
import Scrollbar from '../index';
44

55
class App extends React.Component {
66
handleScroll = (status, scrollbar) => console.log(status, scrollbar);
@@ -26,17 +26,17 @@ class App extends React.Component {
2626
innerRef={node => (this.scrollbar = node)}
2727
onScroll={this.handleScroll}
2828
>
29-
{Array(50)
30-
.fill(1)
31-
.map((value, index) => <div key={index}>{value + index}</div>)}
29+
{[...Array(50).keys()].map((value, index) => (
30+
<div key={index}>{value + index}</div>
31+
))}
3232
</Scrollbar>
3333
</div>
3434

3535
<Scrollbar>
3636
<div className="sample-container-2" style={{ maxHeight: 250 }}>
37-
{Array(40)
38-
.fill(1)
39-
.map((value, index) => <div key={index}>{value + index}</div>)}
37+
{[...Array(40).keys()].map((value, index) => (
38+
<div key={index}>{value + index}</div>
39+
))}
4040
</div>
4141
</Scrollbar>
4242
</div>

index.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import SmoothScrollbar from 'smooth-scrollbar';
44
import OverscrollPlugin from 'smooth-scrollbar/plugins/overscroll';
5+
56
SmoothScrollbar.use(OverscrollPlugin);
67

78
class Scrollbar extends React.Component {
@@ -67,26 +68,33 @@ class Scrollbar extends React.Component {
6768

6869
render() {
6970
const { children } = this.props;
70-
7171
const count = React.Children.count(children);
7272

73-
return count === 1 && typeof children.type === 'string'
74-
? React.cloneElement(children, {
75-
ref: node => (this.container = node),
76-
})
77-
: React.createElement(
78-
'div',
79-
{
80-
ref: node => (this.container = node),
81-
style: {
82-
WebkitBoxFlex: 1,
83-
msFlex: 1,
84-
MozFlex: 1,
85-
flex: 1,
86-
},
87-
},
88-
children
89-
);
73+
if (count === 1 && typeof children.type === 'string') {
74+
return React.cloneElement(children, {
75+
ref: node => (this.container = node),
76+
});
77+
}
78+
79+
return React.createElement(
80+
'div',
81+
{
82+
ref: node => (this.container = node),
83+
style: {
84+
WebkitBoxFlex: 1,
85+
msFlex: 1,
86+
MozFlex: 1,
87+
flex: 1,
88+
},
89+
},
90+
React.createElement(
91+
'div',
92+
{
93+
className: 'scroll-content-inner',
94+
},
95+
children
96+
)
97+
);
9098
}
9199
}
92100

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "smooth-scrollbar-react",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "A wrapper for smooth-scrollbar to React Component",
55
"author": "Nghiệp<me@nghiepit.pro>",
66
"homepage": "http://smooth-scrollbar-react.surge.sh",

0 commit comments

Comments
 (0)