@@ -53,6 +53,7 @@ interface RowsListProps {
5353 initialRowIndex ?: number ;
5454 headerGroups : HeaderGroup [ ] ;
5555 longestField ?: Field ;
56+ textWrapField ?: Field ;
5657}
5758
5859export const RowsList = ( props : RowsListProps ) => {
@@ -78,6 +79,7 @@ export const RowsList = (props: RowsListProps) => {
7879 initialRowIndex = undefined ,
7980 headerGroups,
8081 longestField,
82+ textWrapField,
8183 } = props ;
8284
8385 const [ rowHighlightIndex , setRowHighlightIndex ] = useState < number | undefined > ( initialRowIndex ) ;
@@ -232,7 +234,7 @@ export const RowsList = (props: RowsListProps) => {
232234 ) ;
233235
234236 let rowBg : Function | undefined = undefined ;
235- let textWrapField : Field | undefined = undefined ;
237+ let textWrapFinal : Field | undefined ;
236238 for ( const field of data . fields ) {
237239 // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
238240 const fieldOptions = field . config . custom as TableFieldOptions ;
@@ -250,16 +252,10 @@ export const RowsList = (props: RowsListProps) => {
250252 } ;
251253 }
252254
253- if (
254- cellOptionsExist &&
255- ( fieldOptions . cellOptions . type === TableCellDisplayMode . Auto ||
256- fieldOptions . cellOptions . type === TableCellDisplayMode . ColorBackground ||
257- fieldOptions . cellOptions . type === TableCellDisplayMode . ColorText ) &&
258- fieldOptions . cellOptions . wrapText
259- ) {
260- textWrapField = field ;
255+ if ( textWrapField !== undefined ) {
256+ textWrapFinal = textWrapField ;
261257 } else if ( longestField !== undefined ) {
262- textWrapField = longestField ;
258+ textWrapFinal = longestField ;
263259 }
264260 }
265261
@@ -288,16 +284,17 @@ export const RowsList = (props: RowsListProps) => {
288284 }
289285
290286 // If there's a text wrapping field we set the height of it here
291- if ( textWrapField ) {
287+ if ( textWrapFinal ) {
292288 const visibleFields = data . fields . filter ( ( field ) => ! Boolean ( field . config . custom ?. hidden ) ) ;
293- const seriesIndex = visibleFields . findIndex ( ( field ) => field . name === textWrapField . name ) ;
289+ const seriesIndex = visibleFields . findIndex ( ( field ) => field . name === textWrapFinal . name ) ;
294290 const pxLineHeight = theme . typography . body . lineHeight * theme . typography . fontSize ;
295291 const bbox = guessTextBoundingBox (
296- textWrapField . values [ index ] ,
292+ textWrapFinal . values [ row . index ] ,
297293 headerGroups [ 0 ] . headers [ seriesIndex ] ,
298294 osContext ,
299295 pxLineHeight ,
300- tableStyles . rowHeight
296+ tableStyles . rowHeight ,
297+ tableStyles . cellPadding
301298 ) ;
302299 style . height = bbox . height ;
303300 }
@@ -335,7 +332,7 @@ export const RowsList = (props: RowsListProps) => {
335332 frame = { data }
336333 rowStyled = { rowBg !== undefined }
337334 rowExpanded = { rowExpanded }
338- textWrapped = { textWrapField !== undefined }
335+ textWrapped = { textWrapFinal !== undefined }
339336 height = { Number ( style . height ) }
340337 />
341338 ) ) }
@@ -354,7 +351,7 @@ export const RowsList = (props: RowsListProps) => {
354351 rows ,
355352 tableState . expanded ,
356353 tableStyles ,
357- textWrapField ,
354+ textWrapFinal ,
358355 theme . components . table . rowSelected ,
359356 theme . typography . fontSize ,
360357 theme . typography . body . lineHeight ,
@@ -374,16 +371,17 @@ export const RowsList = (props: RowsListProps) => {
374371 return getExpandedRowHeight ( nestedDataField , row . index , tableStyles ) ;
375372 }
376373
377- if ( textWrapField ) {
374+ if ( textWrapFinal ) {
378375 const visibleFields = data . fields . filter ( ( field ) => ! Boolean ( field . config . custom ?. hidden ) ) ;
379- const seriesIndex = visibleFields . findIndex ( ( field ) => field . name === textWrapField . name ) ;
376+ const seriesIndex = visibleFields . findIndex ( ( field ) => field . name === textWrapFinal . name ) ;
380377 const pxLineHeight = theme . typography . fontSize * theme . typography . body . lineHeight ;
381378 return guessTextBoundingBox (
382- textWrapField . values [ index ] ,
379+ textWrapFinal . values [ row . index ] ,
383380 headerGroups [ 0 ] . headers [ seriesIndex ] ,
384381 osContext ,
385382 pxLineHeight ,
386- tableStyles . rowHeight
383+ tableStyles . rowHeight ,
384+ tableStyles . cellPadding
387385 ) . height ;
388386 }
389387
@@ -401,22 +399,29 @@ export const RowsList = (props: RowsListProps) => {
401399 // Key the virtualizer for expanded rows
402400 const expandedKey = Object . keys ( tableState . expanded ) . join ( '|' ) ;
403401
402+ // It's a hack for text wrapping.
403+ // VariableSizeList component didn't know that we manually set row height.
404+ // So we need to reset the list when the rows high changes.
405+ useEffect ( ( ) => {
406+ if ( listRef . current ) {
407+ listRef . current . resetAfterIndex ( 0 ) ;
408+ }
409+ } , [ rows , listRef ] ) ;
410+
404411 return (
405- < >
406- < CustomScrollbar onScroll = { handleScroll } hideHorizontalTrack = { true } scrollTop = { scrollTop } >
407- < VariableSizeList
408- // This component needs an unmount/remount when row height, page changes, or expanded rows change
409- key = { `${ rowHeight } ${ pageIndex } ${ expandedKey } ` }
410- height = { listHeight }
411- itemCount = { itemCount }
412- itemSize = { getItemSize }
413- width = { '100%' }
414- ref = { listRef }
415- style = { { overflow : undefined } }
416- >
417- { ( { index, style } ) => RenderRow ( { index, style, rowHighlightIndex } ) }
418- </ VariableSizeList >
419- </ CustomScrollbar >
420- </ >
412+ < CustomScrollbar onScroll = { handleScroll } hideHorizontalTrack = { true } scrollTop = { scrollTop } >
413+ < VariableSizeList
414+ // This component needs an unmount/remount when row height, page changes, or expanded rows change
415+ key = { `${ rowHeight } ${ pageIndex } ${ expandedKey } ` }
416+ height = { listHeight }
417+ itemCount = { itemCount }
418+ itemSize = { getItemSize }
419+ width = { '100%' }
420+ ref = { listRef }
421+ style = { { overflow : undefined } }
422+ >
423+ { ( { index, style } ) => RenderRow ( { index, style, rowHighlightIndex } ) }
424+ </ VariableSizeList >
425+ </ CustomScrollbar >
421426 ) ;
422427} ;
0 commit comments