@carbon/react 1.57.0 → 1.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +1106 -990
- package/es/components/Accordion/Accordion.d.ts +1 -1
- package/es/components/Accordion/index.d.ts +2 -2
- package/es/components/Button/Button.js +2 -2
- package/es/components/Button/index.d.ts +2 -1
- package/es/components/Checkbox/Checkbox.d.ts +6 -7
- package/es/components/ComboBox/ComboBox.d.ts +4 -5
- package/es/components/ComboBox/ComboBox.js +268 -261
- package/es/components/ComposedModal/ComposedModal.d.ts +1 -2
- package/es/components/DataTable/TableHeader.d.ts +4 -5
- package/es/components/DataTable/TableSlugRow.d.ts +3 -2
- package/es/components/DatePicker/DatePicker.d.ts +4 -5
- package/es/components/Dropdown/Dropdown.d.ts +6 -7
- package/es/components/Dropdown/index.d.ts +2 -2
- package/es/components/FormLabel/index.d.ts +2 -2
- package/es/components/Grid/Column.d.ts +2 -2
- package/es/components/Grid/GridTypes.d.ts +1 -2
- package/es/components/Grid/index.d.ts +3 -1
- package/es/components/IconButton/index.d.ts +3 -4
- package/es/components/InlineLoading/index.d.ts +2 -2
- package/es/components/ListBox/next/ListBoxTrigger.js +1 -0
- package/es/components/Loading/index.d.ts +2 -2
- package/es/components/Menu/Menu.js +1 -1
- package/es/components/Menu/MenuItem.js +13 -2
- package/es/components/Modal/Modal.d.ts +8 -9
- package/es/components/Modal/index.d.ts +2 -2
- package/es/components/MultiSelect/FilterableMultiSelect.d.ts +1 -2
- package/es/components/MultiSelect/MultiSelect.d.ts +10 -9
- package/es/components/Notification/Notification.d.ts +2 -2
- package/es/components/NumberInput/NumberInput.d.ts +12 -2
- package/es/components/NumberInput/NumberInput.js +2 -2
- package/es/components/NumberInput/index.d.ts +1 -1
- package/es/components/OverflowMenu/OverflowMenu.d.ts +10 -6
- package/es/components/OverflowMenu/index.d.ts +13 -0
- package/es/components/PasswordInput/index.d.ts +3 -0
- package/es/components/Popover/index.d.ts +8 -2
- package/es/components/Popover/index.js +26 -1
- package/es/components/ProgressBar/ProgressBar.d.ts +1 -1
- package/es/components/ProgressBar/index.d.ts +2 -2
- package/es/components/ProgressIndicator/ProgressIndicator.d.ts +2 -2
- package/es/components/ProgressIndicator/index.d.ts +2 -0
- package/es/components/RadioButton/RadioButton.d.ts +3 -4
- package/es/components/RadioButtonGroup/RadioButtonGroup.d.ts +7 -8
- package/es/components/Select/Select.d.ts +1 -2
- package/es/components/Slider/Slider.d.ts +5 -5
- package/es/components/Slider/Slider.js +1 -1
- package/es/components/StructuredList/index.d.ts +2 -0
- package/es/components/Switch/Switch.d.ts +1 -1
- package/es/components/Switch/index.d.ts +2 -2
- package/es/components/Tab/index.d.ts +2 -1
- package/es/components/Tag/DismissibleTag.d.ts +12 -12
- package/es/components/Tag/DismissibleTag.js +34 -9
- package/es/components/Tag/OperationalTag.d.ts +12 -12
- package/es/components/Tag/OperationalTag.js +45 -9
- package/es/components/Tag/SelectableTag.d.ts +12 -12
- package/es/components/Tag/SelectableTag.js +46 -10
- package/es/components/Tag/Tag.d.ts +3 -3
- package/es/components/Tag/Tag.js +31 -5
- package/es/components/TextArea/TextArea.d.ts +6 -7
- package/es/components/TextArea/index.d.ts +2 -2
- package/es/components/TextInput/PasswordInput.d.ts +5 -6
- package/es/components/TextInput/PasswordInput.js +2 -2
- package/es/components/TextInput/TextInput.d.ts +1 -2
- package/es/components/TextInput/index.d.ts +4 -2
- package/es/components/Theme/index.d.ts +1 -0
- package/es/components/Theme/index.js +8 -2
- package/es/components/Tile/Tile.d.ts +3 -4
- package/es/components/TileGroup/TileGroup.d.ts +3 -2
- package/es/components/TileGroup/index.d.ts +9 -0
- package/es/components/Toggle/Toggle.js +1 -1
- package/es/components/Tooltip/DefinitionTooltip.js +1 -1
- package/es/components/Tooltip/Tooltip.js +16 -5
- package/es/components/Tooltip/index.d.ts +2 -2
- package/es/components/UnorderedList/UnorderedList.d.ts +1 -1
- package/es/components/UnorderedList/index.d.ts +1 -0
- package/es/index.js +4 -4
- package/es/prop-types/deprecateValuesWithin.js +35 -0
- package/lib/components/Accordion/Accordion.d.ts +1 -1
- package/lib/components/Accordion/index.d.ts +2 -2
- package/lib/components/Button/Button.js +2 -2
- package/lib/components/Button/index.d.ts +2 -1
- package/lib/components/Checkbox/Checkbox.d.ts +6 -7
- package/lib/components/ComboBox/ComboBox.d.ts +4 -5
- package/lib/components/ComboBox/ComboBox.js +267 -261
- package/lib/components/ComposedModal/ComposedModal.d.ts +1 -2
- package/lib/components/DataTable/TableHeader.d.ts +4 -5
- package/lib/components/DataTable/TableSlugRow.d.ts +3 -2
- package/lib/components/DatePicker/DatePicker.d.ts +4 -5
- package/lib/components/Dropdown/Dropdown.d.ts +6 -7
- package/lib/components/Dropdown/index.d.ts +2 -2
- package/lib/components/FormLabel/index.d.ts +2 -2
- package/lib/components/Grid/Column.d.ts +2 -2
- package/lib/components/Grid/GridTypes.d.ts +1 -2
- package/lib/components/Grid/index.d.ts +3 -1
- package/lib/components/IconButton/index.d.ts +3 -4
- package/lib/components/InlineLoading/index.d.ts +2 -2
- package/lib/components/ListBox/next/ListBoxTrigger.js +1 -0
- package/lib/components/Loading/index.d.ts +2 -2
- package/lib/components/Menu/Menu.js +1 -1
- package/lib/components/Menu/MenuItem.js +13 -2
- package/lib/components/Modal/Modal.d.ts +8 -9
- package/lib/components/Modal/index.d.ts +2 -2
- package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +1 -2
- package/lib/components/MultiSelect/MultiSelect.d.ts +10 -9
- package/lib/components/Notification/Notification.d.ts +2 -2
- package/lib/components/NumberInput/NumberInput.d.ts +12 -2
- package/lib/components/NumberInput/NumberInput.js +2 -2
- package/lib/components/NumberInput/index.d.ts +1 -1
- package/lib/components/OverflowMenu/OverflowMenu.d.ts +10 -6
- package/lib/components/OverflowMenu/index.d.ts +13 -0
- package/lib/components/PasswordInput/index.d.ts +3 -0
- package/lib/components/Popover/index.d.ts +8 -2
- package/lib/components/Popover/index.js +26 -1
- package/lib/components/ProgressBar/ProgressBar.d.ts +1 -1
- package/lib/components/ProgressBar/index.d.ts +2 -2
- package/lib/components/ProgressIndicator/ProgressIndicator.d.ts +2 -2
- package/lib/components/ProgressIndicator/index.d.ts +2 -0
- package/lib/components/RadioButton/RadioButton.d.ts +3 -4
- package/lib/components/RadioButtonGroup/RadioButtonGroup.d.ts +7 -8
- package/lib/components/Select/Select.d.ts +1 -2
- package/lib/components/Slider/Slider.d.ts +5 -5
- package/lib/components/Slider/Slider.js +1 -1
- package/lib/components/StructuredList/index.d.ts +2 -0
- package/lib/components/Switch/Switch.d.ts +1 -1
- package/lib/components/Switch/index.d.ts +2 -2
- package/lib/components/Tab/index.d.ts +2 -1
- package/lib/components/Tag/DismissibleTag.d.ts +12 -12
- package/lib/components/Tag/DismissibleTag.js +33 -8
- package/lib/components/Tag/OperationalTag.d.ts +12 -12
- package/lib/components/Tag/OperationalTag.js +44 -8
- package/lib/components/Tag/SelectableTag.d.ts +12 -12
- package/lib/components/Tag/SelectableTag.js +45 -9
- package/lib/components/Tag/Tag.d.ts +3 -3
- package/lib/components/Tag/Tag.js +30 -4
- package/lib/components/TextArea/TextArea.d.ts +6 -7
- package/lib/components/TextArea/index.d.ts +2 -2
- package/lib/components/TextInput/PasswordInput.d.ts +5 -6
- package/lib/components/TextInput/PasswordInput.js +2 -2
- package/lib/components/TextInput/TextInput.d.ts +1 -2
- package/lib/components/TextInput/index.d.ts +4 -2
- package/lib/components/Theme/index.d.ts +1 -0
- package/lib/components/Theme/index.js +8 -1
- package/lib/components/Tile/Tile.d.ts +3 -4
- package/lib/components/TileGroup/TileGroup.d.ts +3 -2
- package/lib/components/TileGroup/index.d.ts +9 -0
- package/lib/components/Toggle/Toggle.js +1 -1
- package/lib/components/Tooltip/DefinitionTooltip.js +1 -1
- package/lib/components/Tooltip/Tooltip.js +16 -5
- package/lib/components/Tooltip/index.d.ts +2 -2
- package/lib/components/UnorderedList/UnorderedList.d.ts +1 -1
- package/lib/components/UnorderedList/index.d.ts +1 -0
- package/lib/index.js +30 -29
- package/lib/prop-types/deprecateValuesWithin.js +39 -0
- package/package.json +6 -6
- package/es/components/TileGroup/index.js +0 -13
- package/lib/components/TileGroup/index.js +0 -18
|
@@ -23,8 +23,8 @@ var deprecate = require('../../prop-types/deprecate.js');
|
|
|
23
23
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
24
24
|
require('../FluidForm/FluidForm.js');
|
|
25
25
|
var FormContext = require('../FluidForm/FormContext.js');
|
|
26
|
-
var match = require('../../internal/keyboard/match.js');
|
|
27
26
|
var Text = require('../Text/Text.js');
|
|
27
|
+
var match = require('../../internal/keyboard/match.js');
|
|
28
28
|
var ListBoxSelection = require('../ListBox/next/ListBoxSelection.js');
|
|
29
29
|
var ListBoxTrigger = require('../ListBox/next/ListBoxTrigger.js');
|
|
30
30
|
var ListBoxPropTypes = require('../ListBox/ListBoxPropTypes.js');
|
|
@@ -33,21 +33,19 @@ var keys = require('../../internal/keyboard/keys.js');
|
|
|
33
33
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
34
34
|
|
|
35
35
|
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
36
|
-
var Downshift__default = /*#__PURE__*/_interopDefaultLegacy(Downshift);
|
|
37
36
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
38
37
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
39
38
|
|
|
40
39
|
const {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} = Downshift__default["default"].stateChangeTypes;
|
|
40
|
+
InputBlur,
|
|
41
|
+
InputKeyDownEnter,
|
|
42
|
+
FunctionToggleMenu,
|
|
43
|
+
ToggleButtonClick,
|
|
44
|
+
ItemMouseMove,
|
|
45
|
+
InputKeyDownArrowUp,
|
|
46
|
+
InputKeyDownArrowDown,
|
|
47
|
+
MenuMouseLeave
|
|
48
|
+
} = Downshift.useCombobox.stateChangeTypes;
|
|
51
49
|
const defaultItemToString = item => {
|
|
52
50
|
if (typeof item === 'string') {
|
|
53
51
|
return item;
|
|
@@ -87,7 +85,7 @@ const findHighlightedIndex = (_ref2, inputValue) => {
|
|
|
87
85
|
const searchValue = inputValue.toLowerCase();
|
|
88
86
|
for (let i = 0; i < items.length; i++) {
|
|
89
87
|
const item = itemToString(items[i]).toLowerCase();
|
|
90
|
-
if (item.indexOf(searchValue) !== -1) {
|
|
88
|
+
if (!items[i]['disabled'] && item.indexOf(searchValue) !== -1) {
|
|
91
89
|
return i;
|
|
92
90
|
}
|
|
93
91
|
}
|
|
@@ -95,7 +93,6 @@ const findHighlightedIndex = (_ref2, inputValue) => {
|
|
|
95
93
|
};
|
|
96
94
|
const getInstanceId = setupGetInstanceId["default"]();
|
|
97
95
|
const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
98
|
-
var _Text;
|
|
99
96
|
const {
|
|
100
97
|
['aria-label']: ariaLabel = 'Choose an item',
|
|
101
98
|
ariaLabel: deprecatedAriaLabel,
|
|
@@ -117,7 +114,7 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
117
114
|
onToggleClick,
|
|
118
115
|
placeholder,
|
|
119
116
|
readOnly,
|
|
120
|
-
selectedItem,
|
|
117
|
+
selectedItem: selectedItemProp,
|
|
121
118
|
shouldFilterItem = defaultShouldFilterItem,
|
|
122
119
|
size,
|
|
123
120
|
titleText,
|
|
@@ -138,21 +135,20 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
138
135
|
initialSelectedItem,
|
|
139
136
|
inputValue: '',
|
|
140
137
|
itemToString,
|
|
141
|
-
selectedItem
|
|
138
|
+
selectedItem: selectedItemProp
|
|
142
139
|
}));
|
|
143
140
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
144
141
|
const [prevSelectedItem, setPrevSelectedItem] = React.useState();
|
|
145
142
|
const [doneInitialSelectedItem, setDoneInitialSelectedItem] = React.useState(false);
|
|
146
|
-
const [highlightedIndex, setHighlightedIndex] = React.useState();
|
|
147
143
|
const savedOnInputChange = React.useRef(onInputChange);
|
|
148
|
-
if (!doneInitialSelectedItem || prevSelectedItem !==
|
|
144
|
+
if (!doneInitialSelectedItem || prevSelectedItem !== selectedItemProp) {
|
|
149
145
|
setDoneInitialSelectedItem(true);
|
|
150
|
-
setPrevSelectedItem(
|
|
146
|
+
setPrevSelectedItem(selectedItemProp);
|
|
151
147
|
setInputValue(getInputValue({
|
|
152
148
|
initialSelectedItem,
|
|
153
149
|
inputValue,
|
|
154
150
|
itemToString,
|
|
155
|
-
selectedItem
|
|
151
|
+
selectedItem: selectedItemProp
|
|
156
152
|
}));
|
|
157
153
|
}
|
|
158
154
|
const filterItems = (items, itemToString, inputValue) => items.filter(item => shouldFilterItem ? shouldFilterItem({
|
|
@@ -160,16 +156,6 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
160
156
|
itemToString,
|
|
161
157
|
inputValue
|
|
162
158
|
}) : defaultShouldFilterItem());
|
|
163
|
-
const handleOnChange = selectedItem => {
|
|
164
|
-
if (onChange) {
|
|
165
|
-
onChange({
|
|
166
|
-
selectedItem
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
const handleOnInputValueChange = inputValue => {
|
|
171
|
-
setInputValue(inputValue || '');
|
|
172
|
-
};
|
|
173
159
|
React.useEffect(() => {
|
|
174
160
|
savedOnInputChange.current = onInputChange;
|
|
175
161
|
}, [onInputChange]);
|
|
@@ -183,62 +169,80 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
183
169
|
textInput.current.focus();
|
|
184
170
|
}
|
|
185
171
|
};
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const indexToHighlight = findHighlightedIndex({
|
|
193
|
-
...props,
|
|
194
|
-
items: filteredItems
|
|
195
|
-
}, inputValue);
|
|
196
|
-
setHighlightedIndex(indexToHighlight);
|
|
197
|
-
return indexToHighlight;
|
|
198
|
-
}
|
|
199
|
-
return highlightedIndex || 0;
|
|
200
|
-
};
|
|
201
|
-
const handleOnStateChange = (changes, _ref3) => {
|
|
202
|
-
let {
|
|
203
|
-
setHighlightedIndex: updateHighlightedIndex
|
|
204
|
-
} = _ref3;
|
|
172
|
+
const filteredItems = inputValue => filterItems(items, itemToString, inputValue || null);
|
|
173
|
+
const indexToHighlight = inputValue => findHighlightedIndex({
|
|
174
|
+
...props,
|
|
175
|
+
items: filteredItems(inputValue)
|
|
176
|
+
}, inputValue);
|
|
177
|
+
const stateReducer = React__default["default"].useCallback((state, actionAndChanges) => {
|
|
205
178
|
const {
|
|
206
|
-
type
|
|
179
|
+
type,
|
|
180
|
+
changes
|
|
181
|
+
} = actionAndChanges;
|
|
182
|
+
const {
|
|
183
|
+
highlightedIndex
|
|
207
184
|
} = changes;
|
|
208
185
|
switch (type) {
|
|
209
|
-
case
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
186
|
+
case InputBlur:
|
|
187
|
+
if (state.inputValue && highlightedIndex == '-1' && !allowCustomValue) {
|
|
188
|
+
return {
|
|
189
|
+
...changes,
|
|
190
|
+
inputValue: ''
|
|
191
|
+
};
|
|
215
192
|
}
|
|
216
|
-
|
|
217
|
-
case
|
|
218
|
-
case keyDownEscape:
|
|
219
|
-
setHighlightedIndex(changes.highlightedIndex);
|
|
220
|
-
break;
|
|
221
|
-
case changeInput:
|
|
222
|
-
updateHighlightedIndex(getHighlightedIndex(changes));
|
|
223
|
-
break;
|
|
224
|
-
case blurInput:
|
|
193
|
+
return changes;
|
|
194
|
+
case InputKeyDownEnter:
|
|
225
195
|
if (allowCustomValue) {
|
|
226
196
|
setInputValue(inputValue);
|
|
197
|
+
setHighlightedIndex(changes.selectedItem);
|
|
227
198
|
if (onChange) {
|
|
228
199
|
onChange({
|
|
229
|
-
selectedItem
|
|
230
|
-
inputValue
|
|
200
|
+
selectedItem: changes.selectedItem
|
|
231
201
|
});
|
|
232
202
|
}
|
|
203
|
+
return changes;
|
|
204
|
+
} else if (changes.selectedItem && !allowCustomValue) {
|
|
205
|
+
return changes;
|
|
206
|
+
} else {
|
|
207
|
+
return {
|
|
208
|
+
...changes,
|
|
209
|
+
isOpen: true
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
case FunctionToggleMenu:
|
|
213
|
+
case ToggleButtonClick:
|
|
214
|
+
if (changes.isOpen && !changes.selectedItem) {
|
|
215
|
+
return {
|
|
216
|
+
...changes,
|
|
217
|
+
highlightedIndex: 0
|
|
218
|
+
};
|
|
233
219
|
}
|
|
234
|
-
|
|
235
|
-
case
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
220
|
+
return changes;
|
|
221
|
+
case MenuMouseLeave:
|
|
222
|
+
return {
|
|
223
|
+
...changes,
|
|
224
|
+
highlightedIndex: state.highlightedIndex
|
|
225
|
+
};
|
|
226
|
+
case InputKeyDownArrowUp:
|
|
227
|
+
case InputKeyDownArrowDown:
|
|
228
|
+
if (highlightedIndex === -1) {
|
|
229
|
+
return {
|
|
230
|
+
...changes,
|
|
231
|
+
highlightedIndex: 0
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return changes;
|
|
235
|
+
case ItemMouseMove:
|
|
236
|
+
return {
|
|
237
|
+
...changes,
|
|
238
|
+
highlightedIndex: state.highlightedIndex
|
|
239
|
+
};
|
|
240
|
+
default:
|
|
241
|
+
return changes;
|
|
240
242
|
}
|
|
241
|
-
}
|
|
243
|
+
},
|
|
244
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
245
|
+
[allowCustomValue, inputValue, onChange]);
|
|
242
246
|
const handleToggleClick = isOpen => event => {
|
|
243
247
|
if (onToggleClick) {
|
|
244
248
|
onToggleClick(event);
|
|
@@ -283,205 +287,208 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
283
287
|
size: 'mini'
|
|
284
288
|
});
|
|
285
289
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
290
|
+
const {
|
|
291
|
+
getInputProps,
|
|
292
|
+
getItemProps,
|
|
293
|
+
getLabelProps,
|
|
294
|
+
getMenuProps,
|
|
295
|
+
getToggleButtonProps,
|
|
296
|
+
isOpen,
|
|
297
|
+
highlightedIndex,
|
|
298
|
+
selectItem,
|
|
299
|
+
selectedItem,
|
|
300
|
+
toggleMenu,
|
|
301
|
+
setHighlightedIndex
|
|
302
|
+
} = Downshift.useCombobox({
|
|
303
|
+
...downshiftProps,
|
|
304
|
+
items,
|
|
305
|
+
inputValue: inputValue,
|
|
306
|
+
itemToString: item => {
|
|
307
|
+
return itemToString(item);
|
|
308
|
+
},
|
|
309
|
+
onInputValueChange(_ref3) {
|
|
310
|
+
let {
|
|
311
|
+
inputValue
|
|
312
|
+
} = _ref3;
|
|
313
|
+
setInputValue(inputValue || '');
|
|
314
|
+
setHighlightedIndex(indexToHighlight(inputValue));
|
|
315
|
+
},
|
|
316
|
+
onSelectedItemChange(_ref4) {
|
|
317
|
+
let {
|
|
318
|
+
selectedItem
|
|
319
|
+
} = _ref4;
|
|
320
|
+
onChange({
|
|
321
|
+
selectedItem
|
|
322
|
+
});
|
|
295
323
|
},
|
|
296
|
-
inputValue: inputValue || '',
|
|
297
|
-
itemToString: itemToString,
|
|
298
324
|
initialSelectedItem: initialSelectedItem,
|
|
299
325
|
inputId: id,
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
//
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const labelProps = getLabelProps();
|
|
321
|
-
const buttonProps = getToggleButtonProps({
|
|
322
|
-
disabled: disabled || readOnly,
|
|
323
|
-
onClick: handleToggleClick(isOpen),
|
|
324
|
-
// When we moved the "root node" of Downshift to the <input> for
|
|
325
|
-
// ARIA 1.2 compliance, we unfortunately hit this branch for the
|
|
326
|
-
// "mouseup" event that downshift listens to:
|
|
327
|
-
// https://github.com/downshift-js/downshift/blob/v5.2.1/src/downshift.js#L1051-L1065
|
|
328
|
-
//
|
|
329
|
-
// As a result, it will reset the state of the component and so we
|
|
330
|
-
// stop the event from propagating to prevent this if the menu is already open.
|
|
331
|
-
// This allows the toggleMenu behavior for the toggleButton to correctly open and
|
|
332
|
-
// close the menu.
|
|
333
|
-
onMouseUp(event) {
|
|
334
|
-
if (isOpen) {
|
|
335
|
-
event.stopPropagation();
|
|
336
|
-
}
|
|
326
|
+
stateReducer,
|
|
327
|
+
isItemDisabled(item, _index) {
|
|
328
|
+
return item.disabled;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
const buttonProps = getToggleButtonProps({
|
|
332
|
+
disabled: disabled || readOnly,
|
|
333
|
+
onClick: handleToggleClick(isOpen),
|
|
334
|
+
// When we moved the "root node" of Downshift to the <input> for
|
|
335
|
+
// ARIA 1.2 compliance, we unfortunately hit this branch for the
|
|
336
|
+
// "mouseup" event that downshift listens to:
|
|
337
|
+
// https://github.com/downshift-js/downshift/blob/v5.2.1/src/downshift.js#L1051-L1065
|
|
338
|
+
//
|
|
339
|
+
// As a result, it will reset the state of the component and so we
|
|
340
|
+
// stop the event from propagating to prevent this if the menu is already open.
|
|
341
|
+
// This allows the toggleMenu behavior for the toggleButton to correctly open and
|
|
342
|
+
// close the menu.
|
|
343
|
+
onMouseUp(event) {
|
|
344
|
+
if (isOpen) {
|
|
345
|
+
event.stopPropagation();
|
|
337
346
|
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
const handleFocus = evt => {
|
|
350
|
+
setIsFocused(evt.type === 'focus');
|
|
351
|
+
};
|
|
352
|
+
const readOnlyEventHandlers = readOnly ? {
|
|
353
|
+
onKeyDown: evt => {
|
|
354
|
+
// This prevents the select from opening for the above keys
|
|
355
|
+
if (evt.key !== 'Tab') {
|
|
356
|
+
evt.preventDefault();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
} : {};
|
|
360
|
+
|
|
361
|
+
// The input should be described by the appropriate message text id
|
|
362
|
+
// when both the message is supplied *and* when the component is in
|
|
363
|
+
// the matching state (invalid, warn, etc).
|
|
364
|
+
const ariaDescribedBy = invalid && invalidText && invalidTextId || warn && warnText && warnTextId || helperText && !isFluid && helperTextId || undefined;
|
|
365
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
366
|
+
className: wrapperClasses
|
|
367
|
+
}, titleText && /*#__PURE__*/React__default["default"].createElement(Text.Text, _rollupPluginBabelHelpers["extends"]({
|
|
368
|
+
as: "label",
|
|
369
|
+
className: titleClasses
|
|
370
|
+
}, getLabelProps()), titleText), /*#__PURE__*/React__default["default"].createElement(index["default"], {
|
|
371
|
+
onFocus: handleFocus,
|
|
372
|
+
onBlur: handleFocus,
|
|
373
|
+
className: className,
|
|
374
|
+
disabled: disabled,
|
|
375
|
+
invalid: invalid,
|
|
376
|
+
invalidText: invalidText,
|
|
377
|
+
invalidTextId: invalidTextId,
|
|
378
|
+
isOpen: isOpen,
|
|
379
|
+
light: light,
|
|
380
|
+
size: size,
|
|
381
|
+
warn: warn,
|
|
382
|
+
warnText: warnText,
|
|
383
|
+
warnTextId: warnTextId
|
|
384
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
385
|
+
className: `${prefix}--list-box__field`
|
|
386
|
+
}, /*#__PURE__*/React__default["default"].createElement("input", _rollupPluginBabelHelpers["extends"]({
|
|
387
|
+
disabled: disabled,
|
|
388
|
+
className: inputClasses,
|
|
389
|
+
type: "text",
|
|
390
|
+
tabIndex: 0,
|
|
391
|
+
"aria-haspopup": "listbox",
|
|
392
|
+
"aria-owns": getMenuProps().id,
|
|
393
|
+
title: textInput?.current?.value
|
|
394
|
+
}, getInputProps({
|
|
395
|
+
placeholder,
|
|
396
|
+
ref: {
|
|
397
|
+
...mergeRefs["default"](textInput, ref)
|
|
398
|
+
},
|
|
399
|
+
onKeyDown: event => {
|
|
400
|
+
if (match.match(event, keys.Space)) {
|
|
401
|
+
event.stopPropagation();
|
|
402
|
+
}
|
|
403
|
+
if (match.match(event, keys.Enter) && (!inputValue || allowCustomValue)) {
|
|
343
404
|
toggleMenu();
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (match.match(event, keys.Space)) {
|
|
347
|
-
event.stopPropagation();
|
|
405
|
+
if (highlightedIndex !== -1) {
|
|
406
|
+
selectItem(items[highlightedIndex]);
|
|
348
407
|
}
|
|
349
|
-
|
|
408
|
+
event.preventDownshiftDefault = true;
|
|
409
|
+
event?.persist?.();
|
|
410
|
+
}
|
|
411
|
+
if (match.match(event, keys.Escape) && inputValue) {
|
|
412
|
+
if (event.target === textInput.current && isOpen) {
|
|
350
413
|
toggleMenu();
|
|
351
|
-
|
|
352
|
-
// Since `onChange` does not normally fire when the menu is closed, we should
|
|
353
|
-
// manually fire it when `allowCustomValue` is provided, the menu is closing,
|
|
354
|
-
// and there is a value.
|
|
355
|
-
if (allowCustomValue && isOpen && inputValue) {
|
|
356
|
-
onChange({
|
|
357
|
-
selectedItem,
|
|
358
|
-
inputValue
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (match.match(event, keys.Escape) && inputValue) {
|
|
363
|
-
if (event.target === textInput.current && isOpen) {
|
|
364
|
-
toggleMenu();
|
|
365
|
-
event.preventDownshiftDefault = true;
|
|
366
|
-
event?.persist?.();
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
if (match.match(event, keys.Home) && event.code !== 'Numpad7') {
|
|
370
|
-
event.target.setSelectionRange(0, 0);
|
|
371
|
-
}
|
|
372
|
-
if (match.match(event, keys.End) && event.code !== 'Numpad1') {
|
|
373
|
-
event.target.setSelectionRange(event.target.value.length, event.target.value.length);
|
|
374
|
-
}
|
|
375
|
-
if (event.altKey && event.key == 'ArrowDown') {
|
|
376
414
|
event.preventDownshiftDefault = true;
|
|
377
|
-
|
|
378
|
-
toggleMenu();
|
|
379
|
-
}
|
|
415
|
+
event?.persist?.();
|
|
380
416
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
417
|
+
}
|
|
418
|
+
if (match.match(event, keys.Home) && event.code !== 'Numpad7') {
|
|
419
|
+
event.target.setSelectionRange(0, 0);
|
|
420
|
+
}
|
|
421
|
+
if (match.match(event, keys.End) && event.code !== 'Numpad1') {
|
|
422
|
+
event.target.setSelectionRange(event.target.value.length, event.target.value.length);
|
|
423
|
+
}
|
|
424
|
+
if (event.altKey && event.key == 'ArrowDown') {
|
|
425
|
+
event.preventDownshiftDefault = true;
|
|
426
|
+
if (!isOpen) {
|
|
427
|
+
toggleMenu();
|
|
386
428
|
}
|
|
387
429
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const readOnlyEventHandlers = readOnly ? {
|
|
393
|
-
onKeyDown: evt => {
|
|
394
|
-
// This prevents the select from opening for the above keys
|
|
395
|
-
if (evt.key !== 'Tab') {
|
|
396
|
-
evt.preventDefault();
|
|
430
|
+
if (event.altKey && event.key == 'ArrowUp') {
|
|
431
|
+
event.preventDownshiftDefault = true;
|
|
432
|
+
if (isOpen) {
|
|
433
|
+
toggleMenu();
|
|
397
434
|
}
|
|
398
435
|
}
|
|
399
|
-
}
|
|
436
|
+
}
|
|
437
|
+
}), rest, readOnlyEventHandlers, {
|
|
438
|
+
readOnly: readOnly,
|
|
439
|
+
"aria-describedby": ariaDescribedBy
|
|
440
|
+
})), invalid && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningFilled, {
|
|
441
|
+
className: `${prefix}--list-box__invalid-icon`
|
|
442
|
+
}), showWarning && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningAltFilled, {
|
|
443
|
+
className: `${prefix}--list-box__invalid-icon ${prefix}--list-box__invalid-icon--warning`
|
|
444
|
+
}), inputValue && /*#__PURE__*/React__default["default"].createElement(ListBoxSelection["default"], {
|
|
445
|
+
clearSelection: () => {
|
|
446
|
+
selectItem(null);
|
|
447
|
+
},
|
|
448
|
+
translateWithId: translateWithId,
|
|
449
|
+
disabled: disabled || readOnly,
|
|
450
|
+
onClearSelection: handleSelectionClear,
|
|
451
|
+
selectionCount: 0
|
|
452
|
+
}), /*#__PURE__*/React__default["default"].createElement(ListBoxTrigger["default"], _rollupPluginBabelHelpers["extends"]({}, buttonProps, {
|
|
453
|
+
// @ts-expect-error
|
|
454
|
+
isOpen: isOpen,
|
|
455
|
+
translateWithId: translateWithId
|
|
456
|
+
}))), normalizedSlug, /*#__PURE__*/React__default["default"].createElement(index["default"].Menu, getMenuProps({
|
|
457
|
+
'aria-label': deprecatedAriaLabel || ariaLabel
|
|
458
|
+
}), isOpen ? filterItems(items, itemToString, inputValue).map((item, index$1) => {
|
|
459
|
+
const isObject = item !== null && typeof item === 'object';
|
|
460
|
+
const title = isObject && 'text' in item && itemToElement ? item.text?.toString() : itemToString(item);
|
|
461
|
+
const itemProps = getItemProps({
|
|
462
|
+
item,
|
|
463
|
+
index: index$1
|
|
464
|
+
});
|
|
400
465
|
|
|
401
|
-
// The
|
|
402
|
-
//
|
|
403
|
-
//
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
role: "combobox",
|
|
428
|
-
disabled: disabled,
|
|
429
|
-
className: inputClasses,
|
|
430
|
-
type: "text",
|
|
431
|
-
tabIndex: 0,
|
|
432
|
-
"aria-autocomplete": "list",
|
|
433
|
-
"aria-expanded": rootProps['aria-expanded'],
|
|
434
|
-
"aria-haspopup": "listbox",
|
|
435
|
-
"aria-controls": inputProps['aria-controls'],
|
|
436
|
-
"aria-owns": getMenuProps().id,
|
|
437
|
-
title: textInput?.current?.value
|
|
438
|
-
}, inputProps, rest, readOnlyEventHandlers, {
|
|
439
|
-
readOnly: readOnly,
|
|
440
|
-
ref: mergeRefs["default"](textInput, ref),
|
|
441
|
-
"aria-describedby": ariaDescribedBy
|
|
442
|
-
})), invalid && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningFilled, {
|
|
443
|
-
className: `${prefix}--list-box__invalid-icon`
|
|
444
|
-
}), showWarning && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningAltFilled, {
|
|
445
|
-
className: `${prefix}--list-box__invalid-icon ${prefix}--list-box__invalid-icon--warning`
|
|
446
|
-
}), inputValue && /*#__PURE__*/React__default["default"].createElement(ListBoxSelection["default"], {
|
|
447
|
-
clearSelection: clearSelection,
|
|
448
|
-
translateWithId: translateWithId,
|
|
449
|
-
disabled: disabled || readOnly,
|
|
450
|
-
onClearSelection: handleSelectionClear,
|
|
451
|
-
selectionCount: 0
|
|
452
|
-
}), /*#__PURE__*/React__default["default"].createElement(ListBoxTrigger["default"], _rollupPluginBabelHelpers["extends"]({}, buttonProps, {
|
|
453
|
-
// @ts-expect-error
|
|
454
|
-
isOpen: isOpen,
|
|
455
|
-
translateWithId: translateWithId
|
|
456
|
-
}))), normalizedSlug, /*#__PURE__*/React__default["default"].createElement(index["default"].Menu, getMenuProps({
|
|
457
|
-
'aria-label': deprecatedAriaLabel || ariaLabel
|
|
458
|
-
}), isOpen ? filterItems(items, itemToString, inputValue).map((item, index$1) => {
|
|
459
|
-
const isObject = item !== null && typeof item === 'object';
|
|
460
|
-
const title = isObject && 'text' in item && itemToElement ? item.text?.toString() : itemToString(item);
|
|
461
|
-
const disabled = isObject && 'disabled' in item ? !!item.disabled : undefined;
|
|
462
|
-
const itemProps = getItemProps({
|
|
463
|
-
item,
|
|
464
|
-
index: index$1,
|
|
465
|
-
['aria-current']: selectedItem === item ? 'true' : 'false',
|
|
466
|
-
['aria-selected']: highlightedIndex === index$1 ? 'true' : 'false',
|
|
467
|
-
disabled
|
|
468
|
-
});
|
|
469
|
-
return /*#__PURE__*/React__default["default"].createElement(index["default"].MenuItem, _rollupPluginBabelHelpers["extends"]({
|
|
470
|
-
key: itemProps.id,
|
|
471
|
-
isActive: selectedItem === item,
|
|
472
|
-
isHighlighted: highlightedIndex === index$1,
|
|
473
|
-
title: title
|
|
474
|
-
}, itemProps), ItemToElement ? /*#__PURE__*/React__default["default"].createElement(ItemToElement, _rollupPluginBabelHelpers["extends"]({
|
|
475
|
-
key: itemProps.id
|
|
476
|
-
}, item)) : itemToString(item), selectedItem === item && /*#__PURE__*/React__default["default"].createElement(iconsReact.Checkmark, {
|
|
477
|
-
className: `${prefix}--list-box__menu-item__selected-icon`
|
|
478
|
-
}));
|
|
479
|
-
}) : null)), helperText && !invalid && !warn && !isFluid && (_Text || (_Text = /*#__PURE__*/React__default["default"].createElement(Text.Text, {
|
|
480
|
-
as: "div",
|
|
481
|
-
id: helperTextId,
|
|
482
|
-
className: helperClasses
|
|
483
|
-
}, helperText))));
|
|
484
|
-
});
|
|
466
|
+
// The initial implementation using <Downshift> would place the disabled attribute
|
|
467
|
+
// on disabled menu items. Conversely, useCombobox places aria-disabled instead.
|
|
468
|
+
// To avoid any potential breaking changes, we avoid placing aria-disabled and
|
|
469
|
+
// instead match the old behavior of placing the disabled attribute.
|
|
470
|
+
const disabled = itemProps['aria-disabled'];
|
|
471
|
+
const {
|
|
472
|
+
'aria-disabled': unusedAriaDisabled,
|
|
473
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
474
|
+
...modifiedItemProps
|
|
475
|
+
} = itemProps;
|
|
476
|
+
return /*#__PURE__*/React__default["default"].createElement(index["default"].MenuItem, _rollupPluginBabelHelpers["extends"]({
|
|
477
|
+
key: itemProps.id,
|
|
478
|
+
isActive: selectedItem === item,
|
|
479
|
+
isHighlighted: highlightedIndex === index$1,
|
|
480
|
+
title: title,
|
|
481
|
+
disabled: disabled
|
|
482
|
+
}, modifiedItemProps), ItemToElement ? /*#__PURE__*/React__default["default"].createElement(ItemToElement, _rollupPluginBabelHelpers["extends"]({
|
|
483
|
+
key: itemProps.id
|
|
484
|
+
}, item)) : itemToString(item), selectedItem === item && /*#__PURE__*/React__default["default"].createElement(iconsReact.Checkmark, {
|
|
485
|
+
className: `${prefix}--list-box__menu-item__selected-icon`
|
|
486
|
+
}));
|
|
487
|
+
}) : null)), helperText && !invalid && !warn && !isFluid && /*#__PURE__*/React__default["default"].createElement(Text.Text, {
|
|
488
|
+
as: "div",
|
|
489
|
+
id: helperTextId,
|
|
490
|
+
className: helperClasses
|
|
491
|
+
}, helperText));
|
|
485
492
|
});
|
|
486
493
|
ComboBox.displayName = 'ComboBox';
|
|
487
494
|
ComboBox.propTypes = {
|
|
@@ -516,8 +523,7 @@ ComboBox.propTypes = {
|
|
|
516
523
|
/**
|
|
517
524
|
* Additional props passed to Downshift
|
|
518
525
|
*/
|
|
519
|
-
|
|
520
|
-
downshiftProps: PropTypes__default["default"].shape(Downshift__default["default"].propTypes),
|
|
526
|
+
downshiftProps: PropTypes__default["default"].object,
|
|
521
527
|
/**
|
|
522
528
|
* Provide helper text that is used alongside the control label for
|
|
523
529
|
* additional help
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { type MouseEvent, type KeyboardEvent, type HTMLAttributes, type ReactNode, type RefObject } from 'react';
|
|
2
|
-
import { ReactNodeLike } from 'prop-types';
|
|
3
2
|
export interface ModalBodyProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
3
|
/** Specify the content to be placed in the ModalBody. */
|
|
5
4
|
children?: ReactNode;
|
|
@@ -73,7 +72,7 @@ export interface ComposedModalProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
73
72
|
/**
|
|
74
73
|
* **Experimental**: Provide a `Slug` component to be rendered inside the `ComposedModal` component
|
|
75
74
|
*/
|
|
76
|
-
slug?:
|
|
75
|
+
slug?: ReactNode;
|
|
77
76
|
}
|
|
78
77
|
declare const ComposedModal: React.ForwardRefExoticComponent<ComposedModalProps & React.RefAttributes<HTMLDivElement>>;
|
|
79
78
|
export default ComposedModal;
|