@carbon/ibm-products 1.31.0 → 1.32.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.
Files changed (58) hide show
  1. package/css/index-full-carbon.css +57 -5
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +1 -1
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon.css +57 -5
  6. package/css/index-without-carbon.css.map +1 -1
  7. package/css/index-without-carbon.min.css +1 -1
  8. package/css/index-without-carbon.min.css.map +1 -1
  9. package/css/index.css +57 -5
  10. package/css/index.css.map +1 -1
  11. package/css/index.min.css +1 -1
  12. package/css/index.min.css.map +1 -1
  13. package/es/components/DataSpreadsheet/DataSpreadsheet.js +1 -0
  14. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +2 -1
  15. package/es/components/Datagrid/Datagrid/DatagridContent.js +26 -5
  16. package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +9 -1
  17. package/es/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +12 -3
  18. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/InlineEditButton.js +1 -4
  19. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +16 -8
  20. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/returnUpdatedActiveCell.js +9 -1
  21. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.js +153 -87
  22. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleMultipleKeys.js +66 -0
  23. package/es/components/Datagrid/useActionsColumn.js +28 -12
  24. package/es/components/Datagrid/useExpandedRow.js +0 -1
  25. package/es/components/Datagrid/useNestedRowExpander.js +42 -0
  26. package/es/components/Datagrid/useNestedRows.js +2 -2
  27. package/es/components/Datagrid/useSelectAllToggle.js +17 -4
  28. package/es/components/Datagrid/utils/DatagridActions.js +121 -0
  29. package/es/components/Datagrid/utils/DatagridPagination.js +33 -0
  30. package/es/components/Datagrid/utils/Wrapper.js +21 -0
  31. package/es/components/Datagrid/utils/getArgTypes.js +85 -0
  32. package/es/global/js/utils/story-helper.js +5 -1
  33. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +1 -0
  34. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +2 -1
  35. package/lib/components/Datagrid/Datagrid/DatagridContent.js +27 -5
  36. package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +9 -1
  37. package/lib/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +14 -3
  38. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/InlineEditButton.js +1 -4
  39. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +16 -8
  40. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/returnUpdatedActiveCell.js +10 -7
  41. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.js +155 -87
  42. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleMultipleKeys.js +78 -0
  43. package/lib/components/Datagrid/useActionsColumn.js +28 -13
  44. package/lib/components/Datagrid/useExpandedRow.js +0 -1
  45. package/lib/components/Datagrid/useNestedRowExpander.js +57 -0
  46. package/lib/components/Datagrid/useNestedRows.js +3 -3
  47. package/lib/components/Datagrid/useSelectAllToggle.js +18 -4
  48. package/lib/components/Datagrid/utils/DatagridActions.js +139 -0
  49. package/lib/components/Datagrid/utils/DatagridPagination.js +46 -0
  50. package/lib/components/Datagrid/utils/Wrapper.js +33 -0
  51. package/lib/components/Datagrid/utils/getArgTypes.js +93 -0
  52. package/lib/global/js/utils/story-helper.js +5 -1
  53. package/package.json +2 -2
  54. package/scss/components/Datagrid/styles/_datagrid.scss +0 -4
  55. package/scss/components/Datagrid/styles/_useActionsColumn.scss +12 -0
  56. package/scss/components/Datagrid/styles/_useExpandedRow.scss +30 -0
  57. package/scss/components/Datagrid/styles/_useNestedRows.scss +15 -1
  58. package/scss/components/Datagrid/styles/_useStickyColumn.scss +6 -0
@@ -1,4 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
4
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
5
  var _excluded = ["onChange"];
@@ -13,6 +14,7 @@ var _excluded = ["onChange"];
13
14
  // @flow
14
15
  import React, { useEffect, useState } from 'react';
15
16
  import PropTypes from 'prop-types';
17
+ import cx from 'classnames';
16
18
  import { OverflowMenu, OverflowMenuItem, Checkbox } from 'carbon-components-react';
17
19
  import { CaretDown16 } from '@carbon/icons-react';
18
20
  import { pkg } from '../../../settings'; // cspell:words columnheader
@@ -22,6 +24,8 @@ var SELECT_ALL_PAGE_ROWS = 'pageRows';
22
24
  var SELECT_ALL_ROWS = 'allRows';
23
25
 
24
26
  var SelectAllWithToggle = function SelectAllWithToggle(_ref) {
27
+ var _columns$;
28
+
25
29
  var tableId = _ref.tableId,
26
30
  isFetching = _ref.isFetching,
27
31
  isAllRowsSelected = _ref.isAllRowsSelected,
@@ -31,7 +35,9 @@ var SelectAllWithToggle = function SelectAllWithToggle(_ref) {
31
35
  _ref$allPageRowsLabel = _ref.allPageRowsLabel,
32
36
  allPageRowsLabel = _ref$allPageRowsLabel === void 0 ? 'Select all on page' : _ref$allPageRowsLabel,
33
37
  _ref$allRowsLabel = _ref.allRowsLabel,
34
- allRowsLabel = _ref$allRowsLabel === void 0 ? 'Select all' : _ref$allRowsLabel;
38
+ allRowsLabel = _ref$allRowsLabel === void 0 ? 'Select all' : _ref$allRowsLabel,
39
+ columns = _ref.columns,
40
+ withStickyColumn = _ref.withStickyColumn;
35
41
 
36
42
  var _useState = useState(SELECT_ALL_PAGE_ROWS),
37
43
  _useState2 = _slicedToArray(_useState, 2),
@@ -60,10 +66,11 @@ var SelectAllWithToggle = function SelectAllWithToggle(_ref) {
60
66
  selectProps = _objectWithoutProperties(_getProps, _excluded);
61
67
 
62
68
  var disabled = isFetching || selectProps.disabled;
69
+ var isFirstColumnStickyLeft = ((_columns$ = columns[0]) === null || _columns$ === void 0 ? void 0 : _columns$.sticky) === 'left' && withStickyColumn;
63
70
  return /*#__PURE__*/React.createElement("th", {
64
71
  role: "columnheader",
65
72
  scope: "col",
66
- className: "".concat(blockClass, "__select-all-toggle-on")
73
+ className: cx("".concat(blockClass, "__select-all-toggle-on"), _defineProperty({}, "".concat(blockClass, "__select-all-sticky-left"), isFirstColumnStickyLeft))
67
74
  }, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, selectProps, {
68
75
  name: "".concat(tableId, "-select-all-checkbox-name"),
69
76
  onClick: function onClick(e) {
@@ -111,11 +118,13 @@ var SelectAllWithToggle = function SelectAllWithToggle(_ref) {
111
118
  SelectAllWithToggle.propTypes = {
112
119
  allPageRowsLabel: PropTypes.string,
113
120
  allRowsLabel: PropTypes.string,
121
+ columns: PropTypes.arrayOf(PropTypes.object),
114
122
  getToggleAllPageRowsSelectedProps: PropTypes.func.isRequired,
115
123
  getToggleAllRowsSelectedProps: PropTypes.func.isRequired,
116
124
  isAllRowsSelected: PropTypes.bool.isRequired,
117
125
  isFetching: PropTypes.bool,
118
126
  selectAllToggle: PropTypes.object,
119
- tableId: PropTypes.string.isRequired
127
+ tableId: PropTypes.string.isRequired,
128
+ withStickyColumn: PropTypes.bool
120
129
  };
121
130
  export default SelectAllWithToggle;
@@ -20,8 +20,6 @@ export var InlineEditButton = function InlineEditButton(_ref) {
20
20
  disabled = _ref.disabled,
21
21
  LabelIcon = _ref.labelIcon,
22
22
  placeholder = _ref.placeholder,
23
- _ref$tabIndex = _ref.tabIndex,
24
- tabIndex = _ref$tabIndex === void 0 ? -1 : _ref$tabIndex,
25
23
  nonEditCell = _ref.nonEditCell,
26
24
  isActiveCell = _ref.isActiveCell,
27
25
  columnConfig = _ref.columnConfig,
@@ -31,7 +29,7 @@ export var InlineEditButton = function InlineEditButton(_ref) {
31
29
  var inlineEditColsLessThanHalfOfTotal = totalInlineEditColumns < totalColumns / 2;
32
30
  return /*#__PURE__*/React.createElement("div", {
33
31
  className: cx("".concat(blockClass, "__inline-edit-button"), (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__inline-edit-button--disabled"), disabled || nonEditCell), _defineProperty(_cx, "".concat(blockClass, "__inline-edit-button--with-label-icon"), LabelIcon), _defineProperty(_cx, "".concat(blockClass, "__inline-edit-button--non-edit"), nonEditCell), _defineProperty(_cx, "".concat(blockClass, "__inline-edit-button--active"), isActiveCell), _defineProperty(_cx, "".concat(blockClass, "__inline-edit-button--edit-less-than-half-of-total-cols"), inlineEditColsLessThanHalfOfTotal), _defineProperty(_cx, "".concat(blockClass, "__inline-edit-button--").concat(type), type === 'date' || type === 'selection'), _cx)),
34
- tabIndex: tabIndex,
32
+ tabIndex: isActiveCell ? 0 : -1,
35
33
  "data-disabled": disabled || nonEditCell,
36
34
  "aria-disabled": disabled || nonEditCell,
37
35
  role: "button",
@@ -55,7 +53,6 @@ InlineEditButton.propTypes = {
55
53
  nonEditCell: PropTypes.bool,
56
54
  placeholder: PropTypes.string,
57
55
  renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
58
- tabIndex: PropTypes.number,
59
56
  totalColumns: PropTypes.number,
60
57
  totalInlineEditColumns: PropTypes.number,
61
58
  type: PropTypes.oneOf(['text', 'number', 'selection', 'date']),
@@ -33,8 +33,6 @@ export var InlineEditCell = function InlineEditCell(_ref) {
33
33
  placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
34
34
  tabIndex = _ref.tabIndex,
35
35
  value = _ref.value,
36
- _ref$label = _ref.label,
37
- label = _ref$label === void 0 ? 'Inline edit type text label' : _ref$label,
38
36
  nonEditCell = _ref.nonEditCell,
39
37
  totalInlineEditColumns = _ref.totalInlineEditColumns,
40
38
  type = _ref.type;
@@ -64,6 +62,11 @@ export var InlineEditCell = function InlineEditCell(_ref) {
64
62
  initialValue = _useState6[0],
65
63
  setInitialValue = _useState6[1];
66
64
 
65
+ var _useState7 = useState(),
66
+ _useState8 = _slicedToArray(_useState7, 2),
67
+ cellLabel = _useState8[0],
68
+ setCellLabel = _useState8[1];
69
+
67
70
  var activeCellId = state.activeCellId,
68
71
  editId = state.editId;
69
72
  var previousState = usePreviousValue({
@@ -80,7 +83,12 @@ export var InlineEditCell = function InlineEditCell(_ref) {
80
83
  var datePickerRef = useRef();
81
84
  var outerButtonElement = useRef();
82
85
  useEffect(function () {
83
- setInitialValue(value); // eslint-disable-next-line react-hooks/exhaustive-deps
86
+ setInitialValue(value);
87
+ var columnId = cell.column.id;
88
+ var columnLabel = instance.columns.find(function (item) {
89
+ return item.id === columnId;
90
+ });
91
+ setCellLabel(typeof columnLabel.Header === 'string' ? columnLabel.Header : 'Inline edit cell label'); // eslint-disable-next-line react-hooks/exhaustive-deps
84
92
  }, []); // If you are in edit mode and click outside of the cell,
85
93
  // this changes the cell back to the InlineEditButton
86
94
 
@@ -248,7 +256,8 @@ export var InlineEditCell = function InlineEditCell(_ref) {
248
256
 
249
257
  return /*#__PURE__*/React.createElement(Dropdown, _extends({
250
258
  id: cellId,
251
- label: "Dropdown menu options"
259
+ label: cellLabel || 'Dropdown menu options',
260
+ ariaLabel: cellLabel || 'Dropdown menu options'
252
261
  }, inputProps, {
253
262
  hideLabel: true,
254
263
  style: {
@@ -350,7 +359,7 @@ export var InlineEditCell = function InlineEditCell(_ref) {
350
359
  position: 'static'
351
360
  },
352
361
  placeholder: (datePickerInputProps === null || datePickerInputProps === void 0 ? void 0 : datePickerInputProps.placeholder) || 'mm/dd/yyyy',
353
- labelText: (datePickerInputProps === null || datePickerInputProps === void 0 ? void 0 : datePickerInputProps.labelText) || 'Set date',
362
+ labelText: (datePickerInputProps === null || datePickerInputProps === void 0 ? void 0 : datePickerInputProps.labelText) || cellLabel || 'Set date',
354
363
  id: datePickerInputProps.id || "".concat(blockClass, "__inline-edit--date-picker--").concat(cell.row.index),
355
364
  hideLabel: true
356
365
  })));
@@ -407,7 +416,7 @@ export var InlineEditCell = function InlineEditCell(_ref) {
407
416
  totalColumns: totalColumns,
408
417
  type: type
409
418
  }), !nonEditCell && inEditMode && cellId === activeCellId && /*#__PURE__*/React.createElement(React.Fragment, null, type === 'text' && /*#__PURE__*/React.createElement(TextInput, _extends({
410
- labelText: label,
419
+ labelText: cellLabel,
411
420
  placeholder: placeholder
412
421
  }, inputProps, {
413
422
  id: cellId,
@@ -423,7 +432,7 @@ export var InlineEditCell = function InlineEditCell(_ref) {
423
432
  ref: textInputRef
424
433
  })), type === 'number' && /*#__PURE__*/React.createElement(NumberInput, _extends({
425
434
  placeholder: placeholder,
426
- label: label
435
+ label: cellLabel
427
436
  }, inputProps, {
428
437
  id: cellId,
429
438
  hideLabel: true,
@@ -449,7 +458,6 @@ InlineEditCell.propTypes = {
449
458
  rowSize: PropTypes.string,
450
459
  tableId: PropTypes.string
451
460
  }),
452
- label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
453
461
  nonEditCell: PropTypes.bool,
454
462
  placeholder: PropTypes.string,
455
463
  tabIndex: PropTypes.number,
@@ -10,8 +10,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
10
10
  * This source code is licensed under the Apache-2.0 license found in the
11
11
  * LICENSE file in the root directory of this source tree.
12
12
  */
13
- // This function returns the state back to the reducer after
13
+ import { pkg } from '../../../../../../settings';
14
+ var blockClass = "".concat(pkg.prefix, "--datagrid"); // This function returns the state back to the reducer after
14
15
  // determining the new active cell value
16
+
15
17
  export var returnUpdatedActiveCell = function returnUpdatedActiveCell(_ref) {
16
18
  var activeCellCoords = _ref.activeCellCoords,
17
19
  direction = _ref.direction,
@@ -25,6 +27,12 @@ export var returnUpdatedActiveCell = function returnUpdatedActiveCell(_ref) {
25
27
  });
26
28
 
27
29
  var newActiveCellId = "column-".concat(newActiveCoords.column, "-row-").concat(newActiveCoords.row);
30
+ var newCellIdButton = document.querySelector("#".concat(instance.tableId, " .").concat(blockClass, "__table-with-inline-edit [data-cell-id=\"").concat(newActiveCellId, "\"] .").concat(blockClass, "__inline-edit-button")); // Allows scrollable area to keep focused/active cell id visible
31
+
32
+ if (newCellIdButton) {
33
+ newCellIdButton === null || newCellIdButton === void 0 ? void 0 : newCellIdButton.focus();
34
+ }
35
+
28
36
  return _objectSpread(_objectSpread({}, state), {}, {
29
37
  activeCellId: newActiveCellId
30
38
  });
@@ -11,8 +11,16 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
11
11
  * LICENSE file in the root directory of this source tree.
12
12
  */
13
13
  import { carbon, pkg } from '../../../../../settings';
14
+ import { handleMultipleKeys } from './handleMultipleKeys';
15
+ import { getCellIdAsObject } from './InlineEditContext/getCellIdAsObject';
14
16
  var blockClass = "".concat(pkg.prefix, "--datagrid");
15
- export var handleGridKeyPress = function handleGridKeyPress(event, dispatch, state, instance) {
17
+ export var handleGridKeyPress = function handleGridKeyPress(_ref) {
18
+ var event = _ref.event,
19
+ dispatch = _ref.dispatch,
20
+ state = _ref.state,
21
+ instance = _ref.instance,
22
+ keysPressedList = _ref.keysPressedList,
23
+ usingMac = _ref.usingMac;
16
24
  var key = event.key;
17
25
  var gridActive = state.gridActive,
18
26
  activeCellId = state.activeCellId,
@@ -89,7 +97,7 @@ export var handleGridKeyPress = function handleGridKeyPress(event, dispatch, sta
89
97
  } // Prevent arrow keys, home key, and end key from scrolling the page when the data spreadsheet container has focus
90
98
 
91
99
 
92
- if (['End', 'Home', 'ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].indexOf(key) > -1 && !isEditing) {
100
+ if (['End', 'Home', 'ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].indexOf(key) > -1 && !isEditing && keysPressedList.length < 2) {
93
101
  event.preventDefault();
94
102
  }
95
103
 
@@ -99,99 +107,157 @@ export var handleGridKeyPress = function handleGridKeyPress(event, dispatch, sta
99
107
  instance: instance
100
108
  };
101
109
 
102
- switch (key) {
103
- case 'Tab':
104
- {
105
- if (!editId) {
110
+ if (keysPressedList.length > 1) {
111
+ handleMultipleKeys({
112
+ usingMac: usingMac,
113
+ keysPressedList: keysPressedList,
114
+ dispatch: dispatch,
115
+ activeCellId: activeCellId,
116
+ instance: instance
117
+ });
118
+ }
119
+
120
+ if (keysPressedList.length < 2) {
121
+ switch (key) {
122
+ case 'Tab':
123
+ {
124
+ if (!editId) {
125
+ dispatch({
126
+ type: 'REMOVE_GRID_ACTIVE_FOCUS',
127
+ payload: activeCellId
128
+ });
129
+ }
130
+
131
+ break;
132
+ }
133
+
134
+ case 'ArrowRight':
135
+ {
106
136
  dispatch({
107
- type: 'REMOVE_GRID_ACTIVE_FOCUS',
108
- payload: activeCellId
137
+ type: 'UPDATE_ACTIVE_CELL_ID',
138
+ payload: _objectSpread({
139
+ direction: 'right'
140
+ }, sharedUpdateParams)
109
141
  });
142
+ break;
110
143
  }
111
144
 
112
- break;
113
- }
114
-
115
- case 'ArrowRight':
116
- {
117
- dispatch({
118
- type: 'UPDATE_ACTIVE_CELL_ID',
119
- payload: _objectSpread({
120
- direction: 'right'
121
- }, sharedUpdateParams)
122
- });
123
- break;
124
- }
125
-
126
- case 'ArrowLeft':
127
- {
128
- dispatch({
129
- type: 'UPDATE_ACTIVE_CELL_ID',
130
- payload: _objectSpread({
131
- direction: 'left'
132
- }, sharedUpdateParams)
133
- });
134
- break;
135
- }
136
-
137
- case 'ArrowUp':
138
- {
139
- dispatch({
140
- type: 'UPDATE_ACTIVE_CELL_ID',
141
- payload: _objectSpread({
142
- direction: 'up'
143
- }, sharedUpdateParams)
144
- });
145
- break;
146
- }
147
-
148
- case 'ArrowDown':
149
- {
150
- dispatch({
151
- type: 'UPDATE_ACTIVE_CELL_ID',
152
- payload: _objectSpread({
153
- direction: 'down'
154
- }, sharedUpdateParams)
155
- });
156
- break;
157
- }
158
-
159
- case ' ':
160
- case 'F2':
161
- case 'Enter':
162
- {
163
- // Disabled cells are not allowed to go into edit mode
164
- if (isDisabledCell) {
165
- return;
166
- } // Only go into edit mode if there is no editId, meaning that we're not already in edit mode
167
-
168
-
169
- if (!editId) {
170
- var focusedType = focusedCell.getAttribute('data-inline-type'); // Open dropdown immediately after entering edit mode for selection type
171
-
172
- if (focusedType === 'selection') {
173
- setTimeout(function () {
174
- var dropdownTrigger = focusedCell.querySelector('button');
175
- dropdownTrigger === null || dropdownTrigger === void 0 ? void 0 : dropdownTrigger.click();
176
- }, 1);
177
- }
145
+ case 'ArrowLeft':
146
+ {
147
+ dispatch({
148
+ type: 'UPDATE_ACTIVE_CELL_ID',
149
+ payload: _objectSpread({
150
+ direction: 'left'
151
+ }, sharedUpdateParams)
152
+ });
153
+ break;
154
+ }
178
155
 
179
- if (focusedType === 'date') {
180
- setTimeout(function () {
181
- var dateInputTrigger = focusedCell.querySelector('input');
182
- dateInputTrigger === null || dateInputTrigger === void 0 ? void 0 : dateInputTrigger.click();
183
- dateInputTrigger === null || dateInputTrigger === void 0 ? void 0 : dateInputTrigger.focus();
184
- }, 1);
185
- }
156
+ case 'ArrowUp':
157
+ {
158
+ dispatch({
159
+ type: 'UPDATE_ACTIVE_CELL_ID',
160
+ payload: _objectSpread({
161
+ direction: 'up'
162
+ }, sharedUpdateParams)
163
+ });
164
+ break;
165
+ }
186
166
 
167
+ case 'ArrowDown':
168
+ {
187
169
  dispatch({
188
- type: 'ENTER_EDIT_MODE',
189
- payload: {
190
- activeCellId: activeCellId,
191
- editId: activeCellId
192
- }
170
+ type: 'UPDATE_ACTIVE_CELL_ID',
171
+ payload: _objectSpread({
172
+ direction: 'down'
173
+ }, sharedUpdateParams)
174
+ });
175
+ break;
176
+ }
177
+ // Move active cell to first column in current row
178
+
179
+ case 'Home':
180
+ {
181
+ var activeCellObject = getCellIdAsObject(activeCellId);
182
+
183
+ var newActiveCellCoords = _objectSpread(_objectSpread({}, activeCellObject), {}, {
184
+ column: 0
185
+ });
186
+
187
+ var newActiveCellId = "column-".concat(newActiveCellCoords.column, "-row-").concat(newActiveCellCoords.row);
188
+ var scrollElement = document.querySelector("#".concat(instance.tableId, " .").concat(pkg.prefix, "--datagrid__table-container")); // Scroll table container to the furthest left position
189
+
190
+ scrollElement.scrollLeft = 0;
191
+ dispatch({
192
+ type: 'UPDATE_ACTIVE_CELL_ID',
193
+ payload: newActiveCellId
193
194
  });
195
+ break;
194
196
  }
195
- }
197
+ // Move active cell to last column in current row
198
+
199
+ case 'End':
200
+ {
201
+ var _activeCellObject = getCellIdAsObject(activeCellId);
202
+
203
+ var totalVisibleColumns = instance.visibleColumns.filter(function (item) {
204
+ return item.id !== 'spacer';
205
+ });
206
+
207
+ var _newActiveCellCoords = _objectSpread(_objectSpread({}, _activeCellObject), {}, {
208
+ column: totalVisibleColumns.length - 1
209
+ });
210
+
211
+ var _newActiveCellId = "column-".concat(_newActiveCellCoords.column, "-row-").concat(_newActiveCellCoords.row);
212
+
213
+ var _scrollElement = document.querySelector("#".concat(instance.tableId, " .").concat(pkg.prefix, "--datagrid__table-container")); // Scroll table container to the furthest right position
214
+
215
+
216
+ _scrollElement.scrollLeft = _scrollElement.scrollWidth;
217
+ dispatch({
218
+ type: 'UPDATE_ACTIVE_CELL_ID',
219
+ payload: _newActiveCellId
220
+ });
221
+ break;
222
+ }
223
+
224
+ case ' ':
225
+ case 'F2':
226
+ case 'Enter':
227
+ {
228
+ // Disabled cells are not allowed to go into edit mode
229
+ if (isDisabledCell) {
230
+ return;
231
+ } // Only go into edit mode if there is no editId, meaning that we're not already in edit mode
232
+
233
+
234
+ if (!editId) {
235
+ var focusedType = focusedCell.getAttribute('data-inline-type'); // Open dropdown immediately after entering edit mode for selection type
236
+
237
+ if (focusedType === 'selection') {
238
+ setTimeout(function () {
239
+ var dropdownTrigger = focusedCell.querySelector('button');
240
+ dropdownTrigger === null || dropdownTrigger === void 0 ? void 0 : dropdownTrigger.click();
241
+ }, 1);
242
+ }
243
+
244
+ if (focusedType === 'date') {
245
+ setTimeout(function () {
246
+ var dateInputTrigger = focusedCell.querySelector('input');
247
+ dateInputTrigger === null || dateInputTrigger === void 0 ? void 0 : dateInputTrigger.click();
248
+ dateInputTrigger === null || dateInputTrigger === void 0 ? void 0 : dateInputTrigger.focus();
249
+ }, 1);
250
+ }
251
+
252
+ dispatch({
253
+ type: 'ENTER_EDIT_MODE',
254
+ payload: {
255
+ activeCellId: activeCellId,
256
+ editId: activeCellId
257
+ }
258
+ });
259
+ }
260
+ }
261
+ }
196
262
  }
197
263
  };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { includesResourceKey } from '../../../../DataSpreadsheet/utils/handleMultipleKeys';
8
+ import { pkg } from '../../../../../settings';
9
+ var blockClass = "".concat(pkg.prefix, "--datagrid");
10
+ export var handleMultipleKeys = function handleMultipleKeys(_ref) {
11
+ var usingMac = _ref.usingMac,
12
+ keysPressedList = _ref.keysPressedList,
13
+ dispatch = _ref.dispatch,
14
+ activeCellId = _ref.activeCellId,
15
+ instance = _ref.instance;
16
+
17
+ // Resource key and Home
18
+ // Move active cell to first cell in first row and column
19
+ if (includesResourceKey(keysPressedList, usingMac) && keysPressedList.includes('Home')) {
20
+ var scrollElement = document.querySelector("#".concat(instance.tableId, " .").concat(pkg.prefix, "--datagrid__table-container")); // Scroll table container to the furthest top left position
21
+
22
+ scrollElement.scrollTop = 0;
23
+ scrollElement.scrollLeft = 0;
24
+ dispatch({
25
+ type: 'UPDATE_ACTIVE_CELL_ID',
26
+ payload: 'column-0-row-0'
27
+ });
28
+ } // Resource key and End
29
+ // Move active cell to last cell in in the last row and column
30
+
31
+
32
+ if (includesResourceKey(keysPressedList, usingMac) && keysPressedList.includes('End')) {
33
+ var _instance$rows;
34
+
35
+ var totalVisibleColumns = instance.visibleColumns.filter(function (item) {
36
+ return item.id !== 'spacer';
37
+ }).length;
38
+ var totalRows = (_instance$rows = instance.rows) === null || _instance$rows === void 0 ? void 0 : _instance$rows.length;
39
+ var lastCellDataId = "column-".concat(totalVisibleColumns - 1, "-row-").concat(totalRows - 1);
40
+ var lastCellElement = document.querySelector("#".concat(instance.tableId, " .").concat(blockClass, "__table-with-inline-edit [data-cell-id=\"").concat(activeCellId, "\"]"));
41
+
42
+ var _scrollElement = document.querySelector("#".concat(instance.tableId, " .").concat(pkg.prefix, "--datagrid__table-container")); // Scroll table container to the furthest bottom right position
43
+
44
+
45
+ _scrollElement.scrollTop = _scrollElement.scrollHeight;
46
+ _scrollElement.scrollLeft = _scrollElement.scrollWidth;
47
+
48
+ if (lastCellElement) {
49
+ dispatch({
50
+ type: 'UPDATE_ACTIVE_CELL_ID',
51
+ payload: lastCellDataId
52
+ });
53
+ } else {
54
+ // If a Datagrid component is using virtualized data, it's possible that the last cell
55
+ // has not yet been rendered. In this case, we simply need to wait until the scrollable
56
+ // container has scrolled to the bottom/right most position, then we can dispatch the
57
+ // update active cell id action
58
+ setTimeout(function () {
59
+ dispatch({
60
+ type: 'UPDATE_ACTIVE_CELL_ID',
61
+ payload: lastCellDataId
62
+ });
63
+ }, 250);
64
+ }
65
+ }
66
+ };
@@ -1,7 +1,8 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["id", "onClick", "shouldHideMenuItem", "shouldDisableMenuItem", "disabled"];
4
+ var _excluded = ["id", "itemText", "onClick", "icon"],
5
+ _excluded2 = ["id", "onClick", "shouldHideMenuItem", "shouldDisableMenuItem", "disabled"];
5
6
 
6
7
  /*
7
8
  * Licensed Materials - Property of IBM
@@ -19,7 +20,8 @@ var blockClass = "".concat(pkg.prefix, "--datagrid");
19
20
  var useActionsColumn = function useActionsColumn(hooks) {
20
21
  var useAttachActionsOnInstance = function useAttachActionsOnInstance(instance) {
21
22
  var rowActions = instance.rowActions,
22
- isFetching = instance.isFetching;
23
+ isFetching = instance.isFetching,
24
+ selectedFlatRows = instance.selectedFlatRows;
23
25
 
24
26
  if (rowActions && Array.isArray(rowActions)) {
25
27
  var addActionsMenu = function addActionsMenu(props, cellData) {
@@ -28,7 +30,7 @@ var useActionsColumn = function useActionsColumn(hooks) {
28
30
  column = cell.column;
29
31
 
30
32
  if (column.isAction) {
31
- var _cx;
33
+ var _cx3;
32
34
 
33
35
  return [props, {
34
36
  children: /*#__PURE__*/React.createElement("div", {
@@ -40,26 +42,37 @@ var useActionsColumn = function useActionsColumn(hooks) {
40
42
  style: {
41
43
  display: 'flex'
42
44
  }
43
- }, rowActions.map(function (action) {
45
+ }, rowActions.map(function (action, index) {
44
46
  var id = action.id,
45
47
  itemText = action.itemText,
46
48
  _onClick = action.onClick,
47
- icon = action.icon;
49
+ icon = action.icon,
50
+ rest = _objectWithoutProperties(action, _excluded);
51
+
52
+ var selectedRowId = selectedFlatRows === null || selectedFlatRows === void 0 ? void 0 : selectedFlatRows.filter(function (item) {
53
+ return item.id === row.id ? item.id : null;
54
+ });
48
55
  return /*#__PURE__*/React.createElement("div", {
49
- className: "".concat(blockClass, "__actions-column-button"),
50
- key: ""
51
- }, /*#__PURE__*/React.createElement(OverflowMenu, {
56
+ className: cx("".concat(blockClass, "__actions-column-button"), _defineProperty({}, "".concat(blockClass, "__disabled-row-action-button"), selectedFlatRows && selectedFlatRows.length && selectedRowId && selectedRowId.length)),
57
+ key: "".concat(itemText, "__").concat(index)
58
+ }, /*#__PURE__*/React.createElement(OverflowMenu, _extends({}, rest, {
52
59
  renderIcon: icon,
53
60
  hasIconOnly: true,
54
61
  light: true,
55
62
  iconDescription: itemText,
56
63
  kind: "ghost",
64
+ className: cx(_defineProperty({}, "".concat(blockClass, "__disabled-row-action"), selectedFlatRows && selectedFlatRows.length && selectedRowId && selectedRowId.length)),
57
65
  onClick: function onClick(e) {
66
+ if (selectedFlatRows && selectedFlatRows.length && selectedRowId && selectedRowId.length) {
67
+ // Row actions should be disabled if row is selected and batchActions toolbar is active
68
+ return;
69
+ }
70
+
58
71
  e.stopPropagation();
59
72
 
60
73
  _onClick(id, row, e);
61
74
  }
62
- }));
75
+ })));
63
76
  })), !isFetching && rowActions.length > 2 && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(OverflowMenu, {
64
77
  size: "sm",
65
78
  light: true,
@@ -73,7 +86,7 @@ var useActionsColumn = function useActionsColumn(hooks) {
73
86
  shouldHideMenuItem = action.shouldHideMenuItem,
74
87
  shouldDisableMenuItem = action.shouldDisableMenuItem,
75
88
  disabled = action.disabled,
76
- rest = _objectWithoutProperties(action, _excluded);
89
+ rest = _objectWithoutProperties(action, _excluded2);
77
90
 
78
91
  var hidden = typeof shouldHideMenuItem === 'function' && shouldHideMenuItem(row); // shouldDisableMenuItem will override disabled because it's more specific
79
92
  // if shouldDisableMenuItem doesn't exists, fall back to disabled
@@ -94,7 +107,10 @@ var useActionsColumn = function useActionsColumn(hooks) {
94
107
  key: id
95
108
  }));
96
109
  })))),
97
- className: cx((_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__actions-column-cell"), true), _defineProperty(_cx, "".concat(blockClass, "__cell"), true), _cx))
110
+ className: cx((_cx3 = {}, _defineProperty(_cx3, "".concat(blockClass, "__actions-column-cell"), true), _defineProperty(_cx3, "".concat(blockClass, "__cell"), true), _cx3)),
111
+ style: {
112
+ width: 96
113
+ }
98
114
  }];
99
115
  }
100
116
 
@@ -37,7 +37,6 @@ var useExpandedRow = function useExpandedRow(hooks) {
37
37
  return _objectSpread(_objectSpread({}, row), {}, {
38
38
  canExpand: row.original && !row.original.notExpandable,
39
39
  expandedContentHeight: expandedRowsHeight[row.index] || expandedContentHeight,
40
- // RowRenderer: DatagridExpandedRow(row.RowRenderer, expansionRenderer),
41
40
  RowRenderer: DatagridExpandedRow(row.RowRenderer, ExpandedRowContentComponent)
42
41
  });
43
42
  });