@patternfly/react-table 4.55.1 → 4.57.0

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": "4.55.1",
3
+ "version": "4.57.0",
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.186.1",
35
- "@patternfly/react-icons": "^4.37.1",
36
- "@patternfly/react-styles": "^4.36.1",
37
- "@patternfly/react-tokens": "^4.38.1",
34
+ "@patternfly/react-core": "^4.188.0",
35
+ "@patternfly/react-icons": "^4.39.0",
36
+ "@patternfly/react-styles": "^4.38.0",
37
+ "@patternfly/react-tokens": "^4.40.0",
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": "004cdf8648be921f15c9dafa489964f4bc4fa8d5"
49
+ "gitHead": "50f8380568e964aee4be81e64f11454993a3772d"
50
50
  }
@@ -10,7 +10,14 @@ import {
10
10
  DropdownPosition
11
11
  } from '@patternfly/react-core/dist/esm/components/Dropdown/dropdownConstants';
12
12
 
13
- import { IAction, IExtraData, IRowData } from './TableTypes';
13
+ import {
14
+ IAction,
15
+ IActionDropdownItem,
16
+ IActionOutsideItemButton,
17
+ IActionOutsideItemCustom,
18
+ IExtraData,
19
+ IRowData
20
+ } from './TableTypes';
14
21
 
15
22
  export interface CustomActionsToggleProps {
16
23
  onToggle: (isOpen: boolean) => void;
@@ -82,10 +89,16 @@ export class ActionsColumn extends React.Component<ActionsColumnProps, ActionsCo
82
89
  <KebabToggle isDisabled={isDisabled} onToggle={this.onToggle} />
83
90
  );
84
91
 
92
+ const outsideDropdownItems = items.filter(a => a.isOutsideDropdown) as (
93
+ | IActionOutsideItemButton
94
+ | IActionOutsideItemCustom
95
+ )[];
96
+
97
+ const dropdownItems = items.filter(a => !a.isOutsideDropdown) as IActionDropdownItem[];
98
+
85
99
  return (
86
100
  <React.Fragment>
87
- {items
88
- .filter(item => item.isOutsideDropdown)
101
+ {outsideDropdownItems
89
102
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
90
103
  .map(({ title, itemKey, onClick, isOutsideDropdown, ...props }, key) =>
91
104
  typeof title === 'string' ? (
@@ -107,26 +120,24 @@ export class ActionsColumn extends React.Component<ActionsColumnProps, ActionsCo
107
120
  position={dropdownPosition}
108
121
  direction={dropdownDirection}
109
122
  isOpen={isOpen}
110
- dropdownItems={items
111
- .filter(item => !item.isOutsideDropdown)
112
- .map(({ title, itemKey, onClick, isSeparator, ...props }, key) =>
113
- isSeparator ? (
114
- <DropdownSeparator {...props} key={itemKey || key} data-key={itemKey || key} />
115
- ) : (
116
- <DropdownItem
117
- component="button"
118
- onClick={event => {
119
- this.onClick(event, onClick);
120
- this.onToggle(!isOpen);
121
- }}
122
- {...props}
123
- key={itemKey || key}
124
- data-key={itemKey || key}
125
- >
126
- {title}
127
- </DropdownItem>
128
- )
129
- )}
123
+ dropdownItems={dropdownItems.map(({ title, itemKey, onClick, isSeparator, ...props }, key) =>
124
+ isSeparator ? (
125
+ <DropdownSeparator {...props} key={itemKey || key} data-key={itemKey || key} />
126
+ ) : (
127
+ <DropdownItem
128
+ component="button"
129
+ onClick={event => {
130
+ this.onClick(event, onClick);
131
+ this.onToggle(!isOpen);
132
+ }}
133
+ {...props}
134
+ key={itemKey || key}
135
+ data-key={itemKey || key}
136
+ >
137
+ {title}
138
+ </DropdownItem>
139
+ )
140
+ )}
130
141
  isPlain
131
142
  {...(rowData && rowData.actionProps)}
132
143
  />
@@ -57,21 +57,27 @@ class ContextBody extends React.Component<TableBodyProps, {}> {
57
57
  row,
58
58
  rowProps: extendedRowProps,
59
59
  onClick: (event: React.MouseEvent) => {
60
+ const tagName = (event.target as HTMLElement).tagName;
60
61
  const computedData = {
61
- isInput: (event.target as HTMLElement).tagName === 'INPUT',
62
- isButton: (event.target as HTMLElement).tagName === 'BUTTON'
62
+ isInput: tagName === 'INPUT',
63
+ isButton: tagName === 'BUTTON'
63
64
  };
64
65
 
65
66
  onRowClick(event, row, rowProps, computedData);
66
67
  },
67
68
  onKeyDown: (event: React.KeyboardEvent) => {
69
+ const targetElement = event.target as HTMLElement;
70
+ const tagName = targetElement.tagName;
71
+ const computedData = {
72
+ isInput: tagName === 'INPUT',
73
+ isButton: tagName === 'BUTTON'
74
+ };
68
75
  if (event.key === 'Enter' || event.key === ' ') {
69
- const computedData = {
70
- isInput: (event.target as HTMLElement).tagName === 'INPUT',
71
- isButton: (event.target as HTMLElement).tagName === 'BUTTON'
72
- };
73
76
  onRowClick(event, row, rowProps, computedData);
74
- if (!computedData.isInput) {
77
+
78
+ // prevent event default if space is typed while focusing on a hoverable row
79
+ // so that the page does not scroll when trying to use spacebar to select a row
80
+ if (event.key === ' ' && !!targetElement.closest('.pf-m-hoverable')) {
75
81
  event.preventDefault();
76
82
  }
77
83
  }
@@ -146,22 +146,54 @@ export interface ISortBy {
146
146
  defaultDirection?: 'asc' | 'desc';
147
147
  }
148
148
 
149
- export interface IAction extends Omit<DropdownItemProps, 'title' | 'onClick'>, Pick<ButtonProps, 'variant'> {
149
+ export interface ISeparator {
150
150
  /** Flag indicating an item on actions menu is a separator, rather than an action */
151
- isSeparator?: boolean;
152
- /** Key of actions menu item */
153
- itemKey?: string;
154
- /** Content to display in the actions menu item */
155
- title?: string | React.ReactNode;
151
+ isSeparator: true;
152
+ }
153
+
154
+ export interface IActionSeparator extends ISeparator {
155
+ isOutsideDropdown?: false;
156
+ }
157
+
158
+ interface IActionClickable {
156
159
  /** Click handler for the actions menu item */
157
160
  onClick?: (event: React.MouseEvent, rowIndex: number, rowData: IRowData, extraData: IExtraData) => void;
158
- /** Flag indicating this action should be placed outside the actions menu, beside the toggle */
159
- isOutsideDropdown?: boolean;
160
161
  }
161
162
 
162
- export interface ISeparator extends IAction {
163
- isSeparator: boolean;
164
- }
163
+ export type IActionOutsideItemBase = IActionClickable & {
164
+ /** Flag indicating this action should be placed outside the actions menu, beside the toggle */
165
+ isOutsideDropdown: true;
166
+ /** Flag indicating an item on actions menu is not a separator, added to make it easy to distinguish */
167
+ isSeparator?: false;
168
+ /** Key of actions menu item */
169
+ itemKey?: undefined;
170
+ };
171
+
172
+ export type IActionOutsideItemButton = IActionOutsideItemBase &
173
+ Omit<ButtonProps, 'onClick'> & {
174
+ title: string;
175
+ /** Key of actions menu item */
176
+ itemKey?: string;
177
+ };
178
+
179
+ export type IActionOutsideItemCustom = IActionOutsideItemBase & {
180
+ title: Exclude<React.ReactNode, string>;
181
+ [key: string]: any;
182
+ };
183
+
184
+ export type IActionDropdownItem = Omit<DropdownItemProps, 'title' | 'onClick'> &
185
+ IActionClickable & {
186
+ /** Flag indicating an item on actions menu is not a separator, added to make it easy to distinguish */
187
+ isSeparator?: false;
188
+ /** Flag indicating this action should be placed outside the actions menu, beside the toggle */
189
+ isOutsideDropdown?: false;
190
+ /** Key of actions menu item */
191
+ itemKey?: string;
192
+ /** Content to display in the actions menu item */
193
+ title: React.ReactNode;
194
+ };
195
+
196
+ export type IAction = IActionSeparator | IActionDropdownItem | IActionOutsideItemButton | IActionOutsideItemCustom;
165
197
 
166
198
  export type IActions = (IAction | ISeparator)[];
167
199
  export type IActionsResolver = (rowData: IRowData, extraData: IExtraData) => (IAction | ISeparator)[];
@@ -163,6 +163,9 @@ This example demonstrates adding actions as the last column. The header's last c
163
163
 
164
164
  To make a cell an action cell, render an `ActionsColumn` component inside a row's last `Td` and pass an array of `IAction` objects via the `items` prop of `ActionsColumn`.
165
165
 
166
+ Look [here](https://github.com/patternfly/patternfly-react/blob/main/packages/react-table/src/components/Table/TableTypes.tsx)
167
+ for the `IAction` type to see what it looks like.
168
+
166
169
  ```ts file="ComposableTableActions.tsx"
167
170
  ```
168
171