@carbon/ibm-products 1.70.0 → 1.71.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. package/README.md +8 -4
  2. package/css/index-full-carbon.css +0 -7
  3. package/css/index-full-carbon.css.map +1 -1
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +0 -7
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css.map +1 -1
  8. package/css/index-without-carbon.css +0 -7
  9. package/css/index-without-carbon.css.map +1 -1
  10. package/css/index-without-carbon.min.css.map +1 -1
  11. package/css/index.css +0 -7
  12. package/css/index.css.map +1 -1
  13. package/css/index.min.css.map +1 -1
  14. package/es/components/CreateTearsheet/preview-components/MultiStepWithIntro.js +6 -3
  15. package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +6 -1
  16. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +5 -3
  17. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +11 -4
  18. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterFlyout.js +4 -0
  19. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +0 -1
  20. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +34 -10
  21. package/es/components/Datagrid/Datagrid/addons/Filtering/constants.js +6 -2
  22. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilterContext.js +7 -0
  23. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +36 -3
  24. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useShouldDisableButtons.js +1 -0
  25. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useSubscribeToEventEmitter.js +1 -0
  26. package/es/components/Datagrid/Datagrid/addons/Filtering/index.js +1 -0
  27. package/es/components/Datagrid/Datagrid/addons/stateReducer.js +4 -7
  28. package/es/components/Datagrid/useFiltering.js +1 -6
  29. package/es/components/Datagrid/useInfiniteScroll.js +7 -3
  30. package/es/components/Datagrid/useSelectAllToggle.js +11 -10
  31. package/es/components/Datagrid/useSelectRows.js +2 -2
  32. package/es/components/Tearsheet/TearsheetShell.js +6 -4
  33. package/es/global/js/hooks/index.js +3 -2
  34. package/es/global/js/hooks/useFocus.js +72 -0
  35. package/es/global/js/hooks/useIsomorphicEffect.js +12 -0
  36. package/es/global/js/package-settings.js +0 -1
  37. package/lib/components/CreateTearsheet/preview-components/MultiStepWithIntro.js +6 -3
  38. package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +6 -1
  39. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +4 -2
  40. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +11 -4
  41. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterFlyout.js +4 -0
  42. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +0 -1
  43. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +30 -7
  44. package/lib/components/Datagrid/Datagrid/addons/Filtering/constants.js +8 -3
  45. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilterContext.js +7 -0
  46. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +33 -1
  47. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useShouldDisableButtons.js +1 -0
  48. package/lib/components/Datagrid/Datagrid/addons/stateReducer.js +4 -7
  49. package/lib/components/Datagrid/useFiltering.js +0 -5
  50. package/lib/components/Datagrid/useInfiniteScroll.js +7 -3
  51. package/lib/components/Datagrid/useSelectAllToggle.js +9 -9
  52. package/lib/components/Datagrid/useSelectRows.js +1 -1
  53. package/lib/components/Tearsheet/TearsheetShell.js +6 -4
  54. package/lib/global/js/hooks/index.js +8 -1
  55. package/lib/global/js/hooks/useFocus.js +79 -0
  56. package/lib/global/js/hooks/useIsomorphicEffect.js +18 -0
  57. package/lib/global/js/package-settings.js +0 -1
  58. package/package.json +6 -5
  59. package/scss/components/Datagrid/styles/addons/_FilterPanel.scss +6 -7
  60. package/telemetry.yml +816 -0
@@ -30,7 +30,8 @@ var getAccessibilityProps = function getAccessibilityProps(header) {
30
30
  return props;
31
31
  };
32
32
  var HeaderRow = function HeaderRow(datagridState, headRef, headerGroup) {
33
- var resizerAriaLabel = datagridState.resizerAriaLabel;
33
+ var resizerAriaLabel = datagridState.resizerAriaLabel,
34
+ isFetching = datagridState.isFetching;
34
35
  // Used to measure the height of the table and uses that value
35
36
  // to display a vertical line to indicate the column you are resizing
36
37
  useEffect(function () {
@@ -103,9 +104,13 @@ var HeaderRow = function HeaderRow(datagridState, headRef, headerGroup) {
103
104
  key: header.id,
104
105
  "aria-hidden": header.id === 'spacer' && 'true'
105
106
  }, getAccessibilityProps(header)), header.render('Header'), header.getResizerProps && !header.isAction && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("input", _extends({}, header.getResizerProps(), {
107
+ disabled: isFetching,
106
108
  onMouseDown: function onMouseDown(event) {
107
109
  return handleOnMouseDownResize(event, header.getResizerProps);
108
110
  },
111
+ onMouseUp: function onMouseUp() {
112
+ return handleColumnResizeEndEvent(dispatch, onColResizeEnd, header.id, true);
113
+ },
109
114
  onKeyDown: function onKeyDown(event) {
110
115
  var key = event.key;
111
116
  if (key === 'ArrowLeft' || key === 'ArrowRight') {
@@ -4,7 +4,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
5
  var _excluded = ["onChange"];
6
6
  /**
7
- * Copyright IBM Corp. 2020, 2023
7
+ * Copyright IBM Corp. 2020, 2024
8
8
  *
9
9
  * This source code is licensed under the Apache-2.0 license found in the
10
10
  * LICENSE file in the root directory of this source tree.
@@ -18,7 +18,7 @@ import { handleSelectAllRowData } from './addons/stateReducer';
18
18
  var blockClass = "".concat(pkg.prefix, "--datagrid");
19
19
  var SelectAll = function SelectAll(datagridState) {
20
20
  var _columns$;
21
- var _useState = useState(window.innerWidth),
21
+ var _useState = useState(typeof window !== 'undefined' ? window.innerWidth : ''),
22
22
  _useState2 = _slicedToArray(_useState, 2),
23
23
  windowSize = _useState2[0],
24
24
  setWindowSize = _useState2[1];
@@ -27,7 +27,9 @@ var SelectAll = function SelectAll(datagridState) {
27
27
  function updateSize() {
28
28
  setWindowSize(window.innerWidth);
29
29
  }
30
- window.addEventListener('resize', updateSize);
30
+ if (typeof window !== 'undefined') {
31
+ window.addEventListener('resize', updateSize);
32
+ }
31
33
  return function () {
32
34
  return window.removeEventListener('resize', updateSize);
33
35
  };
@@ -99,6 +99,16 @@ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridS
99
99
  }
100
100
  }));
101
101
  };
102
+ var onCancelHandler = function onCancelHandler() {
103
+ handleSelectAllRowData({
104
+ dispatch: dispatch,
105
+ rows: [],
106
+ getRowId: getRowId,
107
+ isChecked: false
108
+ });
109
+ toggleAllRowsSelected(false);
110
+ setGlobalFilter(null);
111
+ };
102
112
 
103
113
  // Only display the first two batch actions, the rest are
104
114
  // displayed inside of the ButtonMenu if there are more than
@@ -106,10 +116,7 @@ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridS
106
116
  return /*#__PURE__*/React.createElement(TableBatchActions, {
107
117
  shouldShowBatchActions: totalSelected > 0,
108
118
  totalSelected: totalSelected,
109
- onCancel: function onCancel() {
110
- toggleAllRowsSelected(false);
111
- setGlobalFilter(null);
112
- },
119
+ onCancel: onCancelHandler,
113
120
  translateWithId: translateWithIdBatchActions
114
121
  }, !displayAllInMenu && toolbarBatchActions && (toolbarBatchActions === null || toolbarBatchActions === void 0 ? void 0 : toolbarBatchActions.map(function (batchAction, index) {
115
122
  if (index < 2 && toolbarBatchActions.length > 3 || index < 3 && toolbarBatchActions.length <= 3) {
@@ -185,9 +185,13 @@ var FilterFlyout = function FilterFlyout(_ref) {
185
185
  };
186
186
 
187
187
  /** Effects */
188
+ // Close flyout when clicking outside
188
189
  useClickOutside(filterFlyoutRef, function (target) {
189
190
  var hasClickedOnDatePicker = target.closest('.flatpickr-calendar');
190
191
  var hasClickedOnDropdown = target.className === "".concat(carbon.prefix, "--list-box__menu-item__option");
192
+
193
+ // Do not do anything if flyout is closed or if clicking on anything
194
+ // rendered via a portal
191
195
  if (!open || hasClickedOnDatePicker || hasClickedOnDropdown) {
192
196
  return;
193
197
  }
@@ -1,6 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- /* eslint-disable react/jsx-key */
4
3
  /**
5
4
  * Copyright IBM Corp. 2022, 2024
6
5
  *
@@ -4,14 +4,15 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
6
  /**
7
- * Copyright IBM Corp. 2022, 2023
7
+ * Copyright IBM Corp. 2022, 2024
8
8
  *
9
9
  * This source code is licensed under the Apache-2.0 license found in the
10
10
  * LICENSE file in the root directory of this source tree.
11
11
  */
12
- import React, { createContext, useState } from 'react';
12
+
13
+ import React, { createContext, useState, useReducer } from 'react';
13
14
  import PropTypes from 'prop-types';
14
- import { DATE, DROPDOWN, NUMBER, RADIO, CHECKBOX, CLEAR_SINGLE_FILTER } from './constants';
15
+ import { DATE, DROPDOWN, NUMBER, RADIO, CHECKBOX, CLEAR_SINGLE_FILTER, SAVED_FILTERS } from './constants';
15
16
  export var FilterContext = /*#__PURE__*/createContext();
16
17
  var EventEmitter = {
17
18
  events: {},
@@ -141,22 +142,45 @@ var prepareFiltersForTags = function prepareFiltersForTags(filters, renderDateLa
141
142
  });
142
143
  return tags;
143
144
  };
144
- export var FilterProvider = function FilterProvider(_ref3) {
145
- var children = _ref3.children,
146
- filters = _ref3.filters,
147
- filterProps = _ref3.filterProps;
148
- var _ref4 = filterProps || {},
149
- renderDateLabel = _ref4.renderDateLabel;
145
+ var filteringReducer = function filteringReducer(state, action) {
146
+ switch (action.type) {
147
+ case SAVED_FILTERS:
148
+ {
149
+ var _ref3 = action.payload || {},
150
+ savedFilters = _ref3.savedFilters;
151
+ return _objectSpread(_objectSpread({}, state), {}, {
152
+ savedFilters: savedFilters
153
+ });
154
+ }
155
+ default:
156
+ return state;
157
+ }
158
+ };
159
+ export var FilterProvider = function FilterProvider(_ref4) {
160
+ var children = _ref4.children,
161
+ filters = _ref4.filters,
162
+ filterProps = _ref4.filterProps;
163
+ var _ref5 = filterProps || {},
164
+ renderDateLabel = _ref5.renderDateLabel;
150
165
  var filterTags = prepareFiltersForTags(filters, renderDateLabel);
151
166
  var _useState = useState(false),
152
167
  _useState2 = _slicedToArray(_useState, 2),
153
168
  panelOpen = _useState2[0],
154
169
  setPanelOpen = _useState2[1];
170
+ var initialState = {
171
+ savedFilters: []
172
+ };
173
+ var _useReducer = useReducer(filteringReducer, initialState),
174
+ _useReducer2 = _slicedToArray(_useReducer, 2),
175
+ state = _useReducer2[0],
176
+ dispatch = _useReducer2[1];
155
177
  var value = {
156
178
  filterTags: filterTags,
157
179
  EventEmitter: EventEmitter,
158
180
  panelOpen: panelOpen,
159
- setPanelOpen: setPanelOpen
181
+ setPanelOpen: setPanelOpen,
182
+ state: state,
183
+ dispatch: dispatch
160
184
  };
161
185
  return /*#__PURE__*/React.createElement(FilterContext.Provider, {
162
186
  value: value
@@ -1,9 +1,10 @@
1
1
  /**
2
- * Copyright IBM Corp. 2022, 2022
2
+ * Copyright IBM Corp. 2022, 2024
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+
7
8
  /** Constants for update methods can either be batch or instant */
8
9
  export var BATCH = 'batch';
9
10
  export var INSTANT = 'instant';
@@ -25,4 +26,7 @@ export var CLEAR_SINGLE_FILTER = 'clearSingleFilter';
25
26
 
26
27
  /** Constants for panel dimensions */
27
28
  export var PANEL_WIDTH = 320;
28
- export var ACTION_SET_HEIGHT = 64;
29
+ export var ACTION_SET_HEIGHT = 64;
30
+
31
+ /** Constants for local reducer */
32
+ export var SAVED_FILTERS = 'savedFilters';
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Copyright IBM Corp. 2023, 2024
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
+
1
8
  import { FilterContext } from '../FilterProvider';
2
9
  import { useContext } from 'react';
3
10
  var useFilterContext = function useFilterContext() {
@@ -10,11 +10,13 @@ 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
- import React, { useState, useRef, useEffect, useCallback } from 'react';
13
+
14
+ import React, { useState, useRef, useEffect, useCallback, useContext } from 'react';
14
15
  import { Checkbox, DatePicker, DatePickerInput, Dropdown, FormGroup, NumberInput, RadioButton, RadioButtonGroup } from 'carbon-components-react';
15
- import { INSTANT, BATCH, DATE, CHECKBOX, NUMBER, RADIO, DROPDOWN, PANEL } from '../constants';
16
+ import { INSTANT, BATCH, DATE, CHECKBOX, NUMBER, RADIO, DROPDOWN, PANEL, SAVED_FILTERS } from '../constants';
16
17
  import { getInitialStateFromFilters } from '../utils';
17
18
  import { usePreviousValue } from '../../../../../../global/js/hooks';
19
+ import { FilterContext } from '../FilterProvider';
18
20
  var useFilters = function useFilters(_ref) {
19
21
  var updateMethod = _ref.updateMethod,
20
22
  _ref$filters = _ref.filters,
@@ -25,6 +27,10 @@ var useFilters = function useFilters(_ref) {
25
27
  onCancel = _ref.onCancel,
26
28
  panelOpen = _ref.panelOpen,
27
29
  isFetching = _ref.isFetching;
30
+ var _useContext = useContext(FilterContext),
31
+ state = _useContext.state,
32
+ localDispatch = _useContext.dispatch;
33
+ var savedFilters = state.savedFilters;
28
34
  /** State */
29
35
  var _useState = useState(getInitialStateFromFilters(filters, variation, reactTableFiltersState)),
30
36
  _useState2 = _slicedToArray(_useState, 2),
@@ -164,6 +170,16 @@ var useFilters = function useFilters(_ref) {
164
170
  }
165
171
  setFiltersObjectArray(filtersObjectArrayCopy);
166
172
 
173
+ // Dispatch action from local filter context to track filters in order
174
+ // to keep history if `isFetching` becomes true. If so, react-table
175
+ // clears all filter history
176
+ localDispatch({
177
+ type: SAVED_FILTERS,
178
+ payload: {
179
+ savedFilters: filtersObjectArrayCopy
180
+ }
181
+ });
182
+
167
183
  // // Automatically apply the filters if the updateMethod is instant
168
184
  if (updateMethod === INSTANT) {
169
185
  setAllFilters(filtersObjectArrayCopy);
@@ -343,10 +359,27 @@ var useFilters = function useFilters(_ref) {
343
359
  setAllFilters(JSON.parse(prevFiltersObjectArrayRef.current));
344
360
  setFetchingReset(true);
345
361
  }
362
+ if (isFetching && fetchingReset) {
363
+ var cleanFilters = function cleanFilters(originalFilterState) {
364
+ var copy = _objectSpread({}, originalFilterState);
365
+ var updatedFilters = savedFilters.map(function (f) {
366
+ if (Object.hasOwn(copy, f.id)) {
367
+ copy[f.id] = f;
368
+ return copy;
369
+ }
370
+ return copy;
371
+ });
372
+ return updatedFilters[0];
373
+ };
374
+ setFiltersObjectArray(savedFilters);
375
+ var filterStateCopy = cleanFilters(filtersState);
376
+ setFiltersState(filterStateCopy);
377
+ }
346
378
  if (!isFetching) {
347
379
  setFetchingReset(false);
348
380
  }
349
- }, [isFetching, reactTableFiltersState, setAllFilters, fetchingReset]);
381
+ // eslint-disable-next-line react-hooks/exhaustive-deps
382
+ }, [isFetching, reactTableFiltersState, setAllFilters, fetchingReset, savedFilters, filtersObjectArray]);
350
383
  var cancel = function cancel() {
351
384
  // Reverting to previous filters only applies when using batch actions
352
385
  if (updateMethod === BATCH) {
@@ -5,6 +5,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
5
  * This source code is licensed under the Apache-2.0 license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+
8
9
  /* eslint-disable jsdoc/check-param-names */
9
10
 
10
11
  import { useState, useEffect } from 'react';
@@ -4,6 +4,7 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+
7
8
  import { useEffect, useContext } from 'react';
8
9
  import { FilterContext } from '../FilterProvider';
9
10
 
@@ -4,6 +4,7 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+
7
8
  export { default as FilterFlyout } from './FilterFlyout';
8
9
  export { default as FilterPanel } from './FilterPanel';
9
10
  export { FilterProvider, FilterContext } from './FilterProvider';
@@ -92,7 +92,7 @@ export var stateReducer = function stateReducer(newState, action) {
92
92
  if (rows) {
93
93
  var newSelectedRowData = {};
94
94
  rows.forEach(function (row) {
95
- newSelectedRowData[getRowId(row, row.index)] = row;
95
+ newSelectedRowData[getRowId(row.original, row.index)] = row.original;
96
96
  });
97
97
  return _objectSpread(_objectSpread({}, newState), {}, {
98
98
  selectedRowData: indeterminate || !isChecked ? {} : newSelectedRowData
@@ -111,7 +111,7 @@ export var stateReducer = function stateReducer(newState, action) {
111
111
  }
112
112
  if (_isChecked) {
113
113
  return _objectSpread(_objectSpread({}, newState), {}, {
114
- selectedRowData: _objectSpread(_objectSpread({}, newState.selectedRowData), {}, _defineProperty({}, _getRowId(rowData, rowData.index), rowData))
114
+ selectedRowData: _objectSpread(_objectSpread({}, newState.selectedRowData), {}, _defineProperty({}, _getRowId(rowData.original, rowData.index), rowData.original))
115
115
  });
116
116
  }
117
117
  if (rowData && !_isChecked) {
@@ -119,7 +119,7 @@ export var stateReducer = function stateReducer(newState, action) {
119
119
  var dataWithRemovedRow = Object.fromEntries(Object.entries(newData).filter(function (_ref5) {
120
120
  var _ref6 = _slicedToArray(_ref5, 1),
121
121
  key = _ref6[0];
122
- return parseInt(key) !== parseInt(rowData.index);
122
+ return parseInt(key) !== parseInt(_getRowId(rowData.original, rowData.index));
123
123
  }));
124
124
  return _objectSpread(_objectSpread({}, newState), {}, {
125
125
  selectedRowData: dataWithRemovedRow
@@ -177,10 +177,7 @@ export var stateReducer = function stateReducer(newState, action) {
177
177
  var currentColumn = {};
178
178
  currentColumn[_headerId2] = newState.columnResizing.columnWidths[_headerId2];
179
179
  var allChangedColumns = newState.columnResizing.columnWidths;
180
- var isResizing = newState.isResizing;
181
- if (isResizing) {
182
- onColResizeEnd === null || onColResizeEnd === void 0 ? void 0 : onColResizeEnd(currentColumn, allChangedColumns);
183
- }
180
+ onColResizeEnd === null || onColResizeEnd === void 0 ? void 0 : onColResizeEnd(currentColumn, allChangedColumns);
184
181
  if (!isKeyEvent) {
185
182
  if (typeof isKeyEvent === 'undefined') {
186
183
  // Blur resizer input if it has focus and is not from a key event resize
@@ -10,15 +10,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
10
10
  * LICENSE file in the root directory of this source tree.
11
11
  */
12
12
 
13
- import { useMemo, useEffect } from 'react';
14
- import { pkg } from '../../settings';
13
+ import { useMemo } from 'react';
15
14
  import { FilterFlyout } from './Datagrid/addons/Filtering';
16
15
  import { BATCH } from './Datagrid/addons/Filtering/constants';
17
16
  var useFiltering = function useFiltering(hooks) {
18
- useEffect(function () {
19
- pkg.checkReportFeatureEnabled('Datagrid.useFiltering');
20
- }, []);
21
-
22
17
  /* istanbul ignore next */
23
18
  var filterTypes = useMemo(function () {
24
19
  return {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright IBM Corp. 2020, 2023
2
+ * Copyright IBM Corp. 2020, 2024
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -13,14 +13,18 @@ var useInfiniteScroll = function useInfiniteScroll(hooks) {
13
13
  useParentDimensions(hooks);
14
14
  useResizeTable(hooks);
15
15
  var useInstance = function useInstance(instance) {
16
+ var _tableElement;
16
17
  var isFetching = instance.isFetching,
17
18
  tableHeight = instance.tableHeight,
18
19
  innerListRef = instance.innerListRef,
19
20
  fetchMoreData = instance.fetchMoreData,
20
21
  tableId = instance.tableId,
21
22
  loadMoreThreshold = instance.loadMoreThreshold;
22
- var tableElement = document.querySelector("#".concat(tableId));
23
- var totalTableHeight = tableHeight || (tableElement === null || tableElement === void 0 ? void 0 : tableElement.clientHeight);
23
+ var tableElement;
24
+ if (typeof document !== 'undefined') {
25
+ tableElement = document.querySelector("#".concat(tableId));
26
+ }
27
+ var totalTableHeight = tableHeight || ((_tableElement = tableElement) === null || _tableElement === void 0 ? void 0 : _tableElement.clientHeight);
24
28
  var loadMoreThresholdValue = typeof loadMoreThreshold === 'number' ? loadMoreThreshold : 200;
25
29
  var emptyFetchData = function emptyFetchData() {};
26
30
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1,18 +1,18 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- /*
4
- * Licensed Materials - Property of IBM
5
- * 5724-Q36
6
- * (c) Copyright IBM Corp. 2021
7
- * US Government Users Restricted Rights - Use, duplication or disclosure
8
- * restricted by GSA ADP Schedule Contract with IBM Corp.
3
+ /**
4
+ * Copyright IBM Corp. 2021, 2024
5
+ *
6
+ * This source code is licensed under the Apache-2.0 license found in the
7
+ * LICENSE file in the root directory of this source tree.
9
8
  */
10
- // @flow
11
- import React, { useLayoutEffect, useState } from 'react';
9
+
10
+ import React, { useState } from 'react';
12
11
  import cx from 'classnames';
13
12
  import { selectionColumnId } from './common-column-ids';
14
13
  import SelectAllWithToggle from './Datagrid/DatagridSelectAllWithToggle';
15
14
  import { pkg } from '../../settings';
15
+ import { useIsomorphicEffect } from '../../global/js/hooks';
16
16
  var blockClass = "".concat(pkg.prefix, "--datagrid__select-all");
17
17
  var useSelectAllToggle = function useSelectAllToggle(hooks) {
18
18
  useSelectAllWithToggleComponent(hooks);
@@ -37,11 +37,12 @@ var useSelectAllWithToggleComponent = function useSelectAllWithToggleComponent(h
37
37
  hooks.useInstance.push(useInstance);
38
38
  };
39
39
  var useAddClassNameToSelectRow = function useAddClassNameToSelectRow(hooks) {
40
- var _useState = useState(window.innerWidth),
40
+ var _useState = useState(0),
41
41
  _useState2 = _slicedToArray(_useState, 2),
42
42
  windowSize = _useState2[0],
43
43
  setWindowSize = _useState2[1];
44
- useLayoutEffect(function () {
44
+ useIsomorphicEffect(function () {
45
+ setWindowSize(window.innerWidth);
45
46
  function updateSize() {
46
47
  setWindowSize(window.innerWidth);
47
48
  }
@@ -7,7 +7,7 @@ var _excluded = ["onChange", "title"];
7
7
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
8
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
9
  /**
10
- * Copyright IBM Corp. 2020, 2023
10
+ * Copyright IBM Corp. 2020, 2024
11
11
  *
12
12
  * This source code is licensed under the Apache-2.0 license found in the
13
13
  * LICENSE file in the root directory of this source tree.
@@ -87,7 +87,7 @@ var SelectRow = function SelectRow(datagridState) {
87
87
  withStickyColumn = datagridState.withStickyColumn,
88
88
  dispatch = datagridState.dispatch,
89
89
  getRowId = datagridState.getRowId;
90
- var _useState = useState(window.innerWidth),
90
+ var _useState = useState(typeof window !== 'undefined' ? window.innerWidth : ''),
91
91
  _useState2 = _slicedToArray(_useState, 2),
92
92
  windowSize = _useState2[0],
93
93
  setWindowSize = _useState2[1];
@@ -27,6 +27,7 @@ import pconsole from '../../global/js/utils/pconsole';
27
27
  import { Button, ComposedModal, ModalHeader, ModalBody } from 'carbon-components-react';
28
28
  import { ActionSet } from '../ActionSet';
29
29
  import { Wrap } from '../../global/js/utils/Wrap';
30
+ import { useFocus } from '../../global/js/hooks/useFocus';
30
31
 
31
32
  // The block part of our conventional BEM class names (bc__E--M).
32
33
  var bc = "".concat(pkg.prefix, "--tearsheet");
@@ -97,6 +98,9 @@ export var TearsheetShell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
97
98
  var modalRef = ref || localRef;
98
99
  var _useResizeObserver = useResizeObserver(resizer),
99
100
  width = _useResizeObserver.width;
101
+ var _useFocus = useFocus(modalRef),
102
+ firstElement = _useFocus.firstElement,
103
+ keyDownListener = _useFocus.keyDownListener;
100
104
 
101
105
  // Keep track of the stack depth and our position in it (1-based, 0=closed)
102
106
  var _useState3 = useState(0),
@@ -133,10 +137,7 @@ export var TearsheetShell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
133
137
 
134
138
  // Callback to give the tearsheet the opportunity to claim focus
135
139
  handleStackChange.claimFocus = function () {
136
- var element = selectorPrimaryFocus ? modalRef.current.innerModal.current.querySelector(selectorPrimaryFocus) : modalRef.current.startSentinel.current;
137
- setTimeout(function () {
138
- return element.focus();
139
- }, 1);
140
+ firstElement === null || firstElement === void 0 ? void 0 : firstElement.focus();
140
141
  };
141
142
  useEffect(function () {
142
143
  var notify = function notify() {
@@ -204,6 +205,7 @@ export var TearsheetShell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
204
205
  open: open,
205
206
  selectorPrimaryFocus: selectorPrimaryFocus,
206
207
  onFocus: handleFocus,
208
+ onKeyDown: keyDownListener,
207
209
  preventCloseOnClickOutside: !isPassive,
208
210
  ref: modalRef,
209
211
  selectorsFloatingMenus: [".".concat(carbon.prefix, "--overflow-menu-options"), ".".concat(carbon.prefix, "--tooltip"), '.flatpickr-calendar', ".".concat(bc, "__container")],
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright IBM Corp. 2020, 2023
2
+ * Copyright IBM Corp. 2020, 2024
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -16,4 +16,5 @@ export { useResetCreateComponent } from './useResetCreateComponent';
16
16
  export { useRetrieveStepData } from './useRetrieveStepData';
17
17
  export { useValidCreateStepCount } from './useValidCreateStepCount';
18
18
  export { useControllableState } from './useControllableState';
19
- export { usePrefix } from './usePrefix';
19
+ export { usePrefix } from './usePrefix';
20
+ export { useIsomorphicEffect } from './useIsomorphicEffect';
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Copyright IBM Corp. 2024, 2024
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
+
8
+ import { pkg, carbon } from '../../../settings';
9
+ import { useCallback, useEffect } from 'react';
10
+ export var useFocus = function useFocus(modalRef) {
11
+ var tearsheetBaseClass = "".concat(pkg.prefix, "--tearsheet");
12
+ // Querying focusable element in the modal
13
+ // Query to exclude hidden elements in the modal from querySelectorAll() method
14
+ // feel free to include more if needed :)
15
+ var notQuery = ":not(.".concat(carbon.prefix, "--visually-hidden,.").concat(tearsheetBaseClass, "__header--no-close-icon,.").concat(carbon.prefix, "--btn--disabled,[aria-hidden=\"true\"],[tabindex=\"-1\"])");
16
+ // Queries to include element types button, input, select, textarea
17
+ var queryButton = "button".concat(notQuery);
18
+ var queryInput = "input".concat(notQuery);
19
+ var querySelect = "select".concat(notQuery);
20
+ var queryTextarea = "textarea".concat(notQuery);
21
+ var queryLink = "[href]".concat(notQuery);
22
+ // Final query
23
+ var query = "".concat(queryButton, ",").concat(queryLink, ",").concat(queryInput, ",").concat(querySelect, ",").concat(queryTextarea);
24
+ var getFocusable = useCallback(function () {
25
+ var _modalRef$current, _modalRef$current$inn, _modalRef$current$inn2;
26
+ // Selecting all focusable elements based on the above conditions
27
+ var focusableElements = modalRef === null || modalRef === void 0 ? void 0 : (_modalRef$current = modalRef.current) === null || _modalRef$current === void 0 ? void 0 : (_modalRef$current$inn = _modalRef$current.innerModal) === null || _modalRef$current$inn === void 0 ? void 0 : (_modalRef$current$inn2 = _modalRef$current$inn.current) === null || _modalRef$current$inn2 === void 0 ? void 0 : _modalRef$current$inn2.querySelectorAll("".concat(query));
28
+ var first = focusableElements === null || focusableElements === void 0 ? void 0 : focusableElements[0];
29
+ var last = focusableElements === null || focusableElements === void 0 ? void 0 : focusableElements[(focusableElements === null || focusableElements === void 0 ? void 0 : focusableElements.length) - 1];
30
+ var all = focusableElements;
31
+ return {
32
+ first: first,
33
+ last: last,
34
+ all: all
35
+ };
36
+ }, [modalRef, query]);
37
+ useEffect(function () {
38
+ getFocusable();
39
+ }, [getFocusable]);
40
+ var handleKeyDown = function handleKeyDown(event) {
41
+ // Checking whether the key is tab or not
42
+ if (event.key === 'Tab') {
43
+ // updating the focusable elements list
44
+ var _getFocusable = getFocusable(),
45
+ first = _getFocusable.first,
46
+ last = _getFocusable.last,
47
+ all = _getFocusable.all;
48
+ event.persist();
49
+ setTimeout(function () {
50
+ var _document, _document2;
51
+ if (event.shiftKey && !Array.prototype.includes.call(all, (_document = document) === null || _document === void 0 ? void 0 : _document.activeElement)) {
52
+ // Prevents the default "Tab" behavior
53
+ event.preventDefault();
54
+ // if the user press shift+tab and the current element not in focusable items
55
+ last === null || last === void 0 ? void 0 : last.focus();
56
+ } else if (!Array.prototype.includes.call(all, (_document2 = document) === null || _document2 === void 0 ? void 0 : _document2.activeElement)) {
57
+ event.preventDefault();
58
+ // user pressing tab key only then
59
+ // focusing the first element if the current element is not in focusable items
60
+ first === null || first === void 0 ? void 0 : first.focus();
61
+ }
62
+ }, 0);
63
+ }
64
+ };
65
+ return {
66
+ firstElement: getFocusable().first,
67
+ lastElement: getFocusable().last,
68
+ allElements: getFocusable().all,
69
+ keyDownListener: handleKeyDown,
70
+ getFocusable: getFocusable
71
+ };
72
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright IBM Corp. 2024, 2024
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
+
8
+ import { useEffect, useLayoutEffect } from 'react';
9
+
10
+ // Originally from `@carbon/react`, https://github.com/carbon-design-system/carbon/blob/main/packages/react/src/internal/useIsomorphicEffect.js
11
+ // useLayoutEffect on the client, useEffect on the server
12
+ export var useIsomorphicEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
@@ -101,7 +101,6 @@ var defaults = {
101
101
  'a-new-feature': false,
102
102
  'default-portal-target-body': true,
103
103
  'Datagrid.useInlineEdit': false,
104
- 'Datagrid.useFiltering': false,
105
104
  'Datagrid.useCustomizeColumns': false,
106
105
  'ExampleComponent.secondaryIcon': false,
107
106
  'ExampleComponent.useExample': false
@@ -129,7 +129,8 @@ var MultiStepWithIntro = function MultiStepWithIntro(_ref) {
129
129
  }, /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.RadioTile, {
130
130
  className: "".concat(_settings.pkg.prefix, "--tearsheet-create-multi-step--custom-tile"),
131
131
  value: "standard",
132
- id: "tile-1"
132
+ id: "tile-1",
133
+ tabIndex: selectedCategory === 'standard' ? 0 : -1
133
134
  }, /*#__PURE__*/_react.default.createElement(_NoDataIllustration.NoDataIllustration, {
134
135
  size: "lg"
135
136
  }), /*#__PURE__*/_react.default.createElement("span", {
@@ -137,7 +138,8 @@ var MultiStepWithIntro = function MultiStepWithIntro(_ref) {
137
138
  }, "Standard")), /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.RadioTile, {
138
139
  className: "".concat(_settings.pkg.prefix, "--tearsheet-create-multi-step--custom-tile"),
139
140
  value: "premium",
140
- id: "tile-2"
141
+ id: "tile-2",
142
+ tabIndex: selectedCategory === 'premium' ? 0 : -1
141
143
  }, /*#__PURE__*/_react.default.createElement(_NoDataIllustration.NoDataIllustration, {
142
144
  size: "lg"
143
145
  }), /*#__PURE__*/_react.default.createElement("span", {
@@ -145,7 +147,8 @@ var MultiStepWithIntro = function MultiStepWithIntro(_ref) {
145
147
  }, "Premium")), /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.RadioTile, {
146
148
  className: "".concat(_settings.pkg.prefix, "--tearsheet-create-multi-step--custom-tile"),
147
149
  value: "plus",
148
- id: "tile-3"
150
+ id: "tile-3",
151
+ tabIndex: selectedCategory === 'plus' ? 0 : -1
149
152
  }, /*#__PURE__*/_react.default.createElement(_NoDataIllustration.NoDataIllustration, {
150
153
  size: "lg"
151
154
  }), /*#__PURE__*/_react.default.createElement("span", {