@@ -150,7 +150,7 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
150
150
*/
151
151
public renderChildren = ( list : T [ ] , startIndex : number , renderFunc : RenderFunc < T > ) =>
152
152
// We should measure rendered item height
153
- list . map ( ( item , index ) => {
153
+ list . map ( ( item , index ) => {
154
154
const node = renderFunc ( item ) as React . ReactElement ;
155
155
const eleIndex = startIndex + index ;
156
156
const eleKey = this . getItemKey ( eleIndex ) ;
@@ -162,8 +162,7 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
162
162
this . itemElements [ eleKey ] = ele ;
163
163
} ,
164
164
} ) ;
165
- } )
166
- ;
165
+ } ) ;
167
166
168
167
public render ( ) {
169
168
const {
@@ -177,11 +176,18 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
177
176
...restProps
178
177
} = this . props ;
179
178
180
- // Render pure list if not set height
181
- if ( height === undefined ) {
179
+ const mergedStyle = {
180
+ ...style ,
181
+ height,
182
+ overflowY : 'auto' ,
183
+ overflowAnchor : 'none' ,
184
+ } ;
185
+
186
+ // Render pure list if not set height or height is enough for all items
187
+ if ( height === undefined || dataSource . length * itemHeight <= height ) {
182
188
return (
183
- < Component style = { style } { ...restProps } >
184
- { this . renderChildren ( dataSource , 0 , children ) }
189
+ < Component style = { mergedStyle } { ...restProps } >
190
+ < Filler height = { height } > { this . renderChildren ( dataSource , 0 , children ) } </ Filler >
185
191
</ Component >
186
192
) ;
187
193
}
@@ -190,17 +196,7 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
190
196
const contentHeight = dataSource . length * itemHeight ;
191
197
192
198
return (
193
- < Component
194
- style = { {
195
- ...style ,
196
- height,
197
- overflowY : 'auto' ,
198
- overflowAnchor : 'none' ,
199
- } }
200
- { ...restProps }
201
- onScroll = { this . onScroll }
202
- ref = { this . listRef }
203
- >
199
+ < Component style = { mergedStyle } { ...restProps } onScroll = { this . onScroll } ref = { this . listRef } >
204
200
< Filler height = { contentHeight } offset = { status === 'MEASURE_DONE' ? startItemTop : 0 } >
205
201
{ this . renderChildren ( dataSource . slice ( startIndex , endIndex + 1 ) , startIndex , children ) }
206
202
</ Filler >
0 commit comments