@patternfly/react-table 4.89.2 → 4.90.2

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/esm/components/Table/base/provider.d.ts +3 -3
  3. package/dist/esm/components/Table/base/types.d.ts +3 -3
  4. package/dist/esm/components/TableComposable/TableComposable.d.ts +10 -1
  5. package/dist/esm/components/TableComposable/TableComposable.d.ts.map +1 -1
  6. package/dist/esm/components/TableComposable/TableComposable.js +23 -2
  7. package/dist/esm/components/TableComposable/TableComposable.js.map +1 -1
  8. package/dist/esm/components/TableComposable/Tr.d.ts +3 -1
  9. package/dist/esm/components/TableComposable/Tr.d.ts.map +1 -1
  10. package/dist/esm/components/TableComposable/Tr.js +18 -2
  11. package/dist/esm/components/TableComposable/Tr.js.map +1 -1
  12. package/dist/js/components/Table/base/provider.d.ts +3 -3
  13. package/dist/js/components/Table/base/types.d.ts +3 -3
  14. package/dist/js/components/TableComposable/TableComposable.d.ts +10 -1
  15. package/dist/js/components/TableComposable/TableComposable.d.ts.map +1 -1
  16. package/dist/js/components/TableComposable/TableComposable.js +24 -3
  17. package/dist/js/components/TableComposable/TableComposable.js.map +1 -1
  18. package/dist/js/components/TableComposable/Tr.d.ts +3 -1
  19. package/dist/js/components/TableComposable/Tr.d.ts.map +1 -1
  20. package/dist/js/components/TableComposable/Tr.js +18 -2
  21. package/dist/js/components/TableComposable/Tr.js.map +1 -1
  22. package/dist/umd/react-table.css +861 -71
  23. package/dist/umd/react-table.js +91 -22
  24. package/dist/umd/react-table.min.css +2656 -1866
  25. package/dist/umd/react-table.min.js +6 -6
  26. package/package.json +6 -6
  27. package/src/components/TableComposable/TableComposable.tsx +67 -22
  28. package/src/components/TableComposable/Tr.tsx +45 -20
  29. package/src/components/TableComposable/examples/ComposableTableHoverable.tsx +2 -1
  30. package/src/demos/Table.md +5 -0
  31. package/src/demos/table-demos/StickyFirstColumn.jsx +210 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-table",
3
- "version": "4.89.2",
3
+ "version": "4.90.2",
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.220.2",
35
- "@patternfly/react-icons": "^4.71.2",
36
- "@patternfly/react-styles": "^4.70.2",
37
- "@patternfly/react-tokens": "^4.72.2",
34
+ "@patternfly/react-core": "^4.221.2",
35
+ "@patternfly/react-icons": "^4.72.2",
36
+ "@patternfly/react-styles": "^4.71.2",
37
+ "@patternfly/react-tokens": "^4.73.2",
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": "a8c59ffa9bb424d46036dabe35c777b999fb11d6"
49
+ "gitHead": "eeeefa74fca5d5c4739cc6113028a2cca51f0fb7"
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
- <table
152
- aria-label={ariaLabel}
153
- role={role}
154
- className={css(
155
- className,
156
- styles.table,
157
- isTreeTable ? treeGrid : grid,
158
- styles.modifiers[variant],
159
- !borders && styles.modifiers.noBorderRows,
160
- isStickyHeader && styles.modifiers.stickyHeader,
161
- isTreeTable && stylesTreeView.modifiers.treeView,
162
- isStriped && styles.modifiers.striped,
163
- isExpandable && styles.modifiers.expandable,
164
- isNested && 'pf-m-nested'
165
- )}
166
- ref={tableRef}
167
- {...(isTreeTable && { role: 'treegrid' })}
168
- {...ouiaProps}
169
- {...props}
170
- >
171
- {children}
172
- </table>
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
- <tr
62
- className={css(
63
- className,
64
- isExpanded !== undefined && styles.tableExpandableRow,
65
- isExpanded && styles.modifiers.expanded,
66
- isEditable && inlineStyles.modifiers.inlineEditable,
67
- isHoverable && styles.modifiers.hoverable,
68
- isRowSelected && styles.modifiers.selected,
69
- isStriped && styles.modifiers.striped,
70
- resetOffset && styles.modifiers.firstCellOffsetReset
71
- )}
72
- hidden={isHidden || (isExpanded !== undefined && !isExpanded)}
73
- {...(isHoverable && { tabIndex: 0 })}
74
- ref={innerRef}
75
- {...(onRowClick && { onClick: onRowClick, onKeyDown })}
76
- {...ouiaProps}
77
- {...props}
78
- >
79
- {children}
80
- </tr>
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
  >
@@ -2978,6 +2978,11 @@ class PageLayoutDefaultNav extends React.Component {
2978
2978
  }
2979
2979
  ```
2980
2980
 
2981
+ ### Sticky first column
2982
+
2983
+ ```js isFullscreen file="table-demos/StickyFirstColumn.jsx"
2984
+ ```
2985
+
2981
2986
  ## Empty states
2982
2987
 
2983
2988
  These examples demonstrate the use of an [Empty State component](/components/empty-state) inside of a [Table](/components/table). Empty states are useful in a table when a filter returns no results, while data is loading, or when any type of error or exception condition occurs.
@@ -0,0 +1,210 @@
1
+ import React from 'react';
2
+ import { TableComposable, Thead, Tr, Th, Tbody, Td, InnerScrollContainer } from '@patternfly/react-table';
3
+ import { Card, PageSection } from '@patternfly/react-core';
4
+ import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
5
+
6
+ export const StickyFirstColumn = () => {
7
+ const facts = Array.from(
8
+ {
9
+ length: 9
10
+ },
11
+ (_, index) => ({
12
+ name: `Fact ${index + 1}`,
13
+ state: `State ${index + 1}`,
14
+ detail1: `Test cell ${index + 1}-3`,
15
+ detail2: `Test cell ${index + 1}-4`,
16
+ detail3: `Test cell ${index + 1}-5`,
17
+ detail4: `Test cell ${index + 1}-6`,
18
+ detail5: `Test cell ${index + 1}-7`,
19
+ detail6: `Test cell ${index + 1}-8`,
20
+ detail7: `Test cell ${index + 1}-9`,
21
+ detail8: `Test cell ${index + 1}-10`,
22
+ detail9: `Test cell ${index + 1}-11`,
23
+ detail10: `Test cell ${index + 1}-12`,
24
+ detail11: `Test cell ${index + 1}-13`,
25
+ detail12: `Test cell ${index + 1}-14`,
26
+ detail13: `Test cell ${index + 1}-15`,
27
+ detail14: `Test cell ${index + 1}-16`
28
+ })
29
+ );
30
+ const columnNames = {
31
+ name: 'Fact',
32
+ state: 'State',
33
+ header3: 'Header 3',
34
+ header4: 'Header 4',
35
+ header5: 'Header 5',
36
+ header6: 'Header 6',
37
+ header7: 'Header 7',
38
+ header8: 'Header 8',
39
+ header9: 'Header 9',
40
+ header10: 'Header 10',
41
+ header11: 'Header 11',
42
+ header12: 'Header 12',
43
+ header13: 'Header 13',
44
+ header14: 'Header 14',
45
+ header15: 'Header 15',
46
+ header16: 'Header 16'
47
+ };
48
+ const [activeSortIndex, setActiveSortIndex] = React.useState(null);
49
+ const [activeSortDirection, setActiveSortDirection] = React.useState(null);
50
+ const getSortableRowValues = fact => {
51
+ const {
52
+ name,
53
+ state,
54
+ detail1,
55
+ detail2,
56
+ detail3,
57
+ detail4,
58
+ detail5,
59
+ detail6,
60
+ detail7,
61
+ detail8,
62
+ detail9,
63
+ detail10,
64
+ detail11,
65
+ detail12,
66
+ detail13,
67
+ detail14
68
+ } = fact;
69
+ return [
70
+ name,
71
+ state,
72
+ detail1,
73
+ detail2,
74
+ detail3,
75
+ detail4,
76
+ detail5,
77
+ detail6,
78
+ detail7,
79
+ detail8,
80
+ detail9,
81
+ detail10,
82
+ detail11,
83
+ detail12,
84
+ detail13,
85
+ detail14
86
+ ];
87
+ };
88
+ let sortedFacts = facts;
89
+ if (activeSortIndex !== null) {
90
+ sortedFacts = facts.sort((a, b) => {
91
+ const aValue = getSortableRowValues(a)[activeSortIndex];
92
+ const bValue = getSortableRowValues(b)[activeSortIndex];
93
+ if (aValue === bValue) {
94
+ return 0;
95
+ }
96
+ if (activeSortDirection === 'asc') {
97
+ return aValue > bValue ? 1 : -1;
98
+ } else {
99
+ return bValue > aValue ? 1 : -1;
100
+ }
101
+ });
102
+ }
103
+ const getSortParams = columnIndex => ({
104
+ sortBy: {
105
+ index: activeSortIndex,
106
+ direction: activeSortDirection
107
+ },
108
+ onSort: (_event, index, direction) => {
109
+ setActiveSortIndex(index);
110
+ setActiveSortDirection(direction);
111
+ },
112
+ columnIndex
113
+ });
114
+ return (
115
+ <DashboardWrapper hasPageTemplateTitle>
116
+ <PageSection isWidthLimited padding={{ default: 'noPadding', xl: 'padding' }}>
117
+ <Card component="div">
118
+ <InnerScrollContainer>
119
+ <TableComposable aria-label="Sticky column table" gridBreakPoint="">
120
+ <Thead>
121
+ <Tr>
122
+ <Th
123
+ isStickyColumn
124
+ stickyMinWidth="100px"
125
+ hasRightBorder
126
+ modifier="fitContent"
127
+ sort={getSortParams(0)}
128
+ >
129
+ {columnNames.name}
130
+ </Th>
131
+ <Th modifier="fitContent" sort={getSortParams(1)}>
132
+ {columnNames.state}
133
+ </Th>
134
+ <Th>{columnNames.header3}</Th>
135
+ <Th>{columnNames.header4}</Th>
136
+ <Th>{columnNames.header5}</Th>
137
+ <Th>{columnNames.header6}</Th>
138
+ <Th>{columnNames.header7}</Th>
139
+ <Th>{columnNames.header8}</Th>
140
+ <Th>{columnNames.header9}</Th>
141
+ <Th>{columnNames.header10}</Th>
142
+ <Th>{columnNames.header11}</Th>
143
+ <Th>{columnNames.header12}</Th>
144
+ <Th>{columnNames.header13}</Th>
145
+ <Th>{columnNames.header14}</Th>
146
+ <Th>{columnNames.header15}</Th>
147
+ <Th>{columnNames.header16}</Th>
148
+ </Tr>
149
+ </Thead>
150
+ <Tbody>
151
+ {sortedFacts.map(fact => (
152
+ <Tr key={fact.name}>
153
+ <Th isStickyColumn stickyMinWidth="100px" hasRightBorder modifier="truncate">
154
+ {fact.name}
155
+ </Th>
156
+ <Td modifier="nowrap" dataLabel={columnNames.state}>
157
+ {fact.state}
158
+ </Td>
159
+ <Td modifier="nowrap" dataLabel={columnNames.header3}>
160
+ {fact.detail1}
161
+ </Td>
162
+ <Td modifier="nowrap" dataLabel={columnNames.header4}>
163
+ {fact.detail2}
164
+ </Td>
165
+ <Td modifier="nowrap" dataLabel={columnNames.header5}>
166
+ {fact.detail3}
167
+ </Td>
168
+ <Td modifier="nowrap" dataLabel={columnNames.header6}>
169
+ {fact.detail4}
170
+ </Td>
171
+ <Td modifier="nowrap" dataLabel={columnNames.header7}>
172
+ {fact.detail5}
173
+ </Td>
174
+ <Td modifier="nowrap" dataLabel={columnNames.header8}>
175
+ {fact.detail6}
176
+ </Td>
177
+ <Td modifier="nowrap" dataLabel={columnNames.header9}>
178
+ {fact.detail7}
179
+ </Td>
180
+ <Td modifier="nowrap" dataLabel={columnNames.header10}>
181
+ {fact.detail8}
182
+ </Td>
183
+ <Td modifier="nowrap" dataLabel={columnNames.header11}>
184
+ {fact.detail9}
185
+ </Td>
186
+ <Td modifier="nowrap" dataLabel={columnNames.header12}>
187
+ {fact.detail10}
188
+ </Td>
189
+ <Td modifier="nowrap" dataLabel={columnNames.header13}>
190
+ {fact.detail11}
191
+ </Td>
192
+ <Td modifier="nowrap" dataLabel={columnNames.header14}>
193
+ {fact.detail12}
194
+ </Td>
195
+ <Td modifier="nowrap" dataLabel={columnNames.header15}>
196
+ {fact.detail13}
197
+ </Td>
198
+ <Td modifier="nowrap" dataLabel={columnNames.header16}>
199
+ {fact.detail14}
200
+ </Td>
201
+ </Tr>
202
+ ))}
203
+ </Tbody>
204
+ </TableComposable>
205
+ </InnerScrollContainer>
206
+ </Card>
207
+ </PageSection>
208
+ </DashboardWrapper>
209
+ );
210
+ };