@@ -7,6 +7,7 @@ import React, {
77 useRef ,
88 useState
99} from "react" ;
10+ import { useResizeDetector } from "react-resize-detector" ;
1011import { ColumnProps , ScrollAlignment , TableProps , TableRef } from "../.." ;
1112import { DEFAULT_ROW_HEIGHT } from "../constants" ;
1213import { arraysMatch , calculateColumnWidths , cx , findColumnWidthConstants } from "../util" ;
@@ -61,6 +62,7 @@ const List = forwardRef(function <T>(
6162 // hooks
6263 const parentRef = useRef < HTMLDivElement | null > ( null ) ;
6364 const headerRef = useRef < HTMLDivElement | null > ( null ) ;
65+ const { ref : innerRef , width : innerWidth = 0 } = useResizeDetector < HTMLDivElement > ( ) ;
6466 const [ pixelWidths , setPixelWidths ] = useState < number [ ] > ( [ ] ) ;
6567 const [ widthConstants , setWidthConstants ] = useState ( findColumnWidthConstants ( columns ) ) ;
6668 const [ expandedCache , setExpandedCache ] = useState < Record < string | number , boolean > > ( { } ) ;
@@ -76,6 +78,7 @@ const List = forwardRef(function <T>(
7678 } ) ;
7779
7880 // constants
81+ const showRowWrapper = ( innerRef . current ?. scrollWidth || 0 ) > innerWidth ;
7982 const items = virtualizer . getVirtualItems ( ) ;
8083 const { fixedWidth, remainingCols } = widthConstants ;
8184
@@ -157,6 +160,7 @@ const List = forwardRef(function <T>(
157160 < Header
158161 ref = { headerRef }
159162 uuid = { uuid }
163+ showRowWrapper = { showRowWrapper }
160164 pixelWidths = { pixelWidths }
161165 columns = { columns as ColumnProps < any > [ ] }
162166 className = { headerClassname }
@@ -167,12 +171,13 @@ const List = forwardRef(function <T>(
167171 />
168172 < div className = "rft-outer-container" style = { { height : virtualizer . getTotalSize ( ) } } >
169173 < div
174+ ref = { innerRef }
170175 className = "rft-inner-container"
171176 style = { {
172177 transform : `translateY(${ items [ 0 ] ?. start ?? 0 } px)`
173178 } }
174179 >
175- < div className = "rft-row-wrapper" >
180+ < div className = { cx ( showRowWrapper && "rft-row-wrapper" ) } >
176181 { items . map ( item => {
177182 const row = data [ item . index ] ;
178183 const key = generateKeyFromRow ( row , item . index ) ;
@@ -182,6 +187,8 @@ const List = forwardRef(function <T>(
182187 const style = typeof rowStyle === "function" ? rowStyle ( item . index ) : rowStyle ;
183188 return (
184189 < Row
190+ ref = { virtualizer . measureElement }
191+ rowHeight = { rowHeight }
185192 key = { key }
186193 row = { row }
187194 uuid = { uuid }
@@ -196,7 +203,6 @@ const List = forwardRef(function <T>(
196203 columns = { columns as any }
197204 pixelWidths = { pixelWidths }
198205 subComponent = { subComponent as any }
199- ref = { virtualizer . measureElement }
200206 />
201207 ) ;
202208 } ) }
0 commit comments