@carbon/react 1.32.0 → 1.33.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 (86) hide show
  1. package/README.md +22 -7
  2. package/es/components/ComboBox/ComboBox.js +43 -10
  3. package/es/components/ContentSwitcher/ContentSwitcher.js +5 -5
  4. package/es/components/DataTable/DataTable.js +110 -130
  5. package/es/components/DataTable/Table.js +1 -1
  6. package/es/components/DataTableSkeleton/DataTableSkeleton.d.ts +17 -16
  7. package/es/components/DatePicker/DatePicker.d.ts +14 -13
  8. package/es/components/DatePicker/DatePicker.js +3 -0
  9. package/es/components/DatePickerInput/DatePickerInput.d.ts +2 -2
  10. package/es/components/Dropdown/Dropdown.js +31 -6
  11. package/es/components/FileUploader/FileUploader.Skeleton.d.ts +29 -0
  12. package/es/components/FileUploader/FileUploader.d.ts +175 -0
  13. package/es/components/FileUploader/FileUploader.js +3 -3
  14. package/es/components/FileUploader/FileUploaderButton.d.ts +140 -0
  15. package/es/components/FileUploader/FileUploaderButton.js +11 -7
  16. package/es/components/FileUploader/FileUploaderDropContainer.d.ts +139 -0
  17. package/es/components/FileUploader/FileUploaderDropContainer.js +3 -3
  18. package/es/components/FileUploader/FileUploaderItem.d.ts +110 -0
  19. package/es/components/FileUploader/Filename.d.ts +71 -0
  20. package/es/components/FileUploader/Filename.js +6 -4
  21. package/es/components/InlineCheckbox/InlineCheckbox.js +3 -1
  22. package/es/components/Loading/Loading.d.ts +65 -0
  23. package/es/components/Notification/Notification.d.ts +4 -4
  24. package/es/components/Notification/Notification.js +3 -3
  25. package/es/components/OverflowMenu/OverflowMenu.js +36 -41
  26. package/es/components/Slider/Slider.js +59 -68
  27. package/es/components/Tag/Tag.js +9 -2
  28. package/es/components/TextArea/TextArea.js +1 -1
  29. package/es/components/Toggle/Toggle.d.ts +129 -0
  30. package/es/components/Toggle/Toggle.js +2 -2
  31. package/es/components/Toggle/index.d.ts +11 -0
  32. package/es/components/UIShell/HeaderMenu.js +29 -36
  33. package/es/components/UIShell/HeaderMenuButton.d.ts +4 -0
  34. package/es/components/UIShell/HeaderMenuButton.js +4 -0
  35. package/es/components/UIShell/HeaderName.d.ts +39 -0
  36. package/es/components/UIShell/HeaderName.js +2 -7
  37. package/es/components/UIShell/HeaderPanel.js +2 -2
  38. package/es/components/UIShell/Link.js +2 -1
  39. package/es/components/UIShell/Switcher.js +17 -6
  40. package/es/index.js +1 -1
  41. package/es/internal/FloatingMenu.js +47 -51
  42. package/es/internal/useControllableState.js +1 -1
  43. package/es/internal/useId.js +10 -1
  44. package/lib/components/ComboBox/ComboBox.js +43 -10
  45. package/lib/components/ContentSwitcher/ContentSwitcher.js +5 -5
  46. package/lib/components/DataTable/DataTable.js +110 -130
  47. package/lib/components/DataTable/Table.js +1 -1
  48. package/lib/components/DataTableSkeleton/DataTableSkeleton.d.ts +17 -16
  49. package/lib/components/DatePicker/DatePicker.d.ts +14 -13
  50. package/lib/components/DatePicker/DatePicker.js +3 -0
  51. package/lib/components/DatePickerInput/DatePickerInput.d.ts +2 -2
  52. package/lib/components/Dropdown/Dropdown.js +30 -5
  53. package/lib/components/FileUploader/FileUploader.Skeleton.d.ts +29 -0
  54. package/lib/components/FileUploader/FileUploader.d.ts +175 -0
  55. package/lib/components/FileUploader/FileUploader.js +3 -3
  56. package/lib/components/FileUploader/FileUploaderButton.d.ts +140 -0
  57. package/lib/components/FileUploader/FileUploaderButton.js +11 -7
  58. package/lib/components/FileUploader/FileUploaderDropContainer.d.ts +139 -0
  59. package/lib/components/FileUploader/FileUploaderDropContainer.js +3 -3
  60. package/lib/components/FileUploader/FileUploaderItem.d.ts +110 -0
  61. package/lib/components/FileUploader/Filename.d.ts +71 -0
  62. package/lib/components/FileUploader/Filename.js +6 -4
  63. package/lib/components/InlineCheckbox/InlineCheckbox.js +3 -1
  64. package/lib/components/Loading/Loading.d.ts +65 -0
  65. package/lib/components/Notification/Notification.d.ts +4 -4
  66. package/lib/components/Notification/Notification.js +3 -3
  67. package/lib/components/OverflowMenu/OverflowMenu.js +36 -41
  68. package/lib/components/Slider/Slider.js +59 -68
  69. package/lib/components/Tag/Tag.js +9 -2
  70. package/lib/components/TextArea/TextArea.js +1 -1
  71. package/lib/components/Toggle/Toggle.d.ts +129 -0
  72. package/lib/components/Toggle/Toggle.js +2 -2
  73. package/lib/components/Toggle/index.d.ts +11 -0
  74. package/lib/components/UIShell/HeaderMenu.js +29 -36
  75. package/lib/components/UIShell/HeaderMenuButton.d.ts +4 -0
  76. package/lib/components/UIShell/HeaderMenuButton.js +4 -0
  77. package/lib/components/UIShell/HeaderName.d.ts +39 -0
  78. package/lib/components/UIShell/HeaderName.js +2 -7
  79. package/lib/components/UIShell/HeaderPanel.js +2 -2
  80. package/lib/components/UIShell/Link.js +2 -1
  81. package/lib/components/UIShell/Switcher.js +17 -6
  82. package/lib/index.js +2 -2
  83. package/lib/internal/FloatingMenu.js +47 -51
  84. package/lib/internal/useControllableState.js +1 -1
  85. package/lib/internal/useId.js +9 -0
  86. package/package.json +22 -19
@@ -42,7 +42,7 @@ interface DatePickerInputProps extends Omit<ReactAttr<HTMLDivElement>, ExcludedA
42
42
  /**
43
43
  * Specify the text to be rendered when the input is invalid
44
44
  */
45
- invalidText: ReactNodeLike;
45
+ invalidText?: ReactNodeLike;
46
46
  /**
47
47
  * Provide the text that will be read by a screen reader when visiting this
48
48
  * control
@@ -61,7 +61,7 @@ interface DatePickerInputProps extends Omit<ReactAttr<HTMLDivElement>, ExcludedA
61
61
  * Provide a regular expression that the input value must match
62
62
  * TODO:need to be rewritten
63
63
  */
64
- pattern: (props: {
64
+ pattern?: (props: {
65
65
  [key: string]: any;
66
66
  }, propName: string, componentName: string) => null | any | Error;
67
67
  /**
@@ -31,6 +31,13 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
31
31
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
32
32
 
33
33
  const getInstanceId = setupGetInstanceId["default"]();
34
+ const {
35
+ MenuBlur,
36
+ MenuKeyDownArrowDown,
37
+ MenuKeyDownArrowUp,
38
+ MenuKeyDownEscape,
39
+ ToggleButtonClick
40
+ } = Downshift.useSelect.stateChangeTypes;
34
41
  const defaultItemToString = item => {
35
42
  if (typeof item === 'string') {
36
43
  return item;
@@ -75,6 +82,7 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
75
82
  ...other
76
83
  } = _ref;
77
84
  const prefix = usePrefix.usePrefix();
85
+ const [highlightedIndex, setHighlightedIndex] = React.useState();
78
86
  const {
79
87
  isFluid
80
88
  } = React.useContext(FormContext.FormContext);
@@ -82,12 +90,32 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
82
90
  ...downshiftProps,
83
91
  items,
84
92
  itemToString,
93
+ highlightedIndex,
85
94
  initialSelectedItem,
86
- onSelectedItemChange
95
+ onSelectedItemChange,
96
+ onStateChange
87
97
  };
88
98
  const {
89
99
  current: dropdownInstanceId
90
100
  } = React.useRef(getInstanceId());
101
+ function onStateChange(changes) {
102
+ const {
103
+ type
104
+ } = changes;
105
+ switch (type) {
106
+ case MenuKeyDownArrowDown:
107
+ case MenuKeyDownArrowUp:
108
+ setHighlightedIndex(changes.highlightedIndex);
109
+ break;
110
+ case MenuBlur:
111
+ case MenuKeyDownEscape:
112
+ setHighlightedIndex(changes.highlightedIndex);
113
+ break;
114
+ case ToggleButtonClick:
115
+ setHighlightedIndex(changes.highlightedIndex);
116
+ break;
117
+ }
118
+ }
91
119
 
92
120
  // only set selectedItem if the prop is defined. Setting if it is undefined
93
121
  // will overwrite default selected items from useSelect
@@ -100,7 +128,6 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
100
128
  getLabelProps,
101
129
  getMenuProps,
102
130
  getItemProps,
103
- highlightedIndex,
104
131
  selectedItem
105
132
  } = Downshift.useSelect(selectProps);
106
133
  const inline = type === 'inline';
@@ -179,12 +206,10 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
179
206
  }
180
207
  } : {
181
208
  onKeyDown: evt => {
182
- console.log('typing should be false', isTyping);
183
209
  if (evt.code !== 'Space' || !['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(evt.key)) {
184
210
  setIsTyping(true);
185
211
  }
186
212
  if (isTyping && evt.code === 'Space' || !['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(evt.key)) {
187
- console.log(evt.key);
188
213
  if (evt.code === 'Space') {
189
214
  evt.preventDefault();
190
215
  return;
@@ -254,7 +279,7 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
254
279
  return /*#__PURE__*/React__default["default"].createElement(index["default"].MenuItem, _rollupPluginBabelHelpers["extends"]({
255
280
  key: itemProps.id,
256
281
  isActive: selectedItem === item,
257
- isHighlighted: highlightedIndex === index$1 || selectedItem === item,
282
+ isHighlighted: highlightedIndex === index$1,
258
283
  title: title,
259
284
  ref: {
260
285
  menuItemOptionRef: menuItemOptionRefs.current[index$1]
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
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
+ /// <reference types="react" />
8
+ import PropTypes from 'prop-types';
9
+ import { ReactAttr } from '../../types/common';
10
+ export interface FileUploaderSkeletonProps extends ReactAttr<HTMLDivElement> {
11
+ /**
12
+ * Specify an optional className to add.
13
+ */
14
+ className?: string;
15
+ }
16
+ declare function FileUploaderSkeleton({ className, ...rest }: {
17
+ [x: string]: any;
18
+ className: any;
19
+ }): JSX.Element;
20
+ declare namespace FileUploaderSkeleton {
21
+ var propTypes: {
22
+ /**
23
+ * Specify an optional className to add.
24
+ */
25
+ className: PropTypes.Requireable<string>;
26
+ };
27
+ }
28
+ export default FileUploaderSkeleton;
29
+ export { FileUploaderSkeleton };
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
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 PropTypes from 'prop-types';
8
+ import React from 'react';
9
+ import { ReactAttr } from '../../types/common';
10
+ export interface FileUploaderProps extends ReactAttr<HTMLSpanElement> {
11
+ /**
12
+ * Specify the types of files that this input should be able to receive
13
+ */
14
+ accept?: string[];
15
+ /**
16
+ * Specify the type of the `<FileUploaderButton>`
17
+ */
18
+ buttonKind?: 'primary' | 'secondary' | 'danger' | 'ghost' | 'danger--primary' | 'danger--ghost' | 'danger--tertiary' | 'tertiary';
19
+ /**
20
+ * Provide the label text to be read by screen readers when interacting with
21
+ * the `<FileUploaderButton>`
22
+ */
23
+ buttonLabel?: string;
24
+ /**
25
+ * Provide a custom className to be applied to the container node
26
+ */
27
+ className?: string;
28
+ /**
29
+ * Specify whether file input is disabled
30
+ */
31
+ disabled?: boolean;
32
+ /**
33
+ * Specify the status of the File Upload
34
+ */
35
+ filenameStatus: 'edit' | 'complete' | 'uploading';
36
+ /**
37
+ * Provide a description for the complete/close icon that can be read by screen readers
38
+ */
39
+ iconDescription: string;
40
+ /**
41
+ * Specify the description text of this `<FileUploader>`
42
+ */
43
+ labelDescription?: string;
44
+ /**
45
+ * Specify the title text of this `<FileUploader>`
46
+ */
47
+ labelTitle?: string;
48
+ /**
49
+ * Specify if the component should accept multiple files to upload
50
+ */
51
+ multiple?: boolean;
52
+ /**
53
+ * Provide a name for the underlying `<input>` node
54
+ */
55
+ name?: string;
56
+ /**
57
+ * Provide an optional `onChange` hook that is called each time the input is
58
+ * changed
59
+ */
60
+ onChange?: (event: any) => void;
61
+ /**
62
+ * Provide an optional `onClick` hook that is called each time the
63
+ * FileUploader is clicked
64
+ */
65
+ onClick?: (event: any) => void;
66
+ /**
67
+ * Provide an optional `onDelete` hook that is called when an uploaded item
68
+ * is removed
69
+ */
70
+ onDelete?: (event: any) => void;
71
+ /**
72
+ * Specify the size of the FileUploaderButton, from a list of available
73
+ * sizes.
74
+ */
75
+ size?: 'sm' | 'small' | 'md' | 'field' | 'lg';
76
+ }
77
+ export default class FileUploader extends React.Component<FileUploaderProps, {
78
+ filenames: string[];
79
+ }> {
80
+ static propTypes: {
81
+ /**
82
+ * Specify the types of files that this input should be able to receive
83
+ */
84
+ accept: PropTypes.Requireable<(string | null | undefined)[]>;
85
+ /**
86
+ * Specify the type of the `<FileUploaderButton>`
87
+ */
88
+ buttonKind: PropTypes.Requireable<string>;
89
+ /**
90
+ * Provide the label text to be read by screen readers when interacting with
91
+ * the `<FileUploaderButton>`
92
+ */
93
+ buttonLabel: PropTypes.Requireable<string>;
94
+ /**
95
+ * Provide a custom className to be applied to the container node
96
+ */
97
+ className: PropTypes.Requireable<string>;
98
+ /**
99
+ * Specify whether file input is disabled
100
+ */
101
+ disabled: PropTypes.Requireable<boolean>;
102
+ /**
103
+ * Specify the status of the File Upload
104
+ */
105
+ filenameStatus: PropTypes.Validator<string>;
106
+ /**
107
+ * Provide a description for the complete/close icon that can be read by screen readers
108
+ */
109
+ iconDescription: PropTypes.Validator<string>;
110
+ /**
111
+ * Specify the description text of this `<FileUploader>`
112
+ */
113
+ labelDescription: PropTypes.Requireable<string>;
114
+ /**
115
+ * Specify the title text of this `<FileUploader>`
116
+ */
117
+ labelTitle: PropTypes.Requireable<string>;
118
+ /**
119
+ * Specify if the component should accept multiple files to upload
120
+ */
121
+ multiple: PropTypes.Requireable<boolean>;
122
+ /**
123
+ * Provide a name for the underlying `<input>` node
124
+ */
125
+ name: PropTypes.Requireable<string>;
126
+ /**
127
+ * Provide an optional `onChange` hook that is called each time the input is
128
+ * changed
129
+ */
130
+ onChange: PropTypes.Requireable<(...args: any[]) => any>;
131
+ /**
132
+ * Provide an optional `onClick` hook that is called each time the
133
+ * FileUploader is clicked
134
+ */
135
+ onClick: PropTypes.Requireable<(...args: any[]) => any>;
136
+ /**
137
+ * Provide an optional `onDelete` hook that is called when an uploaded item
138
+ * is removed
139
+ */
140
+ onDelete: PropTypes.Requireable<(...args: any[]) => any>;
141
+ /**
142
+ * Specify the size of the FileUploaderButton, from a list of available
143
+ * sizes.
144
+ */
145
+ size: PropTypes.Requireable<string>;
146
+ };
147
+ static contextType: React.Context<string>;
148
+ static defaultProps: {
149
+ disabled: boolean;
150
+ filenameStatus: string;
151
+ buttonLabel: string;
152
+ buttonKind: string;
153
+ multiple: boolean;
154
+ onClick: () => void;
155
+ accept: never[];
156
+ };
157
+ state: {
158
+ filenames: string[];
159
+ };
160
+ nodes: HTMLElement[];
161
+ uploaderButton: React.RefObject<HTMLLabelElement>;
162
+ static getDerivedStateFromProps({ filenameStatus }: {
163
+ filenameStatus: any;
164
+ }, state: any): {
165
+ filenameStatus: any;
166
+ prevFilenameStatus: any;
167
+ } | null;
168
+ handleChange: (evt: any) => void;
169
+ handleClick: (evt: any, { index, filenameStatus }: {
170
+ index: any;
171
+ filenameStatus: any;
172
+ }) => void;
173
+ clearFiles: () => void;
174
+ render(): JSX.Element;
175
+ }
@@ -57,9 +57,9 @@ class FileUploader extends React__default["default"].Component {
57
57
  });
58
58
  if (this.props.onDelete) {
59
59
  this.props.onDelete(evt);
60
- this.uploaderButton.current.focus();
60
+ this.uploaderButton.current?.focus?.();
61
61
  }
62
- this.props.onClick(evt);
62
+ this.props.onClick?.(evt);
63
63
  }
64
64
  });
65
65
  _rollupPluginBabelHelpers.defineProperty(this, "clearFiles", () => {
@@ -96,7 +96,7 @@ class FileUploader extends React__default["default"].Component {
96
96
  name,
97
97
  size = 'md',
98
98
  onDelete,
99
- // eslint-disable-line no-unused-vars
99
+ // eslint-disable-line
100
100
  ...other
101
101
  } = this.props;
102
102
  const prefix = this.context;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
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 PropTypes from 'prop-types';
8
+ import React from 'react';
9
+ import { ReactAttr } from '../../types/common';
10
+ export interface FileUploaderButtonProps extends Omit<ReactAttr<HTMLButtonElement>, 'onChange' | 'tabIndex'> {
11
+ /**
12
+ * Specify the types of files that this input should be able to receive
13
+ */
14
+ accept?: string[];
15
+ /**
16
+ * Specify the type of underlying button
17
+ */
18
+ buttonKind?: 'primary' | 'secondary' | 'danger' | 'ghost' | 'danger--primary' | 'danger--ghost' | 'danger--tertiary' | 'tertiary';
19
+ /**
20
+ * Provide a custom className to be applied to the container node
21
+ */
22
+ className?: string;
23
+ /**
24
+ * Specify whether you want to disable any updates to the FileUploaderButton
25
+ * label
26
+ */
27
+ disableLabelChanges?: boolean;
28
+ /**
29
+ * Specify whether file input is disabled
30
+ */
31
+ disabled?: boolean;
32
+ /**
33
+ * Provide a unique id for the underlying `<input>` node
34
+ */
35
+ id?: string;
36
+ /**
37
+ * Provide the label text to be read by screen readers when interacting with
38
+ * this control
39
+ */
40
+ labelText?: React.ReactNode;
41
+ /**
42
+ * Specify if the component should accept multiple files to upload
43
+ */
44
+ multiple?: boolean;
45
+ /**
46
+ * Provide a name for the underlying `<input>` node
47
+ */
48
+ name?: string;
49
+ /**
50
+ * Provide an optional `onChange` hook that is called each time the `<input>`
51
+ * value changes
52
+ */
53
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
54
+ /**
55
+ * Provide an optional `onClick` hook that is called each time the button is
56
+ * clicked
57
+ */
58
+ onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
59
+ /**
60
+ * Provide an accessibility role for the `<FileUploaderButton>`
61
+ */
62
+ role?: string;
63
+ /**
64
+ * Specify the size of the FileUploaderButton, from a list of available
65
+ * sizes.
66
+ */
67
+ size?: 'sm' | 'small' | 'field' | 'md' | 'lg';
68
+ /**
69
+ * @deprecated The `tabIndex` prop for `FileUploaderButton` has been deprecated since it now renders a button element by default.
70
+ */
71
+ tabIndex?: number | string;
72
+ innerRef?: React.RefObject<HTMLLabelElement>;
73
+ }
74
+ declare function FileUploaderButton({ accept, buttonKind, className, disabled, disableLabelChanges, id, labelText: ownerLabelText, multiple, onChange, name, size, innerRef, ...other }: FileUploaderButtonProps): JSX.Element;
75
+ declare namespace FileUploaderButton {
76
+ var propTypes: {
77
+ /**
78
+ * Specify the types of files that this input should be able to receive
79
+ */
80
+ accept: PropTypes.Requireable<(string | null | undefined)[]>;
81
+ /**
82
+ * Specify the type of underlying button
83
+ */
84
+ buttonKind: PropTypes.Requireable<string>;
85
+ /**
86
+ * Provide a custom className to be applied to the container node
87
+ */
88
+ className: PropTypes.Requireable<string>;
89
+ /**
90
+ * Specify whether you want to disable any updates to the FileUploaderButton
91
+ * label
92
+ */
93
+ disableLabelChanges: PropTypes.Requireable<boolean>;
94
+ /**
95
+ * Specify whether file input is disabled
96
+ */
97
+ disabled: PropTypes.Requireable<boolean>;
98
+ /**
99
+ * Provide a unique id for the underlying `<input>` node
100
+ */
101
+ id: PropTypes.Requireable<string>;
102
+ /**
103
+ * Provide the label text to be read by screen readers when interacting with
104
+ * this control
105
+ */
106
+ labelText: PropTypes.Requireable<PropTypes.ReactNodeLike>;
107
+ /**
108
+ * Specify if the component should accept multiple files to upload
109
+ */
110
+ multiple: PropTypes.Requireable<boolean>;
111
+ /**
112
+ * Provide a name for the underlying `<input>` node
113
+ */
114
+ name: PropTypes.Requireable<string>;
115
+ /**
116
+ * Provide an optional `onChange` hook that is called each time the `<input>`
117
+ * value changes
118
+ */
119
+ onChange: PropTypes.Requireable<(...args: any[]) => any>;
120
+ /**
121
+ * Provide an optional `onClick` hook that is called each time the button is
122
+ * clicked
123
+ */
124
+ onClick: PropTypes.Requireable<(...args: any[]) => any>;
125
+ /**
126
+ * Provide an accessibility role for the `<FileUploaderButton>`
127
+ */
128
+ role: PropTypes.Requireable<string>;
129
+ /**
130
+ * Specify the size of the FileUploaderButton, from a list of available
131
+ * sizes.
132
+ */
133
+ size: PropTypes.Requireable<string>;
134
+ /**
135
+ * Provide a custom tabIndex value for the `<FileUploaderButton>`
136
+ */
137
+ tabIndex: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
138
+ };
139
+ }
140
+ export default FileUploaderButton;
@@ -67,18 +67,20 @@ function FileUploaderButton(_ref) {
67
67
  }
68
68
  function onClick(event) {
69
69
  event.target.value = null;
70
- inputNode.current.value = '';
71
- inputNode.current.click();
70
+ if (inputNode.current) {
71
+ inputNode.current.value = '';
72
+ inputNode.current.click();
73
+ }
72
74
  }
73
75
  function onKeyDown(event) {
74
- if (match.matches(event, [keys.Enter, keys.Space])) {
76
+ if (match.matches(event, [keys.Enter, keys.Space]) && inputNode.current) {
75
77
  inputNode.current.value = '';
76
78
  inputNode.current.click();
77
79
  }
78
80
  }
79
81
  function handleOnChange(event) {
80
82
  const files = event.target.files;
81
- const length = event.target.files.length;
83
+ const length = event.target.files?.length || 0;
82
84
  if (files && !disableLabelChanges) {
83
85
  if (length > 1) {
84
86
  setLabelText(`${length} files`);
@@ -94,7 +96,9 @@ function FileUploaderButton(_ref) {
94
96
  className: classes,
95
97
  onClick: onClick,
96
98
  onKeyDown: onKeyDown
97
- }, other), labelText), /*#__PURE__*/React__default["default"].createElement("label", {
99
+ }, other, {
100
+ tabIndex: other.tabIndex !== undefined ? parseInt(other.tabIndex) : undefined
101
+ }), labelText), /*#__PURE__*/React__default["default"].createElement("label", {
98
102
  className: `${prefix}--visually-hidden`,
99
103
  ref: innerRef,
100
104
  htmlFor: inputId
@@ -104,9 +108,9 @@ function FileUploaderButton(_ref) {
104
108
  id: inputId,
105
109
  disabled: disabled,
106
110
  type: "file",
107
- tabIndex: "-1",
111
+ tabIndex: -1,
108
112
  multiple: multiple,
109
- accept: accept,
113
+ accept: accept?.toString(),
110
114
  name: name,
111
115
  onChange: handleOnChange
112
116
  }));
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
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
+ /// <reference types="react" />
8
+ import PropTypes from 'prop-types';
9
+ import { ReactAttr } from '../../types/common';
10
+ export interface FileUploaderDropContainerProps extends Omit<ReactAttr<HTMLButtonElement>, 'tabIndex'> {
11
+ /**
12
+ * Specify the types of files that this input should be able to receive
13
+ */
14
+ accept?: string[];
15
+ /**
16
+ * Provide a custom className to be applied to the container node
17
+ */
18
+ className?: string;
19
+ /**
20
+ * Specify whether file input is disabled
21
+ */
22
+ disabled?: boolean;
23
+ /**
24
+ * Provide a unique id for the underlying `<input>` node
25
+ */
26
+ id?: string;
27
+ /**
28
+ * Provide the label text to be read by screen readers when interacting with
29
+ * this control
30
+ */
31
+ labelText: string;
32
+ /**
33
+ * Specify if the component should accept multiple files to upload
34
+ */
35
+ multiple?: boolean;
36
+ /**
37
+ * Provide a name for the underlying `<input>` node
38
+ */
39
+ name?: string;
40
+ /**
41
+ * Event handler that is called after files are added to the uploader
42
+ * The event handler signature looks like `onAddFiles(evt, { addedFiles })`
43
+ */
44
+ onAddFiles?: () => void;
45
+ /**
46
+ * Provide an optional function to be called when the button element
47
+ * is clicked
48
+ */
49
+ onClick?: () => void;
50
+ /**
51
+ * Provide a custom regex pattern for the acceptedTypes
52
+ */
53
+ pattern?: string;
54
+ /**
55
+ * @deprecated The `role` prop for `FileUploaderButton` has been deprecated since it now renders a button element by default, and has an implicit role of button.
56
+ */
57
+ role?: string;
58
+ /**
59
+ * @deprecated The `tabIndex` prop for `FileUploaderButton` has been deprecated since it now renders a button element by default.
60
+ */
61
+ tabIndex?: number | string;
62
+ }
63
+ declare function FileUploaderDropContainer({ accept, className, id, disabled, labelText, multiple, name, onAddFiles, onClick, pattern, innerRef, ...rest }: {
64
+ [x: string]: any;
65
+ accept: any;
66
+ className: any;
67
+ id: any;
68
+ disabled: any;
69
+ labelText: any;
70
+ multiple: any;
71
+ name: any;
72
+ onAddFiles: any;
73
+ onClick: any;
74
+ pattern: any;
75
+ innerRef: any;
76
+ }): JSX.Element;
77
+ declare namespace FileUploaderDropContainer {
78
+ var propTypes: {
79
+ /**
80
+ * Specify the types of files that this input should be able to receive
81
+ */
82
+ accept: PropTypes.Requireable<(string | null | undefined)[]>;
83
+ /**
84
+ * Provide a custom className to be applied to the container node
85
+ */
86
+ className: PropTypes.Requireable<string>;
87
+ /**
88
+ * Specify whether file input is disabled
89
+ */
90
+ disabled: PropTypes.Requireable<boolean>;
91
+ /**
92
+ * Provide a unique id for the underlying `<input>` node
93
+ */
94
+ id: PropTypes.Requireable<string>;
95
+ /**
96
+ * Provide the label text to be read by screen readers when interacting with
97
+ * this control
98
+ */
99
+ labelText: PropTypes.Validator<string>;
100
+ /**
101
+ * Specify if the component should accept multiple files to upload
102
+ */
103
+ multiple: PropTypes.Requireable<boolean>;
104
+ /**
105
+ * Provide a name for the underlying `<input>` node
106
+ */
107
+ name: PropTypes.Requireable<string>;
108
+ /**
109
+ * Event handler that is called after files are added to the uploader
110
+ * The event handler signature looks like `onAddFiles(evt, { addedFiles })`
111
+ */
112
+ onAddFiles: PropTypes.Requireable<(...args: any[]) => any>;
113
+ /**
114
+ * Provide an optional function to be called when the button element
115
+ * is clicked
116
+ */
117
+ onClick: PropTypes.Requireable<(...args: any[]) => any>;
118
+ /**
119
+ * Provide a custom regex pattern for the acceptedTypes
120
+ */
121
+ pattern: PropTypes.Requireable<string>;
122
+ /**
123
+ * Provide an accessibility role for the `<FileUploaderButton>`
124
+ */
125
+ role: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
126
+ /**
127
+ * Provide a custom tabIndex value for the `<FileUploaderButton>`
128
+ */
129
+ tabIndex: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
130
+ };
131
+ var defaultProps: {
132
+ labelText: string;
133
+ multiple: boolean;
134
+ onAddFiles: () => void;
135
+ accept: never[];
136
+ pattern: string;
137
+ };
138
+ }
139
+ export default FileUploaderDropContainer;
@@ -90,7 +90,7 @@ function FileUploaderDropContainer(_ref) {
90
90
  }
91
91
  const handleClick = () => {
92
92
  if (!disabled) {
93
- inputRef.current.click();
93
+ inputRef.current?.click();
94
94
  }
95
95
  };
96
96
  return /*#__PURE__*/React__default["default"].createElement("div", {
@@ -129,7 +129,7 @@ function FileUploaderDropContainer(_ref) {
129
129
  onKeyDown: evt => {
130
130
  if (match.matches(evt, [keys.Enter, keys.Space])) {
131
131
  evt.preventDefault();
132
- inputRef.current.click();
132
+ inputRef.current?.click();
133
133
  }
134
134
  },
135
135
  onClick: events.composeEventHandlers([onClick, handleClick])
@@ -141,7 +141,7 @@ function FileUploaderDropContainer(_ref) {
141
141
  id: uid,
142
142
  className: `${prefix}--file-input`,
143
143
  ref: inputRef,
144
- tabIndex: "-1",
144
+ tabIndex: -1,
145
145
  disabled: disabled,
146
146
  accept: accept,
147
147
  name: name,