Skip to content

Commit c46b0b3

Browse files
author
Eric Olkowski
committed
Tested handling animation control
1 parent 5428d58 commit c46b0b3

File tree

1 file changed

+35
-2
lines changed
  • packages/react-table/src/components/Table

1 file changed

+35
-2
lines changed

packages/react-table/src/components/Table/Td.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createRef, forwardRef, useEffect, useState } from 'react';
1+
import { createRef, forwardRef, useEffect, useState, useContext } from 'react';
22
import { css } from '@patternfly/react-styles';
33
import styles from '@patternfly/react-styles/css/components/Table/table';
44
import 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';
1718
import { draggable } from './utils/decorators/draggable';
1819
import { treeRow } from './utils';
1920
import { mergeProps } from './base/merge-props';
@@ -29,6 +30,7 @@ import {
2930
TdSelectType,
3031
TdTreeRowType
3132
} from './base/types';
33+
import { TableContext } from './Table';
3234
import cssStickyCellMinWidth from '@patternfly/react-tokens/dist/esm/c_table__sticky_cell_MinWidth';
3335
import cssStickyCellInlineStart from '@patternfly/react-tokens/dist/esm/c_table__sticky_cell_InsetInlineStart';
3436
import 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

Comments
 (0)