@patternfly/react-table 6.3.0-prerelease.24 → 6.3.0-prerelease.26
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 +10 -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.map +1 -1
- package/dist/esm/components/Table/Tr.js +2 -2
- package/dist/esm/components/Table/Tr.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.map +1 -1
- package/dist/js/components/Table/Tr.js +2 -2
- package/dist/js/components/Table/Tr.js.map +1 -1
- package/dist/umd/assets/{output-B7KoXseA.css → output-BKNhQUbO.css} +3407 -3401
- package/dist/umd/react-table.min.js +1 -1
- 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 +2 -1
- 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 +6 -1
- package/src/components/Table/examples/TableNestedExpandable.tsx +3 -3
- package/src/components/Table/examples/TableNestedTableExpandable.tsx +1 -1
- package/src/components/Table/examples/TableStripedExpandable.tsx +9 -3
- package/src/demos/examples/TableCompoundExpansion.tsx +87 -84
- package/src/demos/examples/TableExpandCollapseAll.tsx +1 -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.26",
|
|
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.26",
|
|
44
|
+
"@patternfly/react-icons": "^6.3.0-prerelease.8",
|
|
45
|
+
"@patternfly/react-styles": "^6.3.0-prerelease.8",
|
|
46
|
+
"@patternfly/react-tokens": "^6.3.0-prerelease.8",
|
|
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": "f7974fbc0bcfaeff92cb05a4604bb48f4df54375"
|
|
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
|
}
|
|
@@ -80,7 +80,7 @@ const TrBase: React.FunctionComponent<TrProps> = ({
|
|
|
80
80
|
|
|
81
81
|
const rowIsHidden = isHidden || (isExpanded !== undefined && !isExpanded && isExpandable);
|
|
82
82
|
|
|
83
|
-
const { registerSelectableRow } = useContext(TableContext);
|
|
83
|
+
const { registerSelectableRow, hasAnimations } = useContext(TableContext);
|
|
84
84
|
|
|
85
85
|
useEffect(() => {
|
|
86
86
|
if (isSelectable && !rowIsHidden) {
|
|
@@ -113,6 +113,7 @@ const TrBase: React.FunctionComponent<TrProps> = ({
|
|
|
113
113
|
{...(isClickable && { tabIndex: 0 })}
|
|
114
114
|
aria-label={ariaLabel}
|
|
115
115
|
ref={innerRef}
|
|
116
|
+
{...(hasAnimations && rowIsHidden && { inert: '' })}
|
|
116
117
|
{...(onRowClick && { onClick: onRowClick, onKeyDown })}
|
|
117
118
|
{...ouiaProps}
|
|
118
119
|
{...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" />
|
|
@@ -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 isExpandable aria-label="Simple table">
|
|
131
|
+
<Table isExpandable hasAnimations aria-label="Simple table">
|
|
132
132
|
<Thead>
|
|
133
133
|
<Tr>
|
|
134
134
|
<Th screenReaderText="Row expansion" />
|
|
@@ -112,7 +112,13 @@ export const TableStripedExpandable: React.FunctionComponent = () => {
|
|
|
112
112
|
id="toggle-compact-striped"
|
|
113
113
|
name="toggle-compact-striped"
|
|
114
114
|
/>
|
|
115
|
-
<Table
|
|
115
|
+
<Table
|
|
116
|
+
aria-label="Expandable table"
|
|
117
|
+
variant={isExampleCompact ? 'compact' : undefined}
|
|
118
|
+
isStriped
|
|
119
|
+
isExpandable
|
|
120
|
+
hasAnimations
|
|
121
|
+
>
|
|
116
122
|
<Thead>
|
|
117
123
|
<Tr>
|
|
118
124
|
<Th screenReaderText="Row expansion" />
|
|
@@ -148,7 +154,7 @@ export const TableStripedExpandable: React.FunctionComponent = () => {
|
|
|
148
154
|
}
|
|
149
155
|
return (
|
|
150
156
|
<Tbody key={repo.name} isExpanded={isRepoExpanded(repo)}>
|
|
151
|
-
<Tr>
|
|
157
|
+
<Tr isExpanded={isRepoExpanded(repo)}>
|
|
152
158
|
<Td
|
|
153
159
|
expand={
|
|
154
160
|
repo.details
|
|
@@ -167,7 +173,7 @@ export const TableStripedExpandable: React.FunctionComponent = () => {
|
|
|
167
173
|
<Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td>
|
|
168
174
|
</Tr>
|
|
169
175
|
{repo.details ? (
|
|
170
|
-
<Tr isExpanded={isRepoExpanded(repo)}>
|
|
176
|
+
<Tr isExpanded={isRepoExpanded(repo)} isExpandable>
|
|
171
177
|
{!childIsFullWidth ? <Td /> : null}
|
|
172
178
|
{repo.details.detail1 ? (
|
|
173
179
|
<Td dataLabel="Repo detail 1" noPadding={childHasNoPadding} colSpan={detail1Colspan}>
|