@patternfly/react-table 6.3.0-prerelease.3 → 6.3.0-prerelease.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +116 -0
- package/components/package.json +1 -1
- package/deprecated/package.json +1 -1
- package/dist/dynamic/components/Table/package.json +1 -1
- package/dist/dynamic/components/Table/utils/decorators/package.json +1 -1
- package/dist/dynamic/components/Table/utils/package.json +1 -1
- package/dist/dynamic/deprecated/components/Table/base/package.json +1 -1
- package/dist/dynamic/deprecated/components/Table/package.json +1 -1
- package/dist/dynamic/deprecated/components/package.json +1 -1
- package/dist/esm/components/Table/ExpandableRowContent.d.ts +5 -0
- package/dist/esm/components/Table/ExpandableRowContent.d.ts.map +1 -1
- package/dist/esm/components/Table/ExpandableRowContent.js +2 -2
- package/dist/esm/components/Table/ExpandableRowContent.js.map +1 -1
- package/dist/esm/components/Table/Table.d.ts +6 -1
- package/dist/esm/components/Table/Table.d.ts.map +1 -1
- package/dist/esm/components/Table/Table.js +5 -4
- package/dist/esm/components/Table/Table.js.map +1 -1
- package/dist/esm/components/Table/Td.d.ts.map +1 -1
- package/dist/esm/components/Table/Td.js +23 -2
- package/dist/esm/components/Table/Td.js.map +1 -1
- package/dist/esm/components/Table/Tr.d.ts +3 -1
- package/dist/esm/components/Table/Tr.d.ts.map +1 -1
- package/dist/esm/components/Table/Tr.js +7 -4
- package/dist/esm/components/Table/Tr.js.map +1 -1
- package/dist/esm/demos/DashboardHeader.d.ts.map +1 -1
- package/dist/esm/demos/DashboardHeader.js +1 -2
- package/dist/esm/demos/DashboardHeader.js.map +1 -1
- package/dist/esm/demos/sampleData.d.ts.map +1 -1
- package/dist/esm/demos/sampleData.js +359 -360
- package/dist/esm/demos/sampleData.js.map +1 -1
- package/dist/js/components/Table/ExpandableRowContent.d.ts +5 -0
- package/dist/js/components/Table/ExpandableRowContent.d.ts.map +1 -1
- package/dist/js/components/Table/ExpandableRowContent.js +2 -2
- package/dist/js/components/Table/ExpandableRowContent.js.map +1 -1
- package/dist/js/components/Table/Table.d.ts +6 -1
- package/dist/js/components/Table/Table.d.ts.map +1 -1
- package/dist/js/components/Table/Table.js +5 -4
- package/dist/js/components/Table/Table.js.map +1 -1
- package/dist/js/components/Table/Td.d.ts.map +1 -1
- package/dist/js/components/Table/Td.js +22 -1
- package/dist/js/components/Table/Td.js.map +1 -1
- package/dist/js/components/Table/Tr.d.ts +3 -1
- package/dist/js/components/Table/Tr.d.ts.map +1 -1
- package/dist/js/components/Table/Tr.js +7 -4
- package/dist/js/components/Table/Tr.js.map +1 -1
- package/dist/js/demos/DashboardHeader.d.ts.map +1 -1
- package/dist/js/demos/DashboardHeader.js +1 -2
- package/dist/js/demos/DashboardHeader.js.map +1 -1
- package/dist/js/demos/sampleData.d.ts.map +1 -1
- package/dist/js/demos/sampleData.js +359 -360
- package/dist/js/demos/sampleData.js.map +1 -1
- package/dist/umd/assets/{output-CLV1g6to.css → output-C-sBtw5n.css} +5230 -4833
- package/dist/umd/react-table.min.js +2 -2
- package/package.json +6 -6
- package/src/components/Table/ExpandableRowContent.tsx +7 -1
- package/src/components/Table/Table.tsx +12 -4
- package/src/components/Table/Td.tsx +37 -2
- package/src/components/Table/Tr.tsx +10 -4
- package/src/components/Table/__tests__/ExpandableRowContent.test.tsx +39 -0
- package/src/components/Table/__tests__/Table.test.tsx +62 -0
- package/src/components/Table/__tests__/Tr.test.tsx +79 -0
- package/src/components/Table/__tests__/__snapshots__/ExpandableRowContent.test.tsx.snap +11 -0
- package/src/components/Table/__tests__/__snapshots__/Table.test.tsx.snap +13 -0
- package/src/components/Table/__tests__/__snapshots__/Tr.test.tsx.snap +35 -0
- package/src/components/Table/examples/Table.md +2 -0
- package/src/components/Table/examples/TableCompoundExpandable.tsx +23 -21
- package/src/components/Table/examples/TableExpandable.tsx +8 -3
- package/src/components/Table/examples/TableMisc.tsx +0 -1
- package/src/components/Table/examples/TableNestedExpandable.tsx +3 -3
- package/src/components/Table/examples/TableNestedTableExpandable.tsx +3 -3
- package/src/components/Table/examples/TableStripedExpandable.tsx +9 -3
- package/src/demos/DashboardHeader.tsx +2 -5
- package/src/demos/examples/TableCompoundExpansion.tsx +87 -84
- package/src/demos/examples/TableExpandCollapseAll.tsx +3 -3
- package/src/demos/sampleData.tsx +359 -361
- package/src/deprecated/components/Table/__tests__/__snapshots__/Table.test.tsx.snap +0 -17
- package/src/deprecated/components/Table/examples/LegacyTableMisc.tsx +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-table",
|
|
3
|
-
"version": "6.3.0-prerelease.
|
|
3
|
+
"version": "6.3.0-prerelease.30",
|
|
4
4
|
"description": "This library provides a set of React table components for use with the PatternFly 4",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@patternfly/react-core": "^6.3.0-prerelease.
|
|
44
|
-
"@patternfly/react-icons": "^6.3.0-prerelease.
|
|
45
|
-
"@patternfly/react-styles": "^6.3.0-prerelease.
|
|
46
|
-
"@patternfly/react-tokens": "^6.3.0-prerelease.
|
|
43
|
+
"@patternfly/react-core": "^6.3.0-prerelease.30",
|
|
44
|
+
"@patternfly/react-icons": "^6.3.0-prerelease.12",
|
|
45
|
+
"@patternfly/react-styles": "^6.3.0-prerelease.11",
|
|
46
|
+
"@patternfly/react-tokens": "^6.3.0-prerelease.11",
|
|
47
47
|
"lodash": "^4.17.21",
|
|
48
48
|
"tslib": "^2.8.1"
|
|
49
49
|
},
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"react": "^17 || ^18 || ^19",
|
|
52
52
|
"react-dom": "^17 || ^18 || ^19"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "031fba5b63c67c6cb8ca4ead17830ddd1dafec8e"
|
|
55
55
|
}
|
|
@@ -2,14 +2,20 @@ import { css } from '@patternfly/react-styles';
|
|
|
2
2
|
import styles from '@patternfly/react-styles/css/components/Table/table';
|
|
3
3
|
|
|
4
4
|
interface ExpandableRowContentProps {
|
|
5
|
+
/** Content rendered inside the expandable row. */
|
|
5
6
|
children?: React.ReactNode;
|
|
7
|
+
/** Flag indicating whether the expandable row content has no background. This should be passed in when
|
|
8
|
+
* the parent Td is passed the noPadding prop.
|
|
9
|
+
*/
|
|
10
|
+
hasNoBackground?: boolean;
|
|
6
11
|
}
|
|
7
12
|
|
|
8
13
|
export const ExpandableRowContent: React.FunctionComponent<ExpandableRowContentProps> = ({
|
|
9
14
|
children = null as React.ReactNode,
|
|
15
|
+
hasNoBackground,
|
|
10
16
|
...props
|
|
11
17
|
}: ExpandableRowContentProps) => (
|
|
12
|
-
<div {...props} className={css(styles.tableExpandableRowContent)}>
|
|
18
|
+
<div {...props} className={css(styles.tableExpandableRowContent, hasNoBackground && styles.modifiers.noBackground)}>
|
|
13
19
|
{children}
|
|
14
20
|
</div>
|
|
15
21
|
);
|
|
@@ -57,8 +57,12 @@ export interface TableProps extends React.HTMLProps<HTMLTableElement>, OUIAProps
|
|
|
57
57
|
isNested?: boolean;
|
|
58
58
|
/** Flag indicating this table should be striped. This property works best for a single <tbody> table. Striping may also be done manually by applying this property to Tbody and Tr components. */
|
|
59
59
|
isStriped?: boolean;
|
|
60
|
-
/** Flag indicating this table contains expandable rows
|
|
60
|
+
/** Flag indicating this table contains expandable rows. */
|
|
61
61
|
isExpandable?: boolean;
|
|
62
|
+
/** Flag indicating whether expandable rows within the table have animations. Expandable rows cannot be dynamically rendered. This prop
|
|
63
|
+
* will be removed in the next breaking change, with the default behavior becoming animations always being enabled.
|
|
64
|
+
*/
|
|
65
|
+
hasAnimations?: boolean;
|
|
62
66
|
/** Flag indicating this table's rows will not have the inset typically reserved for expanding/collapsing rows in a tree table. Intended for use on tree tables with no visible rows with children. */
|
|
63
67
|
hasNoInset?: boolean;
|
|
64
68
|
/** Collection of column spans for nested headers. Deprecated: see https://github.com/patternfly/patternfly/issues/4584 */
|
|
@@ -73,10 +77,12 @@ export interface TableProps extends React.HTMLProps<HTMLTableElement>, OUIAProps
|
|
|
73
77
|
|
|
74
78
|
interface TableContextProps {
|
|
75
79
|
registerSelectableRow?: () => void;
|
|
80
|
+
hasAnimations?: boolean;
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
export const TableContext = createContext<TableContextProps>({
|
|
79
|
-
registerSelectableRow: () => {}
|
|
84
|
+
registerSelectableRow: () => {},
|
|
85
|
+
hasAnimations: false
|
|
80
86
|
});
|
|
81
87
|
|
|
82
88
|
const TableBase: React.FunctionComponent<TableProps> = ({
|
|
@@ -95,6 +101,7 @@ const TableBase: React.FunctionComponent<TableProps> = ({
|
|
|
95
101
|
isNested = false,
|
|
96
102
|
isStriped = false,
|
|
97
103
|
isExpandable = false,
|
|
104
|
+
hasAnimations = false,
|
|
98
105
|
hasNoInset = false,
|
|
99
106
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
100
107
|
nestedHeaderColumnSpans,
|
|
@@ -197,7 +204,7 @@ const TableBase: React.FunctionComponent<TableProps> = ({
|
|
|
197
204
|
};
|
|
198
205
|
|
|
199
206
|
return (
|
|
200
|
-
<TableContext.Provider value={{ registerSelectableRow }}>
|
|
207
|
+
<TableContext.Provider value={{ registerSelectableRow, hasAnimations }}>
|
|
201
208
|
<table
|
|
202
209
|
aria-label={ariaLabel}
|
|
203
210
|
role={role}
|
|
@@ -212,7 +219,8 @@ const TableBase: React.FunctionComponent<TableProps> = ({
|
|
|
212
219
|
isStriped && styles.modifiers.striped,
|
|
213
220
|
isExpandable && styles.modifiers.expandable,
|
|
214
221
|
hasNoInset && stylesTreeView.modifiers.noInset,
|
|
215
|
-
isNested && 'pf-m-nested'
|
|
222
|
+
isNested && 'pf-m-nested',
|
|
223
|
+
hasAnimations && styles.modifiers.animateExpand
|
|
216
224
|
)}
|
|
217
225
|
ref={tableRef}
|
|
218
226
|
{...(isTreeTable && { role: 'treegrid' })}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRef, forwardRef, useEffect, useState } from 'react';
|
|
1
|
+
import { createRef, forwardRef, useEffect, useState, useContext } from 'react';
|
|
2
2
|
import { css } from '@patternfly/react-styles';
|
|
3
3
|
import styles from '@patternfly/react-styles/css/components/Table/table';
|
|
4
4
|
import scrollStyles from '@patternfly/react-styles/css/components/Table/table-scrollable';
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
classNames,
|
|
15
15
|
favoritable
|
|
16
16
|
} from './utils';
|
|
17
|
+
import { IRowData, IExtraData } from './TableTypes';
|
|
17
18
|
import { draggable } from './utils/decorators/draggable';
|
|
18
19
|
import { treeRow } from './utils';
|
|
19
20
|
import { mergeProps } from './base/merge-props';
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
TdSelectType,
|
|
30
31
|
TdTreeRowType
|
|
31
32
|
} from './base/types';
|
|
33
|
+
import { TableContext } from './Table';
|
|
32
34
|
import cssStickyCellMinWidth from '@patternfly/react-tokens/dist/esm/c_table__sticky_cell_MinWidth';
|
|
33
35
|
import cssStickyCellInlineStart from '@patternfly/react-tokens/dist/esm/c_table__sticky_cell_InsetInlineStart';
|
|
34
36
|
import cssStickyCellInlineEnd from '@patternfly/react-tokens/dist/esm/c_table__sticky_cell_InsetInlineEnd';
|
|
@@ -193,6 +195,39 @@ const TdBase: React.FunctionComponent<TdProps> = ({
|
|
|
193
195
|
}
|
|
194
196
|
})
|
|
195
197
|
: null;
|
|
198
|
+
|
|
199
|
+
const { hasAnimations } = useContext(TableContext);
|
|
200
|
+
const updateAnimationClass = () => {
|
|
201
|
+
const ancestorControlRow = (cellRef as React.RefObject<HTMLElement | null>)?.current?.closest(
|
|
202
|
+
`.${styles.tableTr}.${styles.tableControlRow}`
|
|
203
|
+
);
|
|
204
|
+
const isControlRowExpanded = ancestorControlRow.classList.contains(styles.modifiers.expanded);
|
|
205
|
+
if (!isControlRowExpanded) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const isCurrentCellExpanded = (cellRef as React.RefObject<HTMLElement | null>)?.current?.classList.contains(
|
|
210
|
+
styles.modifiers.expanded
|
|
211
|
+
);
|
|
212
|
+
if (isCurrentCellExpanded) {
|
|
213
|
+
ancestorControlRow.classList.remove(styles.modifiers.noAnimateExpand);
|
|
214
|
+
} else {
|
|
215
|
+
ancestorControlRow.classList.add(styles.modifiers.noAnimateExpand);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const internalCompoundOnToggle = (
|
|
220
|
+
event: React.MouseEvent,
|
|
221
|
+
rowIndex: number,
|
|
222
|
+
colIndex: number,
|
|
223
|
+
isOpen: boolean,
|
|
224
|
+
rowData: IRowData,
|
|
225
|
+
extraData: IExtraData
|
|
226
|
+
) => {
|
|
227
|
+
hasAnimations && updateAnimationClass();
|
|
228
|
+
compoundExpandProp?.onToggle(event, rowIndex, colIndex, isOpen, rowData, extraData);
|
|
229
|
+
};
|
|
230
|
+
|
|
196
231
|
const compoundParams =
|
|
197
232
|
compoundExpandProp !== null
|
|
198
233
|
? compoundExpand(
|
|
@@ -207,7 +242,7 @@ const TdBase: React.FunctionComponent<TdProps> = ({
|
|
|
207
242
|
columnIndex: compoundExpandProp?.columnIndex,
|
|
208
243
|
column: {
|
|
209
244
|
extraParams: {
|
|
210
|
-
onExpand:
|
|
245
|
+
onExpand: internalCompoundOnToggle,
|
|
211
246
|
expandId: compoundExpandProp?.expandId
|
|
212
247
|
}
|
|
213
248
|
}
|
|
@@ -14,10 +14,12 @@ export interface TrProps extends Omit<React.HTMLProps<HTMLTableRowElement>, 'onR
|
|
|
14
14
|
innerRef?: React.Ref<any>;
|
|
15
15
|
/** Flag indicating the Tr is hidden */
|
|
16
16
|
isHidden?: boolean;
|
|
17
|
-
/** Only applicable to Tr within the Tbody
|
|
17
|
+
/** Only applicable to Tr within the Tbody and determines if the expandable row content is expanded or not.
|
|
18
18
|
* To prevent column widths from responding automatically when expandable rows are toggled, the width prop must also be passed into either the th or td component
|
|
19
19
|
*/
|
|
20
20
|
isExpanded?: boolean;
|
|
21
|
+
/** Flag to indicate that a row is expandable. Only applicable to a tr that is intended to collapse or expand. */
|
|
22
|
+
isExpandable?: boolean;
|
|
21
23
|
/** Only applicable to Tr within the Tbody: Whether the row is editable */
|
|
22
24
|
isEditable?: boolean;
|
|
23
25
|
/** Flag which adds hover styles for the clickable table row */
|
|
@@ -46,6 +48,7 @@ const TrBase: React.FunctionComponent<TrProps> = ({
|
|
|
46
48
|
children,
|
|
47
49
|
className,
|
|
48
50
|
isExpanded,
|
|
51
|
+
isExpandable,
|
|
49
52
|
isEditable,
|
|
50
53
|
isHidden = false,
|
|
51
54
|
isClickable = false,
|
|
@@ -75,9 +78,9 @@ const TrBase: React.FunctionComponent<TrProps> = ({
|
|
|
75
78
|
};
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
const rowIsHidden = isHidden || (isExpanded !== undefined && !isExpanded);
|
|
81
|
+
const rowIsHidden = isHidden || (isExpanded !== undefined && !isExpanded && isExpandable);
|
|
79
82
|
|
|
80
|
-
const { registerSelectableRow } = useContext(TableContext);
|
|
83
|
+
const { registerSelectableRow, hasAnimations } = useContext(TableContext);
|
|
81
84
|
|
|
82
85
|
useEffect(() => {
|
|
83
86
|
if (isSelectable && !rowIsHidden) {
|
|
@@ -96,7 +99,9 @@ const TrBase: React.FunctionComponent<TrProps> = ({
|
|
|
96
99
|
className={css(
|
|
97
100
|
styles.tableTr,
|
|
98
101
|
className,
|
|
99
|
-
|
|
102
|
+
// TODO: Revert this back to just isExpandable !== undefined and refine docs around expandable table structure --
|
|
103
|
+
// We should note where isExpanded and isExpandable props must be passed in
|
|
104
|
+
(isExpandable !== undefined || isExpanded !== undefined) && styles.tableExpandableRow,
|
|
100
105
|
isExpanded && styles.modifiers.expanded,
|
|
101
106
|
isEditable && inlineStyles.modifiers.inlineEditable,
|
|
102
107
|
isClickable && styles.modifiers.clickable,
|
|
@@ -110,6 +115,7 @@ const TrBase: React.FunctionComponent<TrProps> = ({
|
|
|
110
115
|
{...(isClickable && { tabIndex: 0 })}
|
|
111
116
|
aria-label={ariaLabel}
|
|
112
117
|
ref={innerRef}
|
|
118
|
+
{...(hasAnimations && rowIsHidden && { inert: '' })}
|
|
113
119
|
{...(onRowClick && { onClick: onRowClick, onKeyDown })}
|
|
114
120
|
{...ouiaProps}
|
|
115
121
|
{...props}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { ExpandableRowContent } from '../ExpandableRowContent';
|
|
3
|
+
import styles from '@patternfly/react-styles/css/components/Table/table';
|
|
4
|
+
|
|
5
|
+
test('Renders without children', () => {
|
|
6
|
+
render(<ExpandableRowContent data-testid="row-id" />);
|
|
7
|
+
|
|
8
|
+
expect(screen.getByTestId('row-id')).toBeInTheDocument();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('Renders with children', () => {
|
|
12
|
+
render(<ExpandableRowContent>Row content</ExpandableRowContent>);
|
|
13
|
+
|
|
14
|
+
expect(screen.getByText('Row content')).toBeVisible();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test(`Renders only with class ${styles.tableExpandableRowContent} by default`, () => {
|
|
18
|
+
render(<ExpandableRowContent>Row content</ExpandableRowContent>);
|
|
19
|
+
|
|
20
|
+
expect(screen.getByText('Row content')).toHaveClass(styles.tableExpandableRowContent, { exact: true });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test(`Renders with class ${styles.modifiers.noBackground} when hasNoBackground is true`, () => {
|
|
24
|
+
render(<ExpandableRowContent hasNoBackground>Row content</ExpandableRowContent>);
|
|
25
|
+
|
|
26
|
+
expect(screen.getByText('Row content')).toHaveClass(styles.modifiers.noBackground);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test(`Spreads additional props`, () => {
|
|
30
|
+
render(<ExpandableRowContent data-custom="true">Row content</ExpandableRowContent>);
|
|
31
|
+
|
|
32
|
+
expect(screen.getByText('Row content')).toHaveAttribute('data-custom', 'true');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('Matches snapshot', () => {
|
|
36
|
+
const { asFragment } = render(<ExpandableRowContent>Row content</ExpandableRowContent>);
|
|
37
|
+
|
|
38
|
+
expect(asFragment()).toMatchSnapshot();
|
|
39
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { Table } from '../Table';
|
|
3
|
+
import styles from '@patternfly/react-styles/css/components/Table/table';
|
|
4
|
+
|
|
5
|
+
test('Renders without children', () => {
|
|
6
|
+
render(<Table aria-label="Test table" />);
|
|
7
|
+
|
|
8
|
+
expect(screen.getByRole('grid', { name: 'Test table' })).toBeInTheDocument();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('Renders with children', () => {
|
|
12
|
+
render(
|
|
13
|
+
<Table aria-label="Test table">
|
|
14
|
+
<caption>Table caption</caption>
|
|
15
|
+
</Table>
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
expect(screen.getByRole('grid', { name: 'Test table' })).toHaveTextContent('Table caption');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('Renders with role="treegrid" when isTreeTable is true', () => {
|
|
22
|
+
render(<Table isTreeTable aria-label="Test table" />);
|
|
23
|
+
|
|
24
|
+
expect(screen.getByRole('treegrid', { name: 'Test table' })).toBeInTheDocument();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test(`Renders with class ${styles.table} by default`, () => {
|
|
28
|
+
render(<Table aria-label="Test table" />);
|
|
29
|
+
|
|
30
|
+
expect(screen.getByRole('grid', { name: 'Test table' })).toHaveClass(styles.table);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test(`Renders with a pf-m-grid class by default`, () => {
|
|
34
|
+
render(<Table aria-label="Test table" />);
|
|
35
|
+
|
|
36
|
+
expect(screen.getByRole('grid', { name: 'Test table' })).toHaveClass(/^pf-m-grid/);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test(`Renders with a pf-m-tree-view-grid class when isTreeTable is true`, () => {
|
|
40
|
+
render(<Table isTreeTable aria-label="Test table" />);
|
|
41
|
+
|
|
42
|
+
expect(screen.getByRole('treegrid', { name: 'Test table' })).not.toHaveClass(/^pf-m-grid/);
|
|
43
|
+
expect(screen.getByRole('treegrid', { name: 'Test table' })).toHaveClass(/^pf-m-tree-view-grid/);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test(`Does not render with class ${styles.modifiers.animateExpand} by default`, () => {
|
|
47
|
+
render(<Table aria-label="Test table" />);
|
|
48
|
+
|
|
49
|
+
expect(screen.getByRole('grid', { name: 'Test table' })).not.toHaveClass(styles.modifiers.animateExpand);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test(`Renders with class ${styles.modifiers.animateExpand} hasAnimations is true`, () => {
|
|
53
|
+
render(<Table hasAnimations aria-label="Test table" />);
|
|
54
|
+
|
|
55
|
+
expect(screen.getByRole('grid', { name: 'Test table' })).toHaveClass(styles.modifiers.animateExpand);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('Matches snapshot without children', () => {
|
|
59
|
+
const { asFragment } = render(<Table />);
|
|
60
|
+
|
|
61
|
+
expect(asFragment()).toMatchSnapshot();
|
|
62
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { Tr } from '../Tr';
|
|
3
|
+
import styles from '@patternfly/react-styles/css/components/Table/table';
|
|
4
|
+
|
|
5
|
+
test('Renders without children', () => {
|
|
6
|
+
render(
|
|
7
|
+
<table>
|
|
8
|
+
<tbody>
|
|
9
|
+
<Tr />
|
|
10
|
+
</tbody>
|
|
11
|
+
</table>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
expect(screen.getByRole('row')).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('Renders with children', () => {
|
|
18
|
+
render(
|
|
19
|
+
<table>
|
|
20
|
+
<tbody>
|
|
21
|
+
<Tr>
|
|
22
|
+
<td>Row content</td>
|
|
23
|
+
</Tr>
|
|
24
|
+
</tbody>
|
|
25
|
+
</table>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(screen.getByRole('row')).toHaveTextContent('Row content');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test(`Does not render as hidden by default`, () => {
|
|
32
|
+
render(
|
|
33
|
+
<table>
|
|
34
|
+
<tbody>
|
|
35
|
+
<Tr />
|
|
36
|
+
</tbody>
|
|
37
|
+
</table>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
expect(screen.getByRole('row')).not.toHaveAttribute('hidden');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test(`Renders as hidden when isHidden is true`, () => {
|
|
44
|
+
render(
|
|
45
|
+
<table>
|
|
46
|
+
<tbody>
|
|
47
|
+
<Tr isHidden />
|
|
48
|
+
</tbody>
|
|
49
|
+
</table>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(screen.queryByRole('row')).not.toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('Matches snapshot without children', () => {
|
|
56
|
+
const { asFragment } = render(
|
|
57
|
+
<table>
|
|
58
|
+
<tbody>
|
|
59
|
+
<Tr />
|
|
60
|
+
</tbody>
|
|
61
|
+
</table>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(asFragment()).toMatchSnapshot();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('Matches snapshot with children', () => {
|
|
68
|
+
const { asFragment } = render(
|
|
69
|
+
<table>
|
|
70
|
+
<tbody>
|
|
71
|
+
<Tr>
|
|
72
|
+
<td>Row content</td>
|
|
73
|
+
</Tr>
|
|
74
|
+
</tbody>
|
|
75
|
+
</table>
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(asFragment()).toMatchSnapshot();
|
|
79
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Matches snapshot without children 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<table
|
|
6
|
+
class="pf-v6-c-table pf-m-grid-md"
|
|
7
|
+
data-ouia-component-id="OUIA-Generated-Table-9"
|
|
8
|
+
data-ouia-component-type="PF6/Table"
|
|
9
|
+
data-ouia-safe="true"
|
|
10
|
+
role="grid"
|
|
11
|
+
/>
|
|
12
|
+
</DocumentFragment>
|
|
13
|
+
`;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Matches snapshot with children 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<table>
|
|
6
|
+
<tbody>
|
|
7
|
+
<tr
|
|
8
|
+
class="pf-v6-c-table__tr"
|
|
9
|
+
data-ouia-component-id="OUIA-Generated-TableRow-6"
|
|
10
|
+
data-ouia-component-type="PF6/TableRow"
|
|
11
|
+
data-ouia-safe="true"
|
|
12
|
+
>
|
|
13
|
+
<td>
|
|
14
|
+
Row content
|
|
15
|
+
</td>
|
|
16
|
+
</tr>
|
|
17
|
+
</tbody>
|
|
18
|
+
</table>
|
|
19
|
+
</DocumentFragment>
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
exports[`Matches snapshot without children 1`] = `
|
|
23
|
+
<DocumentFragment>
|
|
24
|
+
<table>
|
|
25
|
+
<tbody>
|
|
26
|
+
<tr
|
|
27
|
+
class="pf-v6-c-table__tr"
|
|
28
|
+
data-ouia-component-id="OUIA-Generated-TableRow-5"
|
|
29
|
+
data-ouia-component-type="PF6/TableRow"
|
|
30
|
+
data-ouia-safe="true"
|
|
31
|
+
/>
|
|
32
|
+
</tbody>
|
|
33
|
+
</table>
|
|
34
|
+
</DocumentFragment>
|
|
35
|
+
`;
|
|
@@ -243,6 +243,8 @@ export type OnExpand = (
|
|
|
243
243
|
) => void;
|
|
244
244
|
```
|
|
245
245
|
|
|
246
|
+
For a more complex compound expandable implementation with nested tables, see our [table compound expansion demo](/components/table/react-demos/compound-expansion).
|
|
247
|
+
|
|
246
248
|
```ts file="TableCompoundExpandable.tsx"
|
|
247
249
|
|
|
248
250
|
```
|
|
@@ -4,7 +4,6 @@ import { Table, Thead, Tr, Th, Tbody, Td, TdProps, ExpandableRowContent } from '
|
|
|
4
4
|
import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon';
|
|
5
5
|
import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon';
|
|
6
6
|
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
|
|
7
|
-
import spacing from '@patternfly/react-styles/css/utilities/Spacing/spacing';
|
|
8
7
|
|
|
9
8
|
interface Repository {
|
|
10
9
|
name: string;
|
|
@@ -59,7 +58,7 @@ export const TableCompoundExpandable: React.FunctionComponent = () => {
|
|
|
59
58
|
});
|
|
60
59
|
|
|
61
60
|
return (
|
|
62
|
-
<Table aria-label="Compound expandable table">
|
|
61
|
+
<Table aria-label="Compound expandable table" isExpandable hasAnimations>
|
|
63
62
|
<Thead>
|
|
64
63
|
<Tr>
|
|
65
64
|
<Th>{columnNames.name}</Th>
|
|
@@ -75,7 +74,7 @@ export const TableCompoundExpandable: React.FunctionComponent = () => {
|
|
|
75
74
|
const isRowExpanded = !!expandedCellKey;
|
|
76
75
|
return (
|
|
77
76
|
<Tbody key={repo.name} isExpanded={isRowExpanded}>
|
|
78
|
-
<Tr isControlRow>
|
|
77
|
+
<Tr isExpanded={isRowExpanded} isControlRow>
|
|
79
78
|
<Td width={25} dataLabel={columnNames.name} component="th">
|
|
80
79
|
<a href="#">{repo.name}</a>
|
|
81
80
|
</Td>
|
|
@@ -107,24 +106,27 @@ export const TableCompoundExpandable: React.FunctionComponent = () => {
|
|
|
107
106
|
<a href="#">Open in GitHub</a>
|
|
108
107
|
</Td>
|
|
109
108
|
</Tr>
|
|
110
|
-
{
|
|
111
|
-
<
|
|
112
|
-
<
|
|
113
|
-
<
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
109
|
+
<Tr isExpanded={columnNames[expandedCellKey] === columnNames.branches} isExpandable>
|
|
110
|
+
<Td dataLabel={columnNames[expandedCellKey]} colSpan={6}>
|
|
111
|
+
<ExpandableRowContent>
|
|
112
|
+
<div>Expanded content for {repo.name}: branches goes here!</div>
|
|
113
|
+
</ExpandableRowContent>
|
|
114
|
+
</Td>
|
|
115
|
+
</Tr>
|
|
116
|
+
<Tr isExpanded={columnNames[expandedCellKey] === columnNames.prs} isExpandable>
|
|
117
|
+
<Td dataLabel={columnNames[expandedCellKey]} colSpan={6}>
|
|
118
|
+
<ExpandableRowContent>
|
|
119
|
+
<div>Expanded content for {repo.name}: prs goes here!</div>
|
|
120
|
+
</ExpandableRowContent>
|
|
121
|
+
</Td>
|
|
122
|
+
</Tr>
|
|
123
|
+
<Tr isExpanded={columnNames[expandedCellKey] === columnNames.workspaces} isExpandable>
|
|
124
|
+
<Td dataLabel={columnNames[expandedCellKey]} colSpan={6}>
|
|
125
|
+
<ExpandableRowContent>
|
|
126
|
+
<div>Expanded content for {repo.name}: workspaces goes here!</div>
|
|
127
|
+
</ExpandableRowContent>
|
|
128
|
+
</Td>
|
|
129
|
+
</Tr>
|
|
128
130
|
</Tbody>
|
|
129
131
|
);
|
|
130
132
|
})}
|
|
@@ -116,7 +116,12 @@ export const TableExpandable: React.FunctionComponent = () => {
|
|
|
116
116
|
id="toggle-compact"
|
|
117
117
|
name="toggle-compact"
|
|
118
118
|
/>
|
|
119
|
-
<Table
|
|
119
|
+
<Table
|
|
120
|
+
isExpandable
|
|
121
|
+
hasAnimations
|
|
122
|
+
aria-label="Expandable table"
|
|
123
|
+
variant={isExampleCompact ? 'compact' : undefined}
|
|
124
|
+
>
|
|
120
125
|
<Thead>
|
|
121
126
|
<Tr>
|
|
122
127
|
<Th screenReaderText="Row expansion" />
|
|
@@ -152,7 +157,7 @@ export const TableExpandable: React.FunctionComponent = () => {
|
|
|
152
157
|
}
|
|
153
158
|
return (
|
|
154
159
|
<Tbody key={repo.name} isExpanded={isRepoExpanded(repo)}>
|
|
155
|
-
<Tr>
|
|
160
|
+
<Tr isExpanded={isRepoExpanded(repo)}>
|
|
156
161
|
<Td
|
|
157
162
|
expand={
|
|
158
163
|
repo.details
|
|
@@ -172,7 +177,7 @@ export const TableExpandable: React.FunctionComponent = () => {
|
|
|
172
177
|
<Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td>
|
|
173
178
|
</Tr>
|
|
174
179
|
{repo.details ? (
|
|
175
|
-
<Tr isExpanded={isRepoExpanded(repo)}>
|
|
180
|
+
<Tr isExpandable isExpanded={isRepoExpanded(repo)}>
|
|
176
181
|
{!childIsFullWidth ? <Td /> : null}
|
|
177
182
|
{repo.details.detail1 ? (
|
|
178
183
|
<Td dataLabel="Repo detail 1" noPadding={childHasNoPadding} colSpan={detail1Colspan}>
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
|
|
2
|
-
/* eslint-disable camelcase */
|
|
3
2
|
import t_global_background_color_secondary_default from '@patternfly/react-tokens/dist/esm/t_global_background_color_secondary_default';
|
|
4
3
|
|
|
5
4
|
interface Repository {
|
|
@@ -61,7 +61,7 @@ export const TableNestedExpandable: React.FunctionComponent = () => {
|
|
|
61
61
|
|
|
62
62
|
return (
|
|
63
63
|
<InnerScrollContainer>
|
|
64
|
-
<Table aria-label="Nested column headers with expandable rows table" gridBreakPoint="">
|
|
64
|
+
<Table isExpandable hasAnimations aria-label="Nested column headers with expandable rows table" gridBreakPoint="">
|
|
65
65
|
<Thead hasNestedHeader>
|
|
66
66
|
<Tr>
|
|
67
67
|
<Th screenReaderText="Row expansion" rowSpan={2} />
|
|
@@ -85,7 +85,7 @@ export const TableNestedExpandable: React.FunctionComponent = () => {
|
|
|
85
85
|
</Thead>
|
|
86
86
|
{teams.map((team, rowIndex) => (
|
|
87
87
|
<Tbody key={team.name} isExpanded={isTeamExpanded(team)}>
|
|
88
|
-
<Tr>
|
|
88
|
+
<Tr isExpanded={isTeamExpanded(team)}>
|
|
89
89
|
<Td
|
|
90
90
|
expand={{
|
|
91
91
|
rowIndex,
|
|
@@ -104,7 +104,7 @@ export const TableNestedExpandable: React.FunctionComponent = () => {
|
|
|
104
104
|
</Button>
|
|
105
105
|
</Td>
|
|
106
106
|
</Tr>
|
|
107
|
-
<Tr isExpanded={isTeamExpanded(team)}>
|
|
107
|
+
<Tr isExpanded={isTeamExpanded(team)} isExpandable>
|
|
108
108
|
<Td dataLabel={`Team ${team.name} description`} colSpan={6}>
|
|
109
109
|
<ExpandableRowContent>{team.description}</ExpandableRowContent>
|
|
110
110
|
</Td>
|
|
@@ -128,7 +128,7 @@ export const TableExpandable: React.FunctionComponent = () => {
|
|
|
128
128
|
];
|
|
129
129
|
|
|
130
130
|
return (
|
|
131
|
-
<Table aria-label="Simple table">
|
|
131
|
+
<Table isExpandable hasAnimations aria-label="Simple table">
|
|
132
132
|
<Thead>
|
|
133
133
|
<Tr>
|
|
134
134
|
<Th screenReaderText="Row expansion" />
|
|
@@ -141,7 +141,7 @@ export const TableExpandable: React.FunctionComponent = () => {
|
|
|
141
141
|
</Thead>
|
|
142
142
|
{repositories.map((repo, rowIndex) => (
|
|
143
143
|
<Tbody key={repo.name} isExpanded={isRepoExpanded(repo)}>
|
|
144
|
-
<Tr>
|
|
144
|
+
<Tr isExpanded={isRepoExpanded(repo)}>
|
|
145
145
|
<Td
|
|
146
146
|
expand={
|
|
147
147
|
repo.nestedComponent
|
|
@@ -163,7 +163,7 @@ export const TableExpandable: React.FunctionComponent = () => {
|
|
|
163
163
|
</Td>
|
|
164
164
|
</Tr>
|
|
165
165
|
{repo.nestedComponent ? (
|
|
166
|
-
<Tr isExpanded={isRepoExpanded(repo)}>
|
|
166
|
+
<Tr isExpandable isExpanded={isRepoExpanded(repo)}>
|
|
167
167
|
<Td
|
|
168
168
|
noPadding={repo.noPadding}
|
|
169
169
|
dataLabel={`${columnNames.name} expended`}
|