@patternfly/react-table 4.90.0 → 4.90.3
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 +24 -0
- package/dist/esm/components/Table/base/provider.d.ts +3 -3
- package/dist/esm/components/Table/base/types.d.ts +3 -3
- package/dist/esm/components/TableComposable/TableComposable.d.ts +10 -1
- package/dist/esm/components/TableComposable/TableComposable.d.ts.map +1 -1
- package/dist/esm/components/TableComposable/TableComposable.js +23 -2
- package/dist/esm/components/TableComposable/TableComposable.js.map +1 -1
- package/dist/esm/components/TableComposable/Tr.d.ts +3 -1
- package/dist/esm/components/TableComposable/Tr.d.ts.map +1 -1
- package/dist/esm/components/TableComposable/Tr.js +18 -2
- package/dist/esm/components/TableComposable/Tr.js.map +1 -1
- package/dist/js/components/Table/base/provider.d.ts +3 -3
- package/dist/js/components/Table/base/types.d.ts +3 -3
- package/dist/js/components/TableComposable/TableComposable.d.ts +10 -1
- package/dist/js/components/TableComposable/TableComposable.d.ts.map +1 -1
- package/dist/js/components/TableComposable/TableComposable.js +24 -3
- package/dist/js/components/TableComposable/TableComposable.js.map +1 -1
- package/dist/js/components/TableComposable/Tr.d.ts +3 -1
- package/dist/js/components/TableComposable/Tr.d.ts.map +1 -1
- package/dist/js/components/TableComposable/Tr.js +18 -2
- package/dist/js/components/TableComposable/Tr.js.map +1 -1
- package/dist/umd/react-table.css +1175 -385
- package/dist/umd/react-table.js +67 -19
- package/dist/umd/react-table.min.css +798 -8
- package/dist/umd/react-table.min.js +5 -5
- package/package.json +6 -6
- package/src/components/TableComposable/TableComposable.tsx +67 -22
- package/src/components/TableComposable/Tr.tsx +45 -20
- package/src/components/TableComposable/examples/ComposableTableHoverable.tsx +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-table",
|
|
3
|
-
"version": "4.90.
|
|
3
|
+
"version": "4.90.3",
|
|
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",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"clean": "rimraf dist"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@patternfly/react-core": "^4.221.
|
|
35
|
-
"@patternfly/react-icons": "^4.72.
|
|
36
|
-
"@patternfly/react-styles": "^4.71.
|
|
37
|
-
"@patternfly/react-tokens": "^4.73.
|
|
34
|
+
"@patternfly/react-core": "^4.221.3",
|
|
35
|
+
"@patternfly/react-icons": "^4.72.3",
|
|
36
|
+
"@patternfly/react-styles": "^4.71.3",
|
|
37
|
+
"@patternfly/react-tokens": "^4.73.3",
|
|
38
38
|
"lodash": "^4.17.19",
|
|
39
39
|
"tslib": "^2.0.0"
|
|
40
40
|
},
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"react": "^16.8.0 || ^17.0.0",
|
|
47
47
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c439640ea149012cf32e138f5b9de05ccf3e26f9"
|
|
50
50
|
}
|
|
@@ -59,8 +59,20 @@ export interface TableComposableProps extends React.HTMLProps<HTMLTableElement>,
|
|
|
59
59
|
isExpandable?: boolean;
|
|
60
60
|
/** Collection of column spans for nested headers. Deprecated: see https://github.com/patternfly/patternfly/issues/4584 */
|
|
61
61
|
nestedHeaderColumnSpans?: number[];
|
|
62
|
+
/** Flag to apply a caption element with visually hidden instructions that improves a11y for tables with selectable rows. If this prop is set to true other caption elements should not be passed as children of this table, and you should instead use the selectableRowCaptionText prop. */
|
|
63
|
+
hasSelectableRowCaption?: boolean;
|
|
64
|
+
/** Visible text to add alongside the hidden a11y caption for tables with selectable rows. This prop must be used to add custom caption content to the table when the hasSelectableRowCaption prop is set to true. */
|
|
65
|
+
selectableRowCaptionText?: string;
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
interface TableComposableContextProps {
|
|
69
|
+
registerSelectableRow?: () => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const TableComposableContext = React.createContext<TableComposableContextProps>({
|
|
73
|
+
registerSelectableRow: () => {}
|
|
74
|
+
});
|
|
75
|
+
|
|
64
76
|
const TableComposableBase: React.FunctionComponent<TableComposableProps> = ({
|
|
65
77
|
children,
|
|
66
78
|
className,
|
|
@@ -79,10 +91,15 @@ const TableComposableBase: React.FunctionComponent<TableComposableProps> = ({
|
|
|
79
91
|
isExpandable = false,
|
|
80
92
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
81
93
|
nestedHeaderColumnSpans,
|
|
94
|
+
hasSelectableRowCaption,
|
|
95
|
+
selectableRowCaptionText,
|
|
82
96
|
...props
|
|
83
97
|
}: TableComposableProps) => {
|
|
84
98
|
const tableRef = innerRef || React.useRef(null);
|
|
85
99
|
|
|
100
|
+
const [hasSelectableRows, setHasSelectableRows] = React.useState(false);
|
|
101
|
+
const [tableCaption, setTableCaption] = React.useState<JSX.Element | undefined>();
|
|
102
|
+
|
|
86
103
|
React.useEffect(() => {
|
|
87
104
|
document.addEventListener('keydown', handleKeys);
|
|
88
105
|
|
|
@@ -97,6 +114,27 @@ const TableComposableBase: React.FunctionComponent<TableComposableProps> = ({
|
|
|
97
114
|
};
|
|
98
115
|
}, [tableRef, tableRef.current]);
|
|
99
116
|
|
|
117
|
+
React.useEffect(() => {
|
|
118
|
+
if (selectableRowCaptionText) {
|
|
119
|
+
setTableCaption(
|
|
120
|
+
<caption>
|
|
121
|
+
{selectableRowCaptionText}
|
|
122
|
+
<div className="pf-screen-reader">
|
|
123
|
+
This table has selectable rows. It can be navigated by row using tab, and each row can be selected using
|
|
124
|
+
space or enter.
|
|
125
|
+
</div>
|
|
126
|
+
</caption>
|
|
127
|
+
);
|
|
128
|
+
} else {
|
|
129
|
+
setTableCaption(
|
|
130
|
+
<caption className="pf-screen-reader">
|
|
131
|
+
This table has selectable rows. It can be navigated by row using tab, and each row can be selected using space
|
|
132
|
+
or enter.
|
|
133
|
+
</caption>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}, [selectableRowCaptionText]);
|
|
137
|
+
|
|
100
138
|
const ouiaProps = useOUIAProps('Table', ouiaId, ouiaSafe);
|
|
101
139
|
const grid =
|
|
102
140
|
stylesGrid.modifiers?.[
|
|
@@ -147,29 +185,36 @@ const TableComposableBase: React.FunctionComponent<TableComposableProps> = ({
|
|
|
147
185
|
);
|
|
148
186
|
};
|
|
149
187
|
|
|
188
|
+
const registerSelectableRow = () => {
|
|
189
|
+
!hasSelectableRows && setHasSelectableRows(true);
|
|
190
|
+
};
|
|
191
|
+
|
|
150
192
|
return (
|
|
151
|
-
<
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
className
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
193
|
+
<TableComposableContext.Provider value={{ registerSelectableRow }}>
|
|
194
|
+
<table
|
|
195
|
+
aria-label={ariaLabel}
|
|
196
|
+
role={role}
|
|
197
|
+
className={css(
|
|
198
|
+
className,
|
|
199
|
+
styles.table,
|
|
200
|
+
isTreeTable ? treeGrid : grid,
|
|
201
|
+
styles.modifiers[variant],
|
|
202
|
+
!borders && styles.modifiers.noBorderRows,
|
|
203
|
+
isStickyHeader && styles.modifiers.stickyHeader,
|
|
204
|
+
isTreeTable && stylesTreeView.modifiers.treeView,
|
|
205
|
+
isStriped && styles.modifiers.striped,
|
|
206
|
+
isExpandable && styles.modifiers.expandable,
|
|
207
|
+
isNested && 'pf-m-nested'
|
|
208
|
+
)}
|
|
209
|
+
ref={tableRef}
|
|
210
|
+
{...(isTreeTable && { role: 'treegrid' })}
|
|
211
|
+
{...ouiaProps}
|
|
212
|
+
{...props}
|
|
213
|
+
>
|
|
214
|
+
{hasSelectableRowCaption && hasSelectableRows && tableCaption}
|
|
215
|
+
{children}
|
|
216
|
+
</table>
|
|
217
|
+
</TableComposableContext.Provider>
|
|
173
218
|
);
|
|
174
219
|
};
|
|
175
220
|
|
|
@@ -3,6 +3,7 @@ import { useOUIAProps, OUIAProps } from '@patternfly/react-core';
|
|
|
3
3
|
import styles from '@patternfly/react-styles/css/components/Table/table';
|
|
4
4
|
import inlineStyles from '@patternfly/react-styles/css/components/InlineEdit/inline-edit';
|
|
5
5
|
import { css } from '@patternfly/react-styles';
|
|
6
|
+
import { TableComposableContext } from './TableComposable';
|
|
6
7
|
|
|
7
8
|
export interface TrProps extends React.HTMLProps<HTMLTableRowElement>, OUIAProps {
|
|
8
9
|
/** Content rendered inside the <tr> row */
|
|
@@ -25,6 +26,8 @@ export interface TrProps extends React.HTMLProps<HTMLTableRowElement>, OUIAProps
|
|
|
25
26
|
isStriped?: boolean;
|
|
26
27
|
/** An event handler for the row */
|
|
27
28
|
onRowClick?: (event?: React.KeyboardEvent | React.MouseEvent) => void;
|
|
29
|
+
/** Flag indicating that the row is selectable */
|
|
30
|
+
isSelectable?: boolean;
|
|
28
31
|
/** Flag indicating the spacing offset of the first cell should be reset */
|
|
29
32
|
resetOffset?: boolean;
|
|
30
33
|
}
|
|
@@ -43,9 +46,12 @@ const TrBase: React.FunctionComponent<TrProps> = ({
|
|
|
43
46
|
ouiaSafe = true,
|
|
44
47
|
resetOffset = false,
|
|
45
48
|
onRowClick,
|
|
49
|
+
isSelectable,
|
|
50
|
+
'aria-label': passedAriaLabel,
|
|
46
51
|
...props
|
|
47
52
|
}: TrProps) => {
|
|
48
53
|
const ouiaProps = useOUIAProps('TableRow', ouiaId, ouiaSafe);
|
|
54
|
+
const [computedAriaLabel, setComputedAriaLabel] = React.useState<string | undefined>('');
|
|
49
55
|
|
|
50
56
|
let onKeyDown = null;
|
|
51
57
|
if (onRowClick) {
|
|
@@ -57,27 +63,46 @@ const TrBase: React.FunctionComponent<TrProps> = ({
|
|
|
57
63
|
};
|
|
58
64
|
}
|
|
59
65
|
|
|
66
|
+
const rowIsHidden = isHidden || (isExpanded !== undefined && !isExpanded);
|
|
67
|
+
|
|
68
|
+
const { registerSelectableRow } = React.useContext(TableComposableContext);
|
|
69
|
+
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
if (isSelectable && !rowIsHidden) {
|
|
72
|
+
setComputedAriaLabel(`${isRowSelected ? 'Selected' : 'Unselected'}, selectable row.`);
|
|
73
|
+
registerSelectableRow();
|
|
74
|
+
} else {
|
|
75
|
+
setComputedAriaLabel(undefined);
|
|
76
|
+
}
|
|
77
|
+
}, [isRowSelected, isSelectable, registerSelectableRow, rowIsHidden]);
|
|
78
|
+
|
|
79
|
+
const ariaLabel = passedAriaLabel || computedAriaLabel;
|
|
80
|
+
|
|
60
81
|
return (
|
|
61
|
-
|
|
62
|
-
className={
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
<>
|
|
83
|
+
{isSelectable && <output className="pf-screen-reader">{ariaLabel}</output>}
|
|
84
|
+
<tr
|
|
85
|
+
className={css(
|
|
86
|
+
className,
|
|
87
|
+
isExpanded !== undefined && styles.tableExpandableRow,
|
|
88
|
+
isExpanded && styles.modifiers.expanded,
|
|
89
|
+
isEditable && inlineStyles.modifiers.inlineEditable,
|
|
90
|
+
isHoverable && styles.modifiers.hoverable,
|
|
91
|
+
isRowSelected && styles.modifiers.selected,
|
|
92
|
+
isStriped && styles.modifiers.striped,
|
|
93
|
+
resetOffset && styles.modifiers.firstCellOffsetReset
|
|
94
|
+
)}
|
|
95
|
+
hidden={rowIsHidden}
|
|
96
|
+
{...(isHoverable && { tabIndex: 0 })}
|
|
97
|
+
aria-label={ariaLabel}
|
|
98
|
+
ref={innerRef}
|
|
99
|
+
{...(onRowClick && { onClick: onRowClick, onKeyDown })}
|
|
100
|
+
{...ouiaProps}
|
|
101
|
+
{...props}
|
|
102
|
+
>
|
|
103
|
+
{children}
|
|
104
|
+
</tr>
|
|
105
|
+
</>
|
|
81
106
|
);
|
|
82
107
|
};
|
|
83
108
|
|
|
@@ -36,7 +36,7 @@ export const ComposableTableHoverable: React.FunctionComponent = () => {
|
|
|
36
36
|
const isRepoSelected = (repo: Repository) => selectedRepoNames.includes(repo.name);
|
|
37
37
|
|
|
38
38
|
return (
|
|
39
|
-
<TableComposable aria-label="Hoverable table">
|
|
39
|
+
<TableComposable aria-label="Hoverable table" hasSelectableRowCaption>
|
|
40
40
|
<Thead>
|
|
41
41
|
<Tr>
|
|
42
42
|
<Th>{columnNames.name}</Th>
|
|
@@ -51,6 +51,7 @@ export const ComposableTableHoverable: React.FunctionComponent = () => {
|
|
|
51
51
|
<Tr
|
|
52
52
|
key={repo.name}
|
|
53
53
|
onRowClick={() => setRepoSelected(repo, !isRepoSelected(repo))}
|
|
54
|
+
isSelectable
|
|
54
55
|
isHoverable
|
|
55
56
|
isRowSelected={isRepoSelected(repo)}
|
|
56
57
|
>
|