@patternfly/react-table 6.3.0-prerelease.33 → 6.3.0-prerelease.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-table",
3
- "version": "6.3.0-prerelease.33",
3
+ "version": "6.3.0-prerelease.34",
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",
@@ -51,5 +51,5 @@
51
51
  "react": "^17 || ^18 || ^19",
52
52
  "react-dom": "^17 || ^18 || ^19"
53
53
  },
54
- "gitHead": "7f92acb9f3d7265531d5886058cd80922127fdc5"
54
+ "gitHead": "ca7bb75f595cf3edac08aad8c0706b257fbe293d"
55
55
  }
@@ -45,6 +45,8 @@ export interface TdProps extends BaseCellProps, Omit<React.HTMLProps<HTMLTableDa
45
45
  select?: TdSelectType;
46
46
  /** Turns the cell into an actions cell. Recommended to use an ActionsColumn component as a child of the Td rather than this prop. */
47
47
  actions?: TdActionsType;
48
+ /** Indicates the cell contains an interactive element and prevents that element's padding from increasing row height. Recommended when other cells in the same row contains text. */
49
+ hasAction?: boolean;
48
50
  /** Turns the cell into an expansion toggle and determines if the corresponding expansion row is open */
49
51
  expand?: TdExpandType;
50
52
  /** Turns the cell into a compound expansion toggle */
@@ -86,6 +88,7 @@ const TdBase: React.FunctionComponent<TdProps> = ({
86
88
  children,
87
89
  className,
88
90
  isActionCell = false,
91
+ hasAction = false,
89
92
  component = 'td',
90
93
  dataLabel,
91
94
  textCenter = false,
@@ -314,6 +317,7 @@ const TdBase: React.FunctionComponent<TdProps> = ({
314
317
  styles.tableTd,
315
318
  className,
316
319
  isActionCell && styles.tableAction,
320
+ hasAction && styles.modifiers.action,
317
321
  textCenter && styles.modifiers.center,
318
322
  noPadding && styles.modifiers.noPadding,
319
323
  isStickyColumn && scrollStyles.tableStickyCell,
@@ -0,0 +1,87 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import styles from '@patternfly/react-styles/css/components/Table/table';
3
+ import { Td } from '../Td';
4
+
5
+ test('Renders without children', () => {
6
+ render(
7
+ <table>
8
+ <tbody>
9
+ <tr>
10
+ <Td />
11
+ </tr>
12
+ </tbody>
13
+ </table>
14
+ );
15
+
16
+ expect(screen.getByRole('cell')).toBeInTheDocument();
17
+ });
18
+
19
+ test('Renders with children', () => {
20
+ render(
21
+ <table>
22
+ <tbody>
23
+ <tr>
24
+ <Td>Cell content</Td>
25
+ </tr>
26
+ </tbody>
27
+ </table>
28
+ );
29
+
30
+ expect(screen.getByRole('cell')).toHaveTextContent('Cell content');
31
+ });
32
+
33
+ test(`Applies ${styles.modifiers.action} when hasAction is true`, () => {
34
+ render(
35
+ <table>
36
+ <tbody>
37
+ <tr>
38
+ <Td hasAction>Cell with action</Td>
39
+ </tr>
40
+ </tbody>
41
+ </table>
42
+ );
43
+
44
+ expect(screen.getByRole('cell')).toHaveClass('pf-m-action');
45
+ });
46
+
47
+ test(`Does not apply ${styles.modifiers.action} when hasAction is false`, () => {
48
+ render(
49
+ <table>
50
+ <tbody>
51
+ <tr>
52
+ <Td hasAction={false}>Cell without action</Td>
53
+ </tr>
54
+ </tbody>
55
+ </table>
56
+ );
57
+
58
+ expect(screen.getByRole('cell')).not.toHaveClass('pf-m-action');
59
+ });
60
+
61
+ test('Matches snapshot without children', () => {
62
+ const { asFragment } = render(
63
+ <table>
64
+ <tbody>
65
+ <tr>
66
+ <Td />
67
+ </tr>
68
+ </tbody>
69
+ </table>
70
+ );
71
+
72
+ expect(asFragment()).toMatchSnapshot();
73
+ });
74
+
75
+ test('Matches snapshot with children', () => {
76
+ const { asFragment } = render(
77
+ <table>
78
+ <tbody>
79
+ <tr>
80
+ <Td>Cell content</Td>
81
+ </tr>
82
+ </tbody>
83
+ </table>
84
+ );
85
+
86
+ expect(asFragment()).toMatchSnapshot();
87
+ });
@@ -0,0 +1,33 @@
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
+ <td
9
+ class="pf-v6-c-table__td"
10
+ tabindex="-1"
11
+ >
12
+ Cell content
13
+ </td>
14
+ </tr>
15
+ </tbody>
16
+ </table>
17
+ </DocumentFragment>
18
+ `;
19
+
20
+ exports[`Matches snapshot without children 1`] = `
21
+ <DocumentFragment>
22
+ <table>
23
+ <tbody>
24
+ <tr>
25
+ <td
26
+ class="pf-v6-c-table__td"
27
+ tabindex="-1"
28
+ />
29
+ </tr>
30
+ </tbody>
31
+ </table>
32
+ </DocumentFragment>
33
+ `;
@@ -184,6 +184,8 @@ To make a cell an action cell, render an `ActionsColumn` component inside a row'
184
184
 
185
185
  If actions menus are getting clipped by other items on the page, such as sticky columns or rows, the `ActionsColumn` can be passed a `menuAppendTo` prop to adjust where the actions menu is appended.
186
186
 
187
+ When a table row contains mixed content of text and interactive elements, the `hasAction` property may be passed to a `Td` which contains interactive content like the below example's start `Button`. This will align buttons and other elements with other cells' text. Note that `hasAction` should not be used with `Td`s in an `ActionsColumn` because that comes with it's own spacing.
188
+
187
189
  ```ts file="TableActions.tsx"
188
190
 
189
191
  ```
@@ -146,7 +146,7 @@ export const TableActions: React.FunctionComponent = () => {
146
146
  <Td dataLabel={columnNames.prs}>{repo.prs}</Td>
147
147
  <Td dataLabel={columnNames.workspaces}>{repo.workspaces}</Td>
148
148
  <Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td>
149
- <Td dataLabel={columnNames.singleAction} modifier="fitContent">
149
+ <Td dataLabel={columnNames.singleAction} modifier="fitContent" hasAction>
150
150
  {singleActionButton}
151
151
  </Td>
152
152
  <Td isActionCell>