@patternfly/react-table 5.0.0-alpha.93 → 5.0.0-alpha.95

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 (51) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/components/package.json +1 -1
  3. package/deprecated/package.json +1 -1
  4. package/dist/esm/components/Table/SortColumn.d.ts.map +1 -1
  5. package/dist/esm/components/Table/SortColumn.js +3 -2
  6. package/dist/esm/components/Table/SortColumn.js.map +1 -1
  7. package/dist/esm/components/Table/TableText.d.ts +2 -0
  8. package/dist/esm/components/Table/TableText.d.ts.map +1 -1
  9. package/dist/esm/components/Table/TableText.js +17 -1
  10. package/dist/esm/components/Table/TableText.js.map +1 -1
  11. package/dist/esm/components/Table/Td.d.ts.map +1 -1
  12. package/dist/esm/components/Table/Td.js +9 -2
  13. package/dist/esm/components/Table/Td.js.map +1 -1
  14. package/dist/esm/components/Table/Th.d.ts.map +1 -1
  15. package/dist/esm/components/Table/Th.js +9 -2
  16. package/dist/esm/components/Table/Th.js.map +1 -1
  17. package/dist/js/components/Table/SortColumn.d.ts.map +1 -1
  18. package/dist/js/components/Table/SortColumn.js +3 -2
  19. package/dist/js/components/Table/SortColumn.js.map +1 -1
  20. package/dist/js/components/Table/TableText.d.ts +2 -0
  21. package/dist/js/components/Table/TableText.d.ts.map +1 -1
  22. package/dist/js/components/Table/TableText.js +17 -1
  23. package/dist/js/components/Table/TableText.js.map +1 -1
  24. package/dist/js/components/Table/Td.d.ts.map +1 -1
  25. package/dist/js/components/Table/Td.js +9 -2
  26. package/dist/js/components/Table/Td.js.map +1 -1
  27. package/dist/js/components/Table/Th.d.ts.map +1 -1
  28. package/dist/js/components/Table/Th.js +9 -2
  29. package/dist/js/components/Table/Th.js.map +1 -1
  30. package/dist/js/components/Table/package.json +1 -1
  31. package/dist/js/components/Table/utils/decorators/package.json +1 -1
  32. package/dist/js/components/Table/utils/package.json +1 -1
  33. package/dist/js/components/package.json +1 -1
  34. package/dist/js/deprecated/components/Table/base/package.json +1 -1
  35. package/dist/js/deprecated/components/Table/package.json +1 -1
  36. package/dist/js/deprecated/components/package.json +1 -1
  37. package/dist/js/deprecated/package.json +1 -1
  38. package/dist/js/package.json +1 -1
  39. package/dist/umd/react-table.min.js +1 -1
  40. package/package.json +3 -3
  41. package/src/components/Table/SortColumn.tsx +5 -2
  42. package/src/components/Table/TableText.tsx +21 -2
  43. package/src/components/Table/Td.tsx +19 -3
  44. package/src/components/Table/Th.tsx +18 -2
  45. package/src/components/Table/examples/Table.md +2 -0
  46. package/src/components/Table/examples/TableActions.tsx +1 -1
  47. package/src/components/Table/examples/TableBasic.tsx +1 -1
  48. package/src/components/Table/examples/TableTextModifiers.tsx +33 -22
  49. package/src/deprecated/components/Table/__tests__/__snapshots__/Table.test.tsx.snap +1145 -0
  50. package/src/deprecated/components/Table/examples/LegacyTableActions.tsx +1 -1
  51. package/src/deprecated/components/Table/examples/LegacyTableBasic.tsx +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-table",
3
- "version": "5.0.0-alpha.93",
3
+ "version": "5.0.0-alpha.95",
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,7 +40,7 @@
40
40
  "subpaths": "node scripts/createSubpaths.js"
41
41
  },
42
42
  "dependencies": {
43
- "@patternfly/react-core": "^5.0.0-alpha.91",
43
+ "@patternfly/react-core": "^5.0.0-alpha.93",
44
44
  "@patternfly/react-icons": "^5.0.0-alpha.14",
45
45
  "@patternfly/react-styles": "^5.0.0-alpha.10",
46
46
  "@patternfly/react-tokens": "^5.0.0-alpha.9",
@@ -55,5 +55,5 @@
55
55
  "react": "^17 || ^18",
56
56
  "react-dom": "^17 || ^18"
57
57
  },
58
- "gitHead": "f66b668ef3fc16098974e1ac80c94e98b02a03d2"
58
+ "gitHead": "b0075afbde3a8f5bb474179578d432291dc3109e"
59
59
  }
@@ -29,6 +29,7 @@ export const SortColumn: React.FunctionComponent<SortColumnProps> = ({
29
29
  ...props
30
30
  }: SortColumnProps) => {
31
31
  let SortedByIcon;
32
+ const [focused, setFocused] = React.useState(false);
32
33
  if (isSortedBy) {
33
34
  SortedByIcon = sortDirection === SortByDirection.asc ? LongArrowAltUpIcon : LongArrowAltDownIcon;
34
35
  } else {
@@ -39,10 +40,12 @@ export const SortColumn: React.FunctionComponent<SortColumnProps> = ({
39
40
  {...props}
40
41
  type={type}
41
42
  className={css(className, styles.tableButton)}
42
- onClick={event => onSort && onSort(event)}
43
+ onClick={(event) => onSort && onSort(event)}
44
+ onFocus={() => setFocused(true)}
45
+ onBlur={() => setFocused(false)}
43
46
  >
44
47
  <div className={css(className, styles.tableButtonContent)}>
45
- <TableText>{children}</TableText>
48
+ <TableText focused={focused}>{children}</TableText>
46
49
  <span className={css(styles.tableSortIndicator)}>
47
50
  <SortedByIcon />
48
51
  </span>
@@ -31,6 +31,8 @@ export interface TableTextProps extends React.HTMLProps<HTMLDivElement> {
31
31
  tooltipProps?: Omit<TooltipProps, 'content'>;
32
32
  /** callback used to create the tooltip if text is truncated */
33
33
  onMouseEnter?: (event: any) => void;
34
+ /** Determines if the TableText is focused by parent component */
35
+ focused?: boolean;
34
36
  }
35
37
 
36
38
  export const TableText: React.FunctionComponent<TableTextProps> = ({
@@ -41,10 +43,11 @@ export const TableText: React.FunctionComponent<TableTextProps> = ({
41
43
  tooltip: tooltipProp = '',
42
44
  tooltipProps = {},
43
45
  onMouseEnter: onMouseEnterProp = () => {},
46
+ focused = false,
44
47
  ...props
45
48
  }: TableTextProps) => {
46
49
  const Component: TableTextVariant | 'span' | 'div' = variant;
47
- const textRef = React.createRef<any>();
50
+ const textRef = React.createRef<HTMLElement>();
48
51
 
49
52
  const [tooltip, setTooltip] = React.useState('');
50
53
  const onMouseEnter = (event: any) => {
@@ -56,9 +59,17 @@ export const TableText: React.FunctionComponent<TableTextProps> = ({
56
59
  onMouseEnterProp(event);
57
60
  };
58
61
 
62
+ const onFocus = (element: HTMLElement) => {
63
+ if (element.offsetWidth < element.scrollWidth) {
64
+ setTooltip(tooltipProp || element.innerText);
65
+ } else {
66
+ setTooltip('');
67
+ }
68
+ };
69
+
59
70
  const text = (
60
71
  <Component
61
- ref={textRef}
72
+ ref={textRef as React.Ref<HTMLDivElement>}
62
73
  onMouseEnter={onMouseEnter}
63
74
  className={css(className, wrapModifier && styles.modifiers[wrapModifier], styles.tableText)}
64
75
  {...props}
@@ -67,6 +78,14 @@ export const TableText: React.FunctionComponent<TableTextProps> = ({
67
78
  </Component>
68
79
  );
69
80
 
81
+ React.useEffect(() => {
82
+ if (focused) {
83
+ onFocus(textRef.current);
84
+ } else {
85
+ setTooltip('');
86
+ }
87
+ }, [focused]);
88
+
70
89
  return tooltip !== '' ? (
71
90
  <Tooltip triggerRef={textRef} content={tooltip} isVisible {...tooltipProps}>
72
91
  {text}
@@ -105,14 +105,15 @@ const TdBase: React.FunctionComponent<TdProps> = ({
105
105
  ...props
106
106
  }: TdProps) => {
107
107
  const [showTooltip, setShowTooltip] = React.useState(false);
108
+ const [truncated, setTruncated] = React.useState(false);
108
109
  const cellRef = innerRef ? innerRef : React.createRef();
109
-
110
110
  const onMouseEnter = (event: any) => {
111
111
  if (event.target.offsetWidth < event.target.scrollWidth) {
112
112
  !showTooltip && setShowTooltip(true);
113
113
  } else {
114
114
  showTooltip && setShowTooltip(false);
115
115
  }
116
+
116
117
  onMouseEnterProp(event);
117
118
  };
118
119
 
@@ -255,9 +256,19 @@ const TdBase: React.FunctionComponent<TdProps> = ({
255
256
  (className && className.includes('pf-v5-c-table__tree-view-title-cell')) ||
256
257
  (mergedClassName && mergedClassName.includes('pf-v5-c-table__tree-view-title-cell'));
257
258
 
259
+ React.useEffect(() => {
260
+ setTruncated(
261
+ (cellRef as React.RefObject<HTMLElement>).current.offsetWidth <
262
+ (cellRef as React.RefObject<HTMLElement>).current.scrollWidth
263
+ );
264
+ }, [cellRef]);
265
+
258
266
  const cell = (
259
267
  <MergedComponent
268
+ tabIndex={(select || !truncated) && modifier !== 'truncate' ? -1 : 0}
260
269
  {...(!treeTableTitleCell && { 'data-label': dataLabel })}
270
+ onFocus={tooltip !== null ? onMouseEnter : onMouseEnterProp}
271
+ onBlur={() => setShowTooltip(false)}
261
272
  onMouseEnter={tooltip !== null ? onMouseEnter : onMouseEnterProp}
262
273
  className={css(
263
274
  className,
@@ -289,9 +300,14 @@ const TdBase: React.FunctionComponent<TdProps> = ({
289
300
 
290
301
  const canMakeDefaultTooltip = tooltip === '' ? typeof children === 'string' : true;
291
302
  return tooltip !== null && canMakeDefaultTooltip && showTooltip ? (
292
- <Tooltip triggerRef={cellRef as React.RefObject<any>} content={tooltip || (tooltip === '' && children)} isVisible>
303
+ <>
293
304
  {cell}
294
- </Tooltip>
305
+ <Tooltip
306
+ triggerRef={cellRef as React.RefObject<any>}
307
+ content={tooltip || (tooltip === '' && children)}
308
+ isVisible
309
+ />
310
+ </>
295
311
  ) : (
296
312
  cell
297
313
  );
@@ -80,6 +80,7 @@ const ThBase: React.FunctionComponent<ThProps> = ({
80
80
  ...props
81
81
  }: ThProps) => {
82
82
  const [showTooltip, setShowTooltip] = React.useState(false);
83
+ const [truncated, setTruncated] = React.useState(false);
83
84
  const cellRef = innerRef ? innerRef : React.createRef();
84
85
  const onMouseEnter = (event: any) => {
85
86
  if (event.target.offsetWidth < event.target.scrollWidth) {
@@ -161,8 +162,18 @@ const ThBase: React.FunctionComponent<ThProps> = ({
161
162
  ...mergedProps
162
163
  } = merged;
163
164
 
165
+ React.useEffect(() => {
166
+ setTruncated(
167
+ (cellRef as React.RefObject<HTMLElement>).current.offsetWidth <
168
+ (cellRef as React.RefObject<HTMLElement>).current.scrollWidth
169
+ );
170
+ }, [cellRef]);
171
+
164
172
  const cell = (
165
173
  <MergedComponent
174
+ tabIndex={sort || select || !truncated ? -1 : 0}
175
+ onFocus={tooltip !== null ? onMouseEnter : onMouseEnterProp}
176
+ onBlur={() => setShowTooltip(false)}
166
177
  data-label={dataLabel}
167
178
  onMouseEnter={tooltip !== null ? onMouseEnter : onMouseEnterProp}
168
179
  scope={component === 'th' && children ? scope : null}
@@ -194,9 +205,14 @@ const ThBase: React.FunctionComponent<ThProps> = ({
194
205
 
195
206
  const canMakeDefaultTooltip = tooltip === '' ? typeof transformedChildren === 'string' : true;
196
207
  return tooltip !== null && canMakeDefaultTooltip && showTooltip ? (
197
- <Tooltip triggerRef={cellRef as React.RefObject<any>} content={tooltip || (tooltip === '' && children)} isVisible>
208
+ <>
198
209
  {cell}
199
- </Tooltip>
210
+ <Tooltip
211
+ triggerRef={cellRef as React.RefObject<any>}
212
+ content={tooltip || (tooltip === '' && children)}
213
+ isVisible
214
+ />
215
+ </>
200
216
  ) : (
201
217
  cell
202
218
  );
@@ -233,6 +233,8 @@ export type OnExpand = (
233
233
 
234
234
  ### Modifiers with table text
235
235
 
236
+ If the "wrapModifier" property is set to "truncate", it's needed to ensure that the corresponding tooltip can be opened using both keyboard and screen reader. Since this particular Td element is generic and doesn't have any predefined decorators, the focus management required to trigger the tooltip needs to be handled manually by defining and manipulating the requisite props.
237
+
236
238
  ```ts file="TableTextModifiers.tsx"
237
239
  ```
238
240
 
@@ -46,7 +46,7 @@ export const TableActions: React.FunctionComponent = () => {
46
46
 
47
47
  // This state is just for the ToggleGroup in this example and isn't necessary for Table usage.
48
48
  const [exampleChoice, setExampleChoice] = React.useState<ExampleType>('defaultToggle');
49
- const onExampleTypeChange: ToggleGroupItemProps['onChange'] = (_isSelected, event) => {
49
+ const onExampleTypeChange: ToggleGroupItemProps['onChange'] = (event, _isSelected) => {
50
50
  const id = event.currentTarget.id;
51
51
  setExampleChoice(id as ExampleType);
52
52
  };
@@ -30,7 +30,7 @@ export const TableBasic: React.FunctionComponent = () => {
30
30
 
31
31
  // This state is just for the ToggleGroup in this example and isn't necessary for Table usage.
32
32
  const [exampleChoice, setExampleChoice] = React.useState<ExampleType>('default');
33
- const onExampleTypeChange: ToggleGroupItemProps['onChange'] = (_isSelected, event) => {
33
+ const onExampleTypeChange: ToggleGroupItemProps['onChange'] = (event, _isSelected) => {
34
34
  const id = event.currentTarget.id;
35
35
  setExampleChoice(id as ExampleType);
36
36
  };
@@ -9,25 +9,36 @@ const columnNames = {
9
9
  wrap: 'Wrapping table header text. This th text will wrap instead of truncate.'
10
10
  };
11
11
 
12
- export const TableTextModifiers: React.FunctionComponent = () => (
13
- <Table aria-label="Table text">
14
- <Thead>
15
- <Tr>
16
- <Th width={30}>{columnNames.truncate}</Th>
17
- <Th>{columnNames.wrap}</Th>
18
- </Tr>
19
- </Thead>
20
- <Tbody>
21
- <Tr>
22
- <Td dataLabel={columnNames.truncate}>
23
- <TableText wrapModifier="truncate">This text will truncate instead of wrap.</TableText>
24
- </Td>
25
- <Td dataLabel={columnNames.wrap}>
26
- <TableText wrapModifier="nowrap">
27
- <a href="#">This is a link that needs to be on one line and fully readable.</a>
28
- </TableText>
29
- </Td>
30
- </Tr>
31
- </Tbody>
32
- </Table>
33
- );
12
+ export const TableTextModifiers: React.FunctionComponent = () => {
13
+ const [focused, setFocused] = React.useState(false);
14
+
15
+ return (
16
+ <Table aria-label="Table text">
17
+ <Thead>
18
+ <Tr>
19
+ <Th width={30}>{columnNames.truncate}</Th>
20
+ <Th>{columnNames.wrap}</Th>
21
+ </Tr>
22
+ </Thead>
23
+ <Tbody>
24
+ <Tr>
25
+ <Td
26
+ onFocus={() => setFocused(true)}
27
+ onBlur={() => setFocused(false)}
28
+ tabIndex={0}
29
+ dataLabel={columnNames.truncate}
30
+ >
31
+ <TableText focused={focused} wrapModifier="truncate">
32
+ This text will truncate instead of wrap.
33
+ </TableText>
34
+ </Td>
35
+ <Td dataLabel={columnNames.wrap}>
36
+ <TableText wrapModifier="nowrap">
37
+ <a href="#">This is a link that needs to be on one line and fully readable.</a>
38
+ </TableText>
39
+ </Td>
40
+ </Tr>
41
+ </Tbody>
42
+ </Table>
43
+ );
44
+ };