@carbon/react 1.50.0-rc.0 → 1.51.0-rc.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/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +1005 -1038
  2. package/es/components/Accordion/AccordionItem.js +10 -15
  3. package/es/components/ChatButton/ChatButton.Skeleton.js +40 -0
  4. package/es/components/ChatButton/ChatButton.js +81 -0
  5. package/es/components/ComposedModal/ComposedModal.js +32 -8
  6. package/es/components/Copy/Copy.js +1 -1
  7. package/es/components/DataTable/DataTable.d.ts +21 -0
  8. package/es/components/DataTable/DataTable.js +19 -0
  9. package/es/components/DataTable/TableCell.d.ts +28 -3
  10. package/es/components/DataTable/TableCell.js +22 -5
  11. package/es/components/DataTable/TableExpandRow.js +1 -1
  12. package/es/components/DataTable/TableHeader.js +2 -2
  13. package/es/components/DataTable/TableRow.js +12 -1
  14. package/es/components/DataTable/TableToolbarSearch.d.ts +11 -38
  15. package/es/components/DataTable/TableToolbarSearch.js +1 -1
  16. package/es/components/DataTable/tools/normalize.js +3 -1
  17. package/es/components/Modal/Modal.js +25 -6
  18. package/es/components/MultiSelect/MultiSelect.d.ts +4 -0
  19. package/es/components/MultiSelect/MultiSelect.js +10 -1
  20. package/es/components/NumberInput/NumberInput.js +1 -1
  21. package/es/components/PaginationNav/PaginationNav.d.ts +45 -0
  22. package/es/components/PaginationNav/PaginationNav.js +24 -25
  23. package/es/components/PaginationNav/index.d.ts +9 -0
  24. package/es/components/Tabs/Tabs.js +2 -1
  25. package/es/components/Tile/Tile.d.ts +2 -2
  26. package/es/components/Tile/Tile.js +2 -2
  27. package/es/index.d.ts +1 -0
  28. package/es/index.js +3 -1
  29. package/lib/components/Accordion/AccordionItem.js +9 -14
  30. package/lib/components/ChatButton/ChatButton.Skeleton.js +50 -0
  31. package/lib/components/ChatButton/ChatButton.js +91 -0
  32. package/lib/components/ComposedModal/ComposedModal.js +32 -7
  33. package/lib/components/Copy/Copy.js +1 -1
  34. package/lib/components/DataTable/DataTable.d.ts +21 -0
  35. package/lib/components/DataTable/DataTable.js +19 -0
  36. package/lib/components/DataTable/TableCell.d.ts +28 -3
  37. package/lib/components/DataTable/TableCell.js +27 -5
  38. package/lib/components/DataTable/TableExpandRow.js +1 -1
  39. package/lib/components/DataTable/TableHeader.js +2 -2
  40. package/lib/components/DataTable/TableRow.js +12 -1
  41. package/lib/components/DataTable/TableToolbarSearch.d.ts +11 -38
  42. package/lib/components/DataTable/TableToolbarSearch.js +1 -1
  43. package/lib/components/DataTable/tools/normalize.js +3 -1
  44. package/lib/components/Modal/Modal.js +25 -5
  45. package/lib/components/MultiSelect/MultiSelect.d.ts +4 -0
  46. package/lib/components/MultiSelect/MultiSelect.js +10 -1
  47. package/lib/components/NumberInput/NumberInput.js +1 -1
  48. package/lib/components/PaginationNav/PaginationNav.d.ts +45 -0
  49. package/lib/components/PaginationNav/PaginationNav.js +24 -25
  50. package/lib/components/PaginationNav/index.d.ts +9 -0
  51. package/lib/components/Tabs/Tabs.js +2 -1
  52. package/lib/components/Tile/Tile.d.ts +2 -2
  53. package/lib/components/Tile/Tile.js +2 -2
  54. package/lib/index.d.ts +1 -0
  55. package/lib/index.js +6 -2
  56. package/package.json +5 -5
  57. package/scss/components/chat-button/_chat-button.scss +9 -0
  58. package/scss/components/chat-button/_index.scss +9 -0
@@ -113,6 +113,7 @@ class DataTable extends React__default["default"].Component {
113
113
  sortDirection,
114
114
  isSortable,
115
115
  isSortHeader: sortHeaderKey === header.key,
116
+ slug: header.slug,
116
117
  onClick: event => {
117
118
  const nextSortState = sorting.getNextSortState(this.props, this.state, {
118
119
  key: header.key
@@ -349,6 +350,23 @@ class DataTable extends React__default["default"].Component {
349
350
  useStaticWidth
350
351
  };
351
352
  });
353
+ /**
354
+ * Get the props associated with the given table cell.
355
+ *
356
+ * @param {object} config
357
+ * @param {object} config.cell the cell we want the props for
358
+ * @returns {object}
359
+ */
360
+ _rollupPluginBabelHelpers.defineProperty(this, "getCellProps", _ref4 => {
361
+ let {
362
+ cell,
363
+ ...rest
364
+ } = _ref4;
365
+ return {
366
+ ...rest,
367
+ hasSlugHeader: cell.hasSlugHeader
368
+ };
369
+ });
352
370
  /**
353
371
  * Helper utility to get all the currently selected rows
354
372
  * @returns {Array<string>} the array of rowIds that are currently selected
@@ -622,6 +640,7 @@ class DataTable extends React__default["default"].Component {
622
640
  getBatchActionProps: this.getBatchActionProps,
623
641
  getTableProps: this.getTableProps,
624
642
  getTableContainerProps: this.getTableContainerProps,
643
+ getCellProps: this.getCellProps,
625
644
  // Custom event handlers
626
645
  onInputChange: this.handleOnInputValueChange,
627
646
  // Expose internal state change actions
@@ -4,7 +4,32 @@
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
- import { TdHTMLAttributes } from 'react';
8
- export type TableCellProps = TdHTMLAttributes<HTMLTableCellElement>;
9
- declare const TableCell: React.FC<TableCellProps>;
7
+ import React from 'react';
8
+ import { ReactAttr } from '../../types/common';
9
+ interface TableCellProps extends ReactAttr<HTMLTableCellElement> {
10
+ /**
11
+ * Pass in children that will be embedded in the table header label
12
+ */
13
+ children?: React.ReactNode;
14
+ /**
15
+ * Specify an optional className to be applied to the container node
16
+ */
17
+ className?: string;
18
+ /**
19
+ * The width of the expanded row's internal cell
20
+ */
21
+ colSpan?: number;
22
+ /**
23
+ * Specify if the table cell is in an AI column
24
+ */
25
+ hasSlugHeader?: boolean;
26
+ /**
27
+ * The id of the matching th node in the table head. Addresses a11y concerns outlined here: https://www.ibm.com/able/guidelines/ci162/info_and_relationships.html and https://www.w3.org/TR/WCAG20-TECHS/H43
28
+ */
29
+ headers?: string;
30
+ }
31
+ declare const TableCell: {
32
+ ({ children, className, hasSlugHeader, colSpan, ...rest }: TableCellProps): import("react/jsx-runtime").JSX.Element;
33
+ displayName: string;
34
+ };
10
35
  export default TableCell;
@@ -9,11 +9,33 @@
9
9
 
10
10
  Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
- var wrapComponent = require('../../tools/wrapComponent.js');
12
+ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
13
+ var React = require('react');
14
+ var cx = require('classnames');
15
+ var usePrefix = require('../../internal/usePrefix.js');
13
16
 
14
- const TableCell = wrapComponent["default"]({
15
- name: 'TableCell',
16
- type: 'td'
17
- });
17
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
+
19
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
+ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
21
+
22
+ const TableCell = _ref => {
23
+ let {
24
+ children,
25
+ className,
26
+ hasSlugHeader,
27
+ colSpan,
28
+ ...rest
29
+ } = _ref;
30
+ const prefix = usePrefix.usePrefix();
31
+ const tableCellClassNames = cx__default["default"](className, {
32
+ [`${prefix}--table-cell--column-slug`]: hasSlugHeader
33
+ });
34
+ return /*#__PURE__*/React__default["default"].createElement("td", _rollupPluginBabelHelpers["extends"]({
35
+ className: tableCellClassNames ? tableCellClassNames : undefined,
36
+ colSpan: colSpan
37
+ }, rest), children);
38
+ };
39
+ TableCell.displayName = 'TableCell';
18
40
 
19
41
  exports["default"] = TableCell;
@@ -58,7 +58,7 @@ const TableExpandRow = /*#__PURE__*/React__default["default"].forwardRef((_ref,
58
58
  [`${prefix}--parent-row`]: true,
59
59
  [`${prefix}--expandable-row`]: isExpanded,
60
60
  [`${prefix}--data-table--selected`]: isSelected,
61
- [`${prefix}--parent-row--slug`]: rowHasSlug
61
+ [`${prefix}--data-table--slug-row`]: rowHasSlug
62
62
  }, rowClassName);
63
63
  const previousValue = isExpanded ? 'collapsed' : undefined;
64
64
  return /*#__PURE__*/React__default["default"].createElement("tr", _rollupPluginBabelHelpers["extends"]({}, rest, {
@@ -134,13 +134,13 @@ const TableHeader = /*#__PURE__*/React__default["default"].forwardRef(function T
134
134
  className: `${prefix}--table-sort__flex`
135
135
  }, /*#__PURE__*/React__default["default"].createElement("div", {
136
136
  className: `${prefix}--table-header-label`
137
- }, children), normalizedSlug, /*#__PURE__*/React__default["default"].createElement(iconsReact.ArrowUp, {
137
+ }, children), /*#__PURE__*/React__default["default"].createElement(iconsReact.ArrowUp, {
138
138
  size: 20,
139
139
  className: `${prefix}--table-sort__icon`
140
140
  }), /*#__PURE__*/React__default["default"].createElement(iconsReact.ArrowsVertical, {
141
141
  size: 20,
142
142
  className: `${prefix}--table-sort__icon-unsorted`
143
- }))));
143
+ }), normalizedSlug)));
144
144
  });
145
145
  TableHeader.propTypes = {
146
146
  /**
@@ -24,10 +24,21 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
24
24
 
25
25
  const TableRow = props => {
26
26
  const prefix = usePrefix.usePrefix();
27
+ let rowHasSlug;
28
+ if (props?.children) {
29
+ React__default["default"].Children.toArray(props.children).map(child => {
30
+ if (child.type?.displayName === 'TableSlugRow') {
31
+ if (child.props.slug) {
32
+ rowHasSlug = true;
33
+ }
34
+ }
35
+ });
36
+ }
27
37
  // Remove unnecessary props if provided to this component, these are
28
38
  // only useful in `TableExpandRow`
29
39
  const className = cx__default["default"](props.className, {
30
- [`${prefix}--data-table--selected`]: props.isSelected
40
+ [`${prefix}--data-table--selected`]: props.isSelected,
41
+ [`${prefix}--data-table--slug-row`]: rowHasSlug
31
42
  });
32
43
  const cleanProps = {
33
44
  ...omit__default["default"](props, ['ariaLabel', 'aria-label', 'aria-controls', 'onExpand', 'isExpanded', 'isSelected']),
@@ -6,12 +6,12 @@
6
6
  */
7
7
  import PropTypes from 'prop-types';
8
8
  import { ChangeEvent, FocusEvent, ReactNode } from 'react';
9
- export interface TableToolbarSearchProps {
10
- children?: ReactNode;
11
- /**
12
- * Provide an optional class name for the search container
13
- */
14
- className?: string;
9
+ import { SearchProps } from '../Search';
10
+ import { InternationalProps } from '../../types/common';
11
+ export type TableToolbarTranslationKey = 'carbon.table.toolbar.search.label' | 'carbon.table.toolbar.search.placeholder';
12
+ type ExcludedInheritedProps = 'defaultValue' | 'labelText' | 'onBlur' | 'onChange' | 'onExpand' | 'onFocus' | 'tabIndex';
13
+ export type TableToolbarSearchHandleExpand = (event: FocusEvent<HTMLInputElement>, newValue?: boolean) => void;
14
+ export interface TableToolbarSearchProps extends Omit<SearchProps, ExcludedInheritedProps>, InternationalProps<TableToolbarTranslationKey> {
15
15
  /**
16
16
  * Specifies if the search should initially render in an expanded state
17
17
  */
@@ -20,70 +20,43 @@ export interface TableToolbarSearchProps {
20
20
  * Provide an optional default value for the Search component
21
21
  */
22
22
  defaultValue?: string;
23
- /**
24
- * Specifies if the search should be disabled
25
- */
26
- disabled?: boolean;
27
23
  /**
28
24
  * Specifies if the search should expand
29
25
  */
30
26
  expanded?: boolean;
31
- /**
32
- * Provide an optional id for the search container
33
- */
34
- id?: string;
35
27
  /**
36
28
  * Provide an optional label text for the Search component icon
37
29
  */
38
- labelText?: string;
30
+ labelText?: ReactNode;
39
31
  /**
40
32
  * Provide an optional function to be called when the search input loses focus, this will be
41
33
  * passed the event as the first parameter and a function to handle the expanding of the search
42
34
  * input as the second
43
35
  */
44
- onBlur?: (event: FocusEvent<HTMLInputElement>, handleExpand: (event: FocusEvent<HTMLInputElement>, value: boolean) => void) => void;
36
+ onBlur?(event: FocusEvent<HTMLInputElement>, handleExpand: TableToolbarSearchHandleExpand): void;
45
37
  /**
46
38
  * Provide an optional hook that is called each time the input is updated
47
39
  */
48
40
  onChange?: (event: '' | ChangeEvent<HTMLInputElement>, value?: string) => void;
49
- /**
50
- * Optional callback called when the search value is cleared.
51
- */
52
- onClear?: () => void;
53
41
  /**
54
42
  * Provide an optional hook that is called each time the input is expanded
55
43
  */
56
- onExpand?: (event: FocusEvent<HTMLInputElement>, value: boolean) => void;
44
+ onExpand?(event: FocusEvent<HTMLInputElement>, newExpand: boolean): void;
57
45
  /**
58
46
  * Provide an optional function to be called when the search input gains focus, this will be
59
47
  * passed the event as the first parameter and a function to handle the expanding of the search
60
48
  * input as the second.
61
49
  */
62
- onFocus?: (event: FocusEvent<HTMLInputElement>, handleExpand: (event: FocusEvent<HTMLInputElement>, value: boolean) => void) => void;
50
+ onFocus?(event: FocusEvent<HTMLInputElement>, handleExpand: TableToolbarSearchHandleExpand): void;
63
51
  /**
64
- * Whether the search should be allowed to expand
52
+ * Whether the search should be allowed to expand.
65
53
  */
66
54
  persistent?: boolean;
67
- /**
68
- * Provide an optional placeholder text for the Search component
69
- */
70
- placeholder?: string;
71
55
  /**
72
56
  * Provide an optional className for the overall container of the Search
73
57
  */
74
58
  searchContainerClass?: string;
75
- /**
76
- * Specify the size of the Search
77
- */
78
- size?: 'sm' | 'md' | 'lg';
79
- /**
80
- * Optional prop to specify the tabIndex of the <Search> (in expanded state) or the container (in collapsed state)
81
- */
82
59
  tabIndex?: number | string;
83
- /**
84
- * Provide custom text for the component for each translation id
85
- */
86
- translateWithId?: (id: string) => string;
87
60
  }
88
61
  declare const TableToolbarSearch: {
89
62
  ({ className, searchContainerClass, onChange: onChangeProp, onClear, translateWithId: t, placeholder, labelText, expanded: expandedProp, defaultExpanded, defaultValue, disabled, onExpand, persistent, id, onBlur, onFocus, size, tabIndex, ...rest }: TableToolbarSearchProps): import("react/jsx-runtime").JSX.Element;
@@ -58,7 +58,7 @@ const TableToolbarSearch = _ref => {
58
58
  const {
59
59
  current: controlled
60
60
  } = React.useRef(expandedProp !== undefined);
61
- const [expandedState, setExpandedState] = React.useState(defaultExpanded || defaultValue);
61
+ const [expandedState, setExpandedState] = React.useState(Boolean(defaultExpanded || defaultValue));
62
62
  const expanded = controlled ? expandedProp : expandedState;
63
63
  const [value, setValue] = React.useState(defaultValue || '');
64
64
  const uniqueId = React.useMemo(getInstanceId, []);
@@ -52,7 +52,8 @@ const normalize = function (rows, headers) {
52
52
  }
53
53
  headers.forEach((_ref, i) => {
54
54
  let {
55
- key
55
+ key,
56
+ slug
56
57
  } = _ref;
57
58
  const id = cells.getCellId(row.id, key);
58
59
  // Initialize the cell info and state values, namely for editing
@@ -63,6 +64,7 @@ const normalize = function (rows, headers) {
63
64
  isEditing: false,
64
65
  isValid: true,
65
66
  errors: null,
67
+ hasSlugHeader: !!slug,
66
68
  info: {
67
69
  header: key
68
70
  }
@@ -21,6 +21,8 @@ var ButtonSet = require('../ButtonSet/ButtonSet.js');
21
21
  var InlineLoading = require('../InlineLoading/InlineLoading.js');
22
22
  var requiredIfGivenPropIsTruthy = require('../../prop-types/requiredIfGivenPropIsTruthy.js');
23
23
  var wrapFocus = require('../../internal/wrapFocus.js');
24
+ var debounce = require('lodash.debounce');
25
+ var useIsomorphicEffect = require('../../internal/useIsomorphicEffect.js');
24
26
  var setupGetInstanceId = require('../../tools/setupGetInstanceId.js');
25
27
  var usePrefix = require('../../internal/usePrefix.js');
26
28
  var index = require('../IconButton/index.js');
@@ -35,6 +37,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
35
37
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
36
38
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
37
39
  var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
40
+ var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
38
41
 
39
42
  const getInstanceId = setupGetInstanceId["default"]();
40
43
  const ModalSizes = ['xs', 'sm', 'md', 'lg'];
@@ -76,9 +79,11 @@ const Modal = /*#__PURE__*/React__default["default"].forwardRef(function Modal(_
76
79
  const prefix = usePrefix.usePrefix();
77
80
  const button = React.useRef(null);
78
81
  const secondaryButton = React.useRef();
82
+ const contentRef = React.useRef(null);
79
83
  const innerModal = React.useRef(null);
80
84
  const startTrap = React.useRef(null);
81
85
  const endTrap = React.useRef(null);
86
+ const [isScrollable, setIsScrollable] = React.useState(false);
82
87
  const modalInstanceId = `modal-${getInstanceId()}`;
83
88
  const modalLabelId = `${prefix}--modal-header__label--${modalInstanceId}`;
84
89
  const modalHeadingId = `${prefix}--modal-header__heading--${modalInstanceId}`;
@@ -144,7 +149,7 @@ const Modal = /*#__PURE__*/React__default["default"].forwardRef(function Modal(_
144
149
  [`${prefix}--modal-container--full-width`]: isFullWidth
145
150
  });
146
151
  const contentClasses = cx__default["default"](`${prefix}--modal-content`, {
147
- [`${prefix}--modal-scroll-content`]: hasScrollingContent
152
+ [`${prefix}--modal-scroll-content`]: hasScrollingContent || isScrollable
148
153
  });
149
154
  const footerClasses = cx__default["default"](`${prefix}--modal-footer`, {
150
155
  [`${prefix}--modal-footer--three-button`]: Array.isArray(secondaryButtons) && secondaryButtons.length === 2
@@ -156,7 +161,7 @@ const Modal = /*#__PURE__*/React__default["default"].forwardRef(function Modal(_
156
161
  const modalHeadingStr = asStringOrUndefined(modalHeading);
157
162
  const ariaLabel = modalLabelStr || ariaLabelProp || modalAriaLabel || modalHeadingStr;
158
163
  const getAriaLabelledBy = modalLabel ? modalLabelId : modalHeadingId;
159
- const hasScrollingContentProps = hasScrollingContent ? {
164
+ const hasScrollingContentProps = hasScrollingContent || isScrollable ? {
160
165
  tabIndex: 0,
161
166
  role: 'region',
162
167
  'aria-label': ariaLabel,
@@ -204,6 +209,22 @@ const Modal = /*#__PURE__*/React__default["default"].forwardRef(function Modal(_
204
209
  focusButton(innerModal.current);
205
210
  }
206
211
  }, [open, selectorPrimaryFocus, danger, prefix]);
212
+ useIsomorphicEffect["default"](() => {
213
+ if (contentRef.current) {
214
+ setIsScrollable(contentRef.current.scrollHeight > contentRef.current.clientHeight);
215
+ }
216
+ function handler() {
217
+ if (contentRef.current) {
218
+ setIsScrollable(contentRef.current.scrollHeight > contentRef.current.clientHeight);
219
+ }
220
+ }
221
+ const debouncedHandler = debounce__default["default"](handler, 200);
222
+ window.addEventListener('resize', debouncedHandler);
223
+ return () => {
224
+ debouncedHandler.cancel();
225
+ window.removeEventListener('resize', debouncedHandler);
226
+ };
227
+ }, []);
207
228
 
208
229
  // Slug is always size `lg`
209
230
  let normalizedSlug;
@@ -247,11 +268,10 @@ const Modal = /*#__PURE__*/React__default["default"].forwardRef(function Modal(_
247
268
  id: modalHeadingId,
248
269
  className: `${prefix}--modal-header__heading`
249
270
  }, modalHeading), normalizedSlug, !passiveModal && modalButton), /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
271
+ ref: contentRef,
250
272
  id: modalBodyId,
251
273
  className: contentClasses
252
- }, hasScrollingContentProps), children), hasScrollingContent && /*#__PURE__*/React__default["default"].createElement("div", {
253
- className: `${prefix}--modal-content--overflow-indicator`
254
- }), !passiveModal && /*#__PURE__*/React__default["default"].createElement(ButtonSet["default"], {
274
+ }, hasScrollingContentProps), children), !passiveModal && /*#__PURE__*/React__default["default"].createElement(ButtonSet["default"], {
255
275
  className: footerClasses,
256
276
  "aria-busy": loadingActive
257
277
  }, Array.isArray(secondaryButtons) && secondaryButtons.length <= 2 ? secondaryButtons.map((_ref3, i) => {
@@ -51,6 +51,10 @@ interface MultiSelectSortingProps<ItemType> {
51
51
  }
52
52
  export interface MultiSelectProps<ItemType> extends MultiSelectSortingProps<ItemType>, InternationalProps<'close.menu' | 'open.menu' | 'clear.all' | 'clear.selection'> {
53
53
  className?: string;
54
+ /**
55
+ * Specify the text that should be read for screen readers that describes that all items are deleted
56
+ */
57
+ clearAnnouncement?: string;
54
58
  /**
55
59
  * Specify the text that should be read for screen readers that describes total items selected
56
60
  */
@@ -82,6 +82,7 @@ const MultiSelect = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref
82
82
  sortItems = sorting.defaultSortItems,
83
83
  compareItems = sorting.defaultCompareItems,
84
84
  clearSelectionText = 'To clear selection, press Delete or Backspace',
85
+ clearAnnouncement = 'all items have been cleared',
85
86
  clearSelectionDescription = 'Total items selected: ',
86
87
  light,
87
88
  invalid,
@@ -113,6 +114,7 @@ const MultiSelect = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref
113
114
  const [isOpen, setIsOpen] = React.useState(open || false);
114
115
  const [prevOpenProp, setPrevOpenProp] = React.useState(open);
115
116
  const [topItems, setTopItems] = React.useState([]);
117
+ const [itemsCleared, setItemsCleared] = React.useState(false);
116
118
  const {
117
119
  selectedItems: controlledSelectedItems,
118
120
  onItemChange,
@@ -159,7 +161,11 @@ const MultiSelect = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref
159
161
  clearSelection();
160
162
  e.stopPropagation();
161
163
  }
164
+ if (!isOpen && match.match(e, keys.Delete) && selectedItems.length > 0) {
165
+ setItemsCleared(true);
166
+ }
162
167
  if ((match.match(e, keys.Space) || match.match(e, keys.ArrowDown) || match.match(e, keys.Enter)) && !isOpen) {
168
+ setItemsCleared(false);
163
169
  setIsOpenWrapper(true);
164
170
  }
165
171
  }
@@ -394,7 +400,10 @@ const MultiSelect = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref
394
400
  }, itemToElement ? /*#__PURE__*/React__default["default"].createElement(ItemToElement, _rollupPluginBabelHelpers["extends"]({
395
401
  key: itemProps.id
396
402
  }, item)) : itemText)));
397
- }))), !inline && !invalid && !warn && helperText && /*#__PURE__*/React__default["default"].createElement("div", {
403
+ })), itemsCleared && /*#__PURE__*/React__default["default"].createElement("span", {
404
+ "aria-live": "assertive",
405
+ "aria-label": clearAnnouncement
406
+ })), !inline && !invalid && !warn && helperText && /*#__PURE__*/React__default["default"].createElement("div", {
398
407
  id: helperId,
399
408
  className: helperClasses
400
409
  }, helperText));
@@ -140,7 +140,7 @@ const NumberInput = /*#__PURE__*/React__default["default"].forwardRef(function N
140
140
  return;
141
141
  }
142
142
  const state = {
143
- value: event.target.value,
143
+ value: Number(event.target.value),
144
144
  direction: value < event.target.value ? 'up' : 'down'
145
145
  };
146
146
  setValue(state.value);
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright IBM Corp. 2020
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 React from 'react';
8
+ interface PaginationNavProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {
9
+ /**
10
+ * Additional CSS class names.
11
+ */
12
+ className?: string;
13
+ /**
14
+ * If true, the '...' pagination overflow will not render page links between the first and last rendered buttons.
15
+ * Set this to true if you are having performance problems with large data sets.
16
+ */
17
+ disableOverflow?: boolean;
18
+ /**
19
+ * The number of items to be shown.
20
+ */
21
+ itemsShown?: number;
22
+ /**
23
+ * Whether user should be able to loop through the items when reaching first / last.
24
+ */
25
+ loop?: boolean;
26
+ /**
27
+ * The callback function called when the current page changes.
28
+ */
29
+ onChange?: (data: number) => void;
30
+ /**
31
+ * The index of current page.
32
+ */
33
+ page?: number;
34
+ /**
35
+ * The total number of items.
36
+ */
37
+ totalItems?: number;
38
+ /**
39
+ * Specify a custom translation function that takes in a message identifier
40
+ * and returns the localized string for the message
41
+ */
42
+ translateWithId?: (id: string) => string;
43
+ }
44
+ declare const PaginationNav: React.ForwardRefExoticComponent<PaginationNavProps & React.RefAttributes<HTMLElement>>;
45
+ export default PaginationNav;
@@ -37,23 +37,23 @@ function translateWithId(messageId) {
37
37
 
38
38
  // https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state
39
39
  function usePrevious(value) {
40
- const ref = React.useRef();
40
+ const ref = React.useRef(null);
41
41
  React.useEffect(() => {
42
42
  ref.current = value;
43
43
  });
44
44
  return ref.current;
45
45
  }
46
- function getCuts(page, totalItems, itemsThatFit) {
46
+ function calculateCuts(page, totalItems, itemsDisplayedOnPage) {
47
47
  let splitPoint = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
48
- if (itemsThatFit >= totalItems) {
48
+ if (itemsDisplayedOnPage >= totalItems) {
49
49
  return {
50
50
  front: 0,
51
51
  back: 0
52
52
  };
53
53
  }
54
- const split = splitPoint || Math.ceil(itemsThatFit / 2) - 1;
54
+ const split = splitPoint || Math.ceil(itemsDisplayedOnPage / 2) - 1;
55
55
  let frontHidden = page + 1 - split;
56
- let backHidden = totalItems - page - (itemsThatFit - split) + 1;
56
+ let backHidden = totalItems - page - (itemsDisplayedOnPage - split) + 1;
57
57
  if (frontHidden <= 1) {
58
58
  backHidden -= frontHidden <= 0 ? Math.abs(frontHidden) + 1 : 0;
59
59
  frontHidden = 0;
@@ -103,15 +103,15 @@ function PaginationItem(_ref2) {
103
103
  }),
104
104
  onClick: onClick,
105
105
  "data-page": page,
106
- "aria-current": isActive ? 'page' : null
106
+ "aria-current": isActive ? 'page' : undefined
107
107
  }, /*#__PURE__*/React__default["default"].createElement("span", {
108
108
  className: `${prefix}--pagination-nav__accessibility-label`
109
109
  }, isActive ? `${t('carbon.pagination-nav.active')}, ${itemLabel}` : itemLabel), page));
110
110
  }
111
111
  function PaginationOverflow(_ref3) {
112
112
  let {
113
- fromIndex,
114
- count,
113
+ fromIndex = NaN,
114
+ count = NaN,
115
115
  onSelect,
116
116
  // eslint-disable-next-line react/prop-types
117
117
  disableOverflow,
@@ -145,7 +145,7 @@ function PaginationOverflow(_ref3) {
145
145
  "aria-label": `Select ${t('carbon.pagination-nav.item')} number`,
146
146
  onChange: e => {
147
147
  const index = Number(e.target.value);
148
- onSelect(index);
148
+ onSelect?.(index);
149
149
  }
150
150
  }, _option || (_option = /*#__PURE__*/React__default["default"].createElement("option", {
151
151
  value: "",
@@ -165,7 +165,7 @@ function PaginationOverflow(_ref3) {
165
165
  page: fromIndex + 1,
166
166
  translateWithId: t,
167
167
  onClick: () => {
168
- onSelect(fromIndex);
168
+ onSelect?.(fromIndex);
169
169
  }
170
170
  });
171
171
  }
@@ -175,7 +175,7 @@ const PaginationNav = /*#__PURE__*/React__default["default"].forwardRef(function
175
175
  let {
176
176
  className,
177
177
  onChange = () => {},
178
- totalItems,
178
+ totalItems = NaN,
179
179
  disableOverflow,
180
180
  itemsShown = 10,
181
181
  page = 0,
@@ -184,8 +184,8 @@ const PaginationNav = /*#__PURE__*/React__default["default"].forwardRef(function
184
184
  ...rest
185
185
  } = _ref4;
186
186
  const [currentPage, setCurrentPage] = React.useState(page);
187
- const [itemsThatFit, setItemsThatFit] = React.useState(itemsShown >= 4 ? itemsShown : 4);
188
- const [cuts, setCuts] = React.useState(getCuts(currentPage, totalItems, itemsThatFit));
187
+ const [itemsDisplayedOnPage, setItemsDisplayedOnPage] = React.useState(itemsShown >= 4 ? itemsShown : 4);
188
+ const [cuts, setCuts] = React.useState(calculateCuts(currentPage, totalItems, itemsDisplayedOnPage));
189
189
  const prevPage = usePrevious(currentPage);
190
190
  const prefix = usePrefix.usePrefix();
191
191
  const [isOverflowDisabled, setIsOverFlowDisabled] = React.useState(disableOverflow);
@@ -216,7 +216,7 @@ const PaginationNav = /*#__PURE__*/React__default["default"].forwardRef(function
216
216
  }
217
217
  }
218
218
  function pageWouldBeHidden(page) {
219
- const startOffset = itemsThatFit <= 4 && page > 1 ? 0 : 1;
219
+ const startOffset = itemsDisplayedOnPage <= 4 && page > 1 ? 0 : 1;
220
220
  const wouldBeHiddenInFront = page >= startOffset && page <= cuts.front;
221
221
  const wouldBeHiddenInBack = page >= totalItems - cuts.back - 1 && page <= totalItems - 2;
222
222
  return wouldBeHiddenInFront || wouldBeHiddenInBack;
@@ -229,20 +229,20 @@ const PaginationNav = /*#__PURE__*/React__default["default"].forwardRef(function
229
229
 
230
230
  // re-calculate cuts if props.totalItems or props.itemsShown change
231
231
  React.useEffect(() => {
232
- setItemsThatFit(itemsShown >= 4 ? itemsShown : 4);
233
- setCuts(getCuts(currentPage, totalItems, itemsShown));
232
+ setItemsDisplayedOnPage(itemsShown >= 4 ? itemsShown : 4);
233
+ setCuts(calculateCuts(currentPage, totalItems, itemsShown));
234
234
  }, [totalItems, itemsShown]); // eslint-disable-line react-hooks/exhaustive-deps
235
235
 
236
236
  // update cuts if necessary whenever currentPage changes
237
237
  React.useEffect(() => {
238
238
  if (pageWouldBeHidden(currentPage)) {
239
- const delta = currentPage - prevPage || 0;
239
+ const delta = currentPage - (prevPage || 0);
240
240
  if (delta > 0) {
241
- const splitPoint = itemsThatFit - 3;
242
- setCuts(getCuts(currentPage, totalItems, itemsThatFit, splitPoint));
241
+ const splitPoint = itemsDisplayedOnPage - 3;
242
+ setCuts(calculateCuts(currentPage, totalItems, itemsDisplayedOnPage, splitPoint));
243
243
  } else {
244
- const splitPoint = itemsThatFit > 4 ? 2 : 1;
245
- setCuts(getCuts(currentPage, totalItems, itemsThatFit, splitPoint));
244
+ const splitPoint = itemsDisplayedOnPage > 4 ? 2 : 1;
245
+ setCuts(calculateCuts(currentPage, totalItems, itemsDisplayedOnPage, splitPoint));
246
246
  }
247
247
  }
248
248
  }, [currentPage]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -253,7 +253,7 @@ const PaginationNav = /*#__PURE__*/React__default["default"].forwardRef(function
253
253
  const classNames = cx__default["default"](`${prefix}--pagination-nav`, className);
254
254
  const backwardButtonDisabled = !loop && currentPage === 0;
255
255
  const forwardButtonDisabled = !loop && currentPage === totalItems - 1;
256
- const startOffset = itemsThatFit <= 4 && currentPage > 1 ? 0 : 1;
256
+ const startOffset = itemsDisplayedOnPage <= 4 && currentPage > 1 ? 0 : 1;
257
257
  return /*#__PURE__*/React__default["default"].createElement("nav", _rollupPluginBabelHelpers["extends"]({
258
258
  className: classNames,
259
259
  ref: ref
@@ -269,7 +269,7 @@ const PaginationNav = /*#__PURE__*/React__default["default"].forwardRef(function
269
269
  }),
270
270
  // render first item if at least 5 items can be displayed or
271
271
  // 4 items can be displayed and the current page is either 0 or 1
272
- (itemsThatFit >= 5 || itemsThatFit <= 4 && currentPage <= 1) && /*#__PURE__*/React__default["default"].createElement(PaginationItem, {
272
+ (itemsDisplayedOnPage >= 5 || itemsDisplayedOnPage <= 4 && currentPage <= 1) && /*#__PURE__*/React__default["default"].createElement(PaginationItem, {
273
273
  page: 1,
274
274
  translateWithId: t,
275
275
  isActive: currentPage === 0,
@@ -411,6 +411,5 @@ PaginationNav.propTypes = {
411
411
  */
412
412
  translateWithId: PropTypes__default["default"].func
413
413
  };
414
- var PaginationNav$1 = PaginationNav;
415
414
 
416
- exports["default"] = PaginationNav$1;
415
+ exports["default"] = PaginationNav;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright IBM Corp. 2020
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 PaginationNav from './PaginationNav';
8
+ export default PaginationNav;
9
+ export { PaginationNav };
@@ -239,7 +239,8 @@ function TabList(_ref2) {
239
239
  function onKeyDown(event) {
240
240
  if (match.matches(event, [keys.ArrowRight, keys.ArrowLeft, keys.Home, keys.End])) {
241
241
  event.preventDefault();
242
- const activeTabs = tabs.current.filter(tab => !tab.disabled);
242
+ const filtredTabs = tabs.current.filter(tab => tab !== null);
243
+ const activeTabs = filtredTabs.filter(tab => !tab.disabled);
243
244
  const currentIndex = activeTabs.indexOf(tabs.current[activation === 'automatic' ? selectedIndex : activeIndex]);
244
245
  const nextIndex = tabs.current.indexOf(activeTabs[getNextIndex(event, activeTabs.length, currentIndex)]);
245
246
  if (activation === 'automatic') {