File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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' ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
22
3- import Scrollbar from '..' ;
3+ import Scrollbar from '../index ' ;
44
55class 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 >
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React from 'react';
22import PropTypes from 'prop-types' ;
33import SmoothScrollbar from 'smooth-scrollbar' ;
44import OverscrollPlugin from 'smooth-scrollbar/plugins/overscroll' ;
5+
56SmoothScrollbar . use ( OverscrollPlugin ) ;
67
78class 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
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments