1- import { createRef , forwardRef , useEffect , useState } from 'react' ;
1+ import { createRef , forwardRef , useEffect , useState , useContext } from 'react' ;
22import { css } from '@patternfly/react-styles' ;
33import styles from '@patternfly/react-styles/css/components/Table/table' ;
44import scrollStyles from '@patternfly/react-styles/css/components/Table/table-scrollable' ;
@@ -14,6 +14,7 @@ import {
1414 classNames ,
1515 favoritable
1616} from './utils' ;
17+ import { IRowData , IExtraData } from './TableTypes' ;
1718import { draggable } from './utils/decorators/draggable' ;
1819import { treeRow } from './utils' ;
1920import { mergeProps } from './base/merge-props' ;
@@ -29,6 +30,7 @@ import {
2930 TdSelectType ,
3031 TdTreeRowType
3132} from './base/types' ;
33+ import { TableContext } from './Table' ;
3234import cssStickyCellMinWidth from '@patternfly/react-tokens/dist/esm/c_table__sticky_cell_MinWidth' ;
3335import cssStickyCellInlineStart from '@patternfly/react-tokens/dist/esm/c_table__sticky_cell_InsetInlineStart' ;
3436import cssStickyCellInlineEnd from '@patternfly/react-tokens/dist/esm/c_table__sticky_cell_InsetInlineEnd' ;
@@ -193,6 +195,37 @@ const TdBase: React.FunctionComponent<TdProps> = ({
193195 }
194196 } )
195197 : null ;
198+
199+ const { hasAnimations } = useContext ( TableContext ) ;
200+ const internalCompoundOnToggle = (
201+ event : React . MouseEvent ,
202+ rowIndex : number ,
203+ colIndex : number ,
204+ isOpen : boolean ,
205+ rowData : IRowData ,
206+ extraData : IExtraData
207+ ) => {
208+ if ( hasAnimations ) {
209+ const ancestorControlRow = ( cellRef as React . RefObject < HTMLElement | null > ) ?. current ?. closest (
210+ `.${ styles . tableTr } .${ styles . tableControlRow } `
211+ ) ;
212+ const isControlRowExpanded = ancestorControlRow . classList . contains ( styles . modifiers . expanded ) ;
213+ const isCurrentCellExpanded = ( cellRef as React . RefObject < HTMLElement | null > ) ?. current ?. classList . contains (
214+ styles . modifiers . expanded
215+ ) ;
216+
217+ if ( isControlRowExpanded ) {
218+ if ( isCurrentCellExpanded ) {
219+ ancestorControlRow . classList . remove ( 'pf-m-no-animate' ) ;
220+ } else {
221+ ancestorControlRow . classList . add ( 'pf-m-no-animate' ) ;
222+ }
223+ }
224+ }
225+
226+ compoundExpandProp ?. onToggle ( event , rowIndex , colIndex , isOpen , rowData , extraData ) ;
227+ } ;
228+
196229 const compoundParams =
197230 compoundExpandProp !== null
198231 ? compoundExpand (
@@ -207,7 +240,7 @@ const TdBase: React.FunctionComponent<TdProps> = ({
207240 columnIndex : compoundExpandProp ?. columnIndex ,
208241 column : {
209242 extraParams : {
210- onExpand : compoundExpandProp ?. onToggle ,
243+ onExpand : internalCompoundOnToggle ,
211244 expandId : compoundExpandProp ?. expandId
212245 }
213246 }
0 commit comments