@@ -7,7 +7,6 @@ import { isInteractiveElement } from '@semcore/core/lib/utils/isInteractiveEleme
7
7
import ChevronRightM from '@semcore/icon/ChevronRight/m' ;
8
8
import * as React from 'react' ;
9
9
10
- import { INDEX_OFFSET } from './Body' ;
11
10
import { Cell } from './Cell' ;
12
11
import type { DataTableCellProps , DataTableCellType } from './Cell.types' ;
13
12
import { MergedColumnsCell , MergedRowsCell } from './MergedCells' ;
@@ -18,6 +17,7 @@ import type { DataTableData, DTValue } from '../DataTable/DataTable.types';
18
17
19
18
type State = {
20
19
expandedForAnimation : boolean ;
20
+ calculatedHeight : number ;
21
21
} ;
22
22
23
23
export class RowRoot < Data extends DataTableData , UniqKeyType > extends Component < DataTableRowProps < Data , UniqKeyType > , { } , State , [ ] , RowPropsInner < Data , UniqKeyType > > {
@@ -35,6 +35,7 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
35
35
36
36
state : State = {
37
37
expandedForAnimation : false ,
38
+ calculatedHeight : 0 ,
38
39
} ;
39
40
40
41
constructor ( props : DataTableRowProps < Data , UniqKeyType > ) {
@@ -47,6 +48,16 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
47
48
this . asProps . componentRef ?.( this ) ;
48
49
}
49
50
51
+ componentDidUpdate ( prevProps : DataTableRowProps < Data , UniqKeyType > , prevState : State ) {
52
+ const { animationExpand } = this . asProps ;
53
+
54
+ if ( animationExpand && this . rowElementRef . current && prevState . calculatedHeight === 0 ) {
55
+ const height = this . calculateRowHeight ( this . rowElementRef . current ) ;
56
+
57
+ this . setState ( { calculatedHeight : height } ) ;
58
+ }
59
+ }
60
+
50
61
componentWillUnmount ( ) {
51
62
this . asProps . componentRef ?.( null ) ;
52
63
}
@@ -221,6 +232,7 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
221
232
flatRows : this . asProps . flatRows ,
222
233
shadowVertical,
223
234
withoutBorder,
235
+ calculatedHeight : this . state . calculatedHeight ,
224
236
} ;
225
237
226
238
if ( renderCell ) {
@@ -531,6 +543,40 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
531
543
obj === null
532
544
) ;
533
545
}
546
+
547
+ private calculateRowHeight ( rowElement : HTMLElement ) : number {
548
+ const accordionFull = rowElement . cloneNode ( true ) ;
549
+
550
+ if ( ! ( accordionFull instanceof HTMLElement ) ) {
551
+ return 0 ;
552
+ }
553
+
554
+ const columnsWidth : number [ ] = [ ] ;
555
+
556
+ const columns = Array . from ( rowElement . children ) ;
557
+ columns . forEach ( ( column ) => {
558
+ columnsWidth . push ( column . getBoundingClientRect ( ) . width ) ;
559
+ } ) ;
560
+
561
+ accordionFull . style . display = 'grid' ;
562
+ accordionFull . style . position = 'absolute' ;
563
+ accordionFull . style . visibility = 'hidden' ;
564
+ accordionFull . style . gridTemplateColumns = columnsWidth . join ( 'px ' ) + 'px' ;
565
+
566
+ Array . from ( accordionFull . children ) . forEach ( ( child ) => {
567
+ if ( child instanceof HTMLElement ) {
568
+ child . style . height = '100%' ;
569
+ }
570
+ } ) ;
571
+
572
+ document . body . appendChild ( accordionFull ) ;
573
+
574
+ const height = accordionFull . getBoundingClientRect ( ) . height ;
575
+
576
+ document . body . removeChild ( accordionFull ) ;
577
+
578
+ return height ;
579
+ }
534
580
}
535
581
536
582
export const Row = createComponent ( RowRoot , {
0 commit comments