@carbon/react 1.57.0-rc.0 → 1.57.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 +971 -936
- package/es/components/ComboBox/ComboBox.js +1 -0
- package/es/components/ContainedList/ContainedList.d.ts +7 -3
- package/es/components/ContainedList/ContainedList.js +3 -2
- package/es/components/ContainedList/ContainedListItem/ContainedListItem.js +1 -2
- package/es/components/ContainedList/ContainedListItem/index.d.ts +9 -0
- package/es/components/ContainedList/index.d.ts +11 -0
- package/es/components/ContainedList/index.js +13 -0
- package/es/components/DataTable/stories/examples/TableToolbarFilter.d.ts +51 -0
- package/es/components/DatePicker/DatePicker.d.ts +5 -4
- package/es/components/DatePicker/plugins/rangePlugin.js +5 -6
- package/es/components/Dialog/index.d.ts +31 -0
- package/es/components/ListBox/next/ListBoxTrigger.js +4 -3
- package/es/components/MultiSelect/FilterableMultiSelect.d.ts +177 -0
- package/es/components/MultiSelect/FilterableMultiSelect.js +388 -313
- package/es/components/MultiSelect/MultiSelect.js +1 -2
- package/es/components/MultiSelect/MultiSelectPropTypes.d.ts +62 -0
- package/es/components/MultiSelect/index.d.ts +10 -0
- package/es/components/MultiSelect/index.js +2 -0
- package/es/components/Pagination/Pagination.js +9 -9
- package/es/components/RadioButton/RadioButton.d.ts +4 -0
- package/es/components/RadioButton/RadioButton.js +7 -1
- package/es/components/RadioButtonGroup/RadioButtonGroup.d.ts +4 -0
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +7 -1
- package/es/components/TimePicker/TimePicker.js +1 -1
- package/es/index.js +3 -1
- package/lib/components/ComboBox/ComboBox.js +1 -0
- package/lib/components/ContainedList/ContainedList.d.ts +7 -3
- package/lib/components/ContainedList/ContainedList.js +3 -2
- package/lib/components/ContainedList/ContainedListItem/ContainedListItem.js +1 -2
- package/lib/components/ContainedList/ContainedListItem/index.d.ts +9 -0
- package/lib/components/ContainedList/index.d.ts +11 -0
- package/lib/components/ContainedList/index.js +19 -0
- package/lib/components/DataTable/stories/examples/TableToolbarFilter.d.ts +51 -0
- package/lib/components/DatePicker/DatePicker.d.ts +5 -4
- package/lib/components/DatePicker/plugins/rangePlugin.js +5 -6
- package/lib/components/Dialog/index.d.ts +31 -0
- package/lib/components/ListBox/next/ListBoxTrigger.js +4 -3
- package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +177 -0
- package/lib/components/MultiSelect/FilterableMultiSelect.js +387 -312
- package/lib/components/MultiSelect/MultiSelect.js +1 -2
- package/lib/components/MultiSelect/MultiSelectPropTypes.d.ts +62 -0
- package/lib/components/MultiSelect/index.d.ts +10 -0
- package/lib/components/MultiSelect/index.js +2 -0
- package/lib/components/Pagination/Pagination.js +9 -9
- package/lib/components/RadioButton/RadioButton.d.ts +4 -0
- package/lib/components/RadioButton/RadioButton.js +7 -1
- package/lib/components/RadioButtonGroup/RadioButtonGroup.d.ts +4 -0
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +7 -1
- package/lib/components/TimePicker/TimePicker.js +1 -1
- package/lib/index.js +4 -2
- package/package.json +7 -7
|
@@ -19,7 +19,6 @@ var React = require('react');
|
|
|
19
19
|
var filter = require('../ComboBox/tools/filter.js');
|
|
20
20
|
var MultiSelectPropTypes = require('./MultiSelectPropTypes.js');
|
|
21
21
|
var index = require('../ListBox/index.js');
|
|
22
|
-
var Selection = require('../../internal/Selection.js');
|
|
23
22
|
var itemToString = require('./tools/itemToString.js');
|
|
24
23
|
var mergeRefs = require('../../tools/mergeRefs.js');
|
|
25
24
|
var deprecate = require('../../prop-types/deprecate.js');
|
|
@@ -28,6 +27,7 @@ var sorting = require('./tools/sorting.js');
|
|
|
28
27
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
29
28
|
require('../FluidForm/FluidForm.js');
|
|
30
29
|
var FormContext = require('../FluidForm/FormContext.js');
|
|
30
|
+
var Selection = require('../../internal/Selection.js');
|
|
31
31
|
var match = require('../../internal/keyboard/match.js');
|
|
32
32
|
var ListBoxSelection = require('../ListBox/next/ListBoxSelection.js');
|
|
33
33
|
var ListBoxTrigger = require('../ListBox/next/ListBoxTrigger.js');
|
|
@@ -42,6 +42,27 @@ var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
|
42
42
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
43
43
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
44
44
|
|
|
45
|
+
const {
|
|
46
|
+
InputBlur,
|
|
47
|
+
InputKeyDownEnter,
|
|
48
|
+
ItemClick,
|
|
49
|
+
MenuMouseLeave,
|
|
50
|
+
InputKeyDownArrowUp,
|
|
51
|
+
InputKeyDownArrowDown,
|
|
52
|
+
ItemMouseMove,
|
|
53
|
+
InputClick,
|
|
54
|
+
ToggleButtonClick,
|
|
55
|
+
FunctionToggleMenu,
|
|
56
|
+
InputChange,
|
|
57
|
+
InputKeyDownEscape,
|
|
58
|
+
FunctionSetHighlightedIndex
|
|
59
|
+
} = Downshift.useCombobox.stateChangeTypes;
|
|
60
|
+
const {
|
|
61
|
+
SelectedItemKeyDownBackspace,
|
|
62
|
+
SelectedItemKeyDownDelete,
|
|
63
|
+
DropdownKeyDownBackspace,
|
|
64
|
+
FunctionRemoveSelectedItem
|
|
65
|
+
} = Downshift.useMultipleSelection.stateChangeTypes;
|
|
45
66
|
const FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(function FilterableMultiSelect(_ref, ref) {
|
|
46
67
|
let {
|
|
47
68
|
className: containerClassName,
|
|
@@ -72,6 +93,7 @@ const FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(
|
|
|
72
93
|
titleText,
|
|
73
94
|
type,
|
|
74
95
|
selectionFeedback = 'top-after-reopen',
|
|
96
|
+
selectedItems: selected,
|
|
75
97
|
size,
|
|
76
98
|
sortItems = sorting.defaultSortItems,
|
|
77
99
|
translateWithId,
|
|
@@ -84,20 +106,41 @@ const FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(
|
|
|
84
106
|
isFluid
|
|
85
107
|
} = React.useContext(FormContext.FormContext);
|
|
86
108
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
87
|
-
const [isOpen, setIsOpen] = React.useState(open);
|
|
88
|
-
const [prevOpen, setPrevOpen] = React.useState(open);
|
|
109
|
+
const [isOpen, setIsOpen] = React.useState(!!open);
|
|
110
|
+
const [prevOpen, setPrevOpen] = React.useState(!!open);
|
|
89
111
|
const [inputValue, setInputValue] = React.useState('');
|
|
90
112
|
const [topItems, setTopItems] = React.useState(initialSelectedItems ?? []);
|
|
91
113
|
const [inputFocused, setInputFocused] = React.useState(false);
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
114
|
+
const {
|
|
115
|
+
selectedItems: controlledSelectedItems,
|
|
116
|
+
onItemChange,
|
|
117
|
+
clearSelection
|
|
118
|
+
} = Selection.useSelection({
|
|
119
|
+
disabled,
|
|
120
|
+
initialSelectedItems,
|
|
121
|
+
onChange,
|
|
122
|
+
selectedItems: selected
|
|
123
|
+
});
|
|
124
|
+
const textInput = React.useRef(null);
|
|
95
125
|
const filterableMultiSelectInstanceId = useId.useId();
|
|
96
126
|
const prefix = usePrefix.usePrefix();
|
|
97
127
|
if (prevOpen !== open) {
|
|
98
128
|
setIsOpen(open);
|
|
99
129
|
setPrevOpen(open);
|
|
100
130
|
}
|
|
131
|
+
const sortedItems = sortItems(filterItems(items, {
|
|
132
|
+
itemToString: itemToString$1,
|
|
133
|
+
inputValue
|
|
134
|
+
}), {
|
|
135
|
+
selectedItems: {
|
|
136
|
+
top: controlledSelectedItems,
|
|
137
|
+
fixed: [],
|
|
138
|
+
'top-after-reopen': topItems
|
|
139
|
+
}[selectionFeedback],
|
|
140
|
+
itemToString: itemToString$1,
|
|
141
|
+
compareItems,
|
|
142
|
+
locale
|
|
143
|
+
});
|
|
101
144
|
const inline = type === 'inline';
|
|
102
145
|
const showWarning = !invalid && warn;
|
|
103
146
|
const wrapperClasses = cx__default["default"](`${prefix}--multi-select__wrapper`, `${prefix}--multi-select--filterable__wrapper`, `${prefix}--list-box__wrapper`, containerClassName, {
|
|
@@ -134,101 +177,170 @@ const FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(
|
|
|
134
177
|
const inputId = `${id}-input`;
|
|
135
178
|
React.useEffect(() => {
|
|
136
179
|
if (!isOpen) {
|
|
137
|
-
setTopItems(
|
|
180
|
+
setTopItems(controlledSelectedItems);
|
|
138
181
|
}
|
|
139
|
-
}, [
|
|
140
|
-
function
|
|
141
|
-
setCurrentSelectedItems(changes.selectedItems);
|
|
142
|
-
if (onChange) {
|
|
143
|
-
onChange(changes);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function handleOnMenuChange(forceIsOpen) {
|
|
182
|
+
}, [controlledSelectedItems, isOpen, setTopItems]);
|
|
183
|
+
function handleMenuChange(forceIsOpen) {
|
|
147
184
|
const nextIsOpen = forceIsOpen ?? !isOpen;
|
|
148
185
|
setIsOpen(nextIsOpen);
|
|
149
186
|
if (onMenuChange) {
|
|
150
187
|
onMenuChange(nextIsOpen);
|
|
151
188
|
}
|
|
152
|
-
if (!isOpen) {
|
|
153
|
-
setHighlightedIndex(0);
|
|
154
|
-
}
|
|
155
189
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
190
|
+
const {
|
|
191
|
+
getToggleButtonProps,
|
|
192
|
+
getLabelProps,
|
|
193
|
+
getMenuProps,
|
|
194
|
+
getInputProps,
|
|
195
|
+
highlightedIndex,
|
|
196
|
+
setHighlightedIndex,
|
|
197
|
+
getItemProps,
|
|
198
|
+
openMenu,
|
|
199
|
+
isOpen: isMenuOpen
|
|
200
|
+
} = Downshift.useCombobox({
|
|
201
|
+
isOpen,
|
|
202
|
+
items: sortedItems,
|
|
203
|
+
itemToString: itemToString$1,
|
|
204
|
+
defaultHighlightedIndex: 0,
|
|
205
|
+
// after selection, highlight the first item.
|
|
206
|
+
id,
|
|
207
|
+
labelId,
|
|
208
|
+
menuId,
|
|
209
|
+
inputId,
|
|
210
|
+
inputValue,
|
|
211
|
+
stateReducer,
|
|
212
|
+
isItemDisabled(item, _index) {
|
|
213
|
+
return item.disabled;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
function stateReducer(state, actionAndChanges) {
|
|
160
217
|
const {
|
|
161
|
-
type
|
|
162
|
-
|
|
218
|
+
type,
|
|
219
|
+
props,
|
|
220
|
+
changes
|
|
221
|
+
} = actionAndChanges;
|
|
163
222
|
const {
|
|
164
|
-
|
|
165
|
-
} =
|
|
223
|
+
highlightedIndex
|
|
224
|
+
} = changes;
|
|
225
|
+
if (changes.isOpen && !isOpen) {
|
|
226
|
+
setTopItems(controlledSelectedItems);
|
|
227
|
+
}
|
|
166
228
|
switch (type) {
|
|
167
|
-
case
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
case stateChangeTypes.keyDownEnd:
|
|
171
|
-
setHighlightedIndex(changes.highlightedIndex !== undefined ? changes.highlightedIndex : 0);
|
|
172
|
-
if (stateChangeTypes.keyDownArrowDown === type && !isOpen) {
|
|
173
|
-
handleOnMenuChange(true);
|
|
229
|
+
case InputKeyDownEnter:
|
|
230
|
+
if (changes.selectedItem && changes.selectedItem.disabled !== true) {
|
|
231
|
+
onItemChange(changes.selectedItem);
|
|
174
232
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
case
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
case stateChangeTypes.keyDownEnter:
|
|
184
|
-
if (!isOpen) {
|
|
185
|
-
setHighlightedIndex(0);
|
|
233
|
+
setHighlightedIndex(changes.selectedItem);
|
|
234
|
+
return {
|
|
235
|
+
...changes,
|
|
236
|
+
highlightedIndex: state.highlightedIndex
|
|
237
|
+
};
|
|
238
|
+
case ItemClick:
|
|
239
|
+
if (changes.selectedItem) {
|
|
240
|
+
onItemChange(changes.selectedItem);
|
|
186
241
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
242
|
+
setHighlightedIndex(changes.selectedItem);
|
|
243
|
+
return changes;
|
|
244
|
+
case InputBlur:
|
|
245
|
+
case InputKeyDownEscape:
|
|
246
|
+
setIsOpen(false);
|
|
247
|
+
return changes;
|
|
248
|
+
case FunctionToggleMenu:
|
|
249
|
+
case ToggleButtonClick:
|
|
250
|
+
if (changes.isOpen && !changes.selectedItem) {
|
|
251
|
+
return {
|
|
252
|
+
...changes,
|
|
253
|
+
highlightedIndex: 0
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
return changes;
|
|
257
|
+
case InputChange:
|
|
258
|
+
if (onInputValueChange) {
|
|
259
|
+
onInputValueChange(changes.inputValue);
|
|
260
|
+
}
|
|
261
|
+
setInputValue(changes.inputValue ?? '');
|
|
262
|
+
setIsOpen(true);
|
|
263
|
+
return changes;
|
|
264
|
+
case InputClick:
|
|
265
|
+
return {
|
|
266
|
+
...changes,
|
|
267
|
+
isOpen: false
|
|
268
|
+
};
|
|
269
|
+
case MenuMouseLeave:
|
|
270
|
+
return {
|
|
271
|
+
...changes,
|
|
272
|
+
highlightedIndex: state.highlightedIndex
|
|
273
|
+
};
|
|
274
|
+
case InputKeyDownArrowUp:
|
|
275
|
+
case InputKeyDownArrowDown:
|
|
276
|
+
if (InputKeyDownArrowDown === type && !isOpen) {
|
|
277
|
+
setIsOpen(true);
|
|
205
278
|
}
|
|
206
|
-
|
|
279
|
+
if (highlightedIndex > -1) {
|
|
280
|
+
const itemArray = document.querySelectorAll(`li.${prefix}--list-box__menu-item[role="option"]`);
|
|
281
|
+
props.scrollIntoView(itemArray[highlightedIndex]);
|
|
282
|
+
}
|
|
283
|
+
if (highlightedIndex === -1) {
|
|
284
|
+
return {
|
|
285
|
+
...changes,
|
|
286
|
+
highlightedIndex: 0
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return changes;
|
|
290
|
+
case ItemMouseMove:
|
|
291
|
+
return {
|
|
292
|
+
...changes,
|
|
293
|
+
highlightedIndex: state.highlightedIndex
|
|
294
|
+
};
|
|
295
|
+
case FunctionSetHighlightedIndex:
|
|
296
|
+
if (!isOpen) {
|
|
297
|
+
return {
|
|
298
|
+
...changes,
|
|
299
|
+
highlightedIndex: 0
|
|
300
|
+
};
|
|
301
|
+
} else {
|
|
302
|
+
return {
|
|
303
|
+
...changes,
|
|
304
|
+
highlightedIndex: props.items.indexOf(highlightedIndex)
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
default:
|
|
308
|
+
return changes;
|
|
207
309
|
}
|
|
208
310
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
311
|
+
const {
|
|
312
|
+
getDropdownProps
|
|
313
|
+
} = Downshift.useMultipleSelection({
|
|
314
|
+
...downshiftProps,
|
|
315
|
+
activeIndex: highlightedIndex,
|
|
316
|
+
initialSelectedItems,
|
|
317
|
+
selectedItems: controlledSelectedItems,
|
|
318
|
+
itemToString: itemToString$1,
|
|
319
|
+
onStateChange(changes) {
|
|
320
|
+
switch (changes.type) {
|
|
321
|
+
case SelectedItemKeyDownBackspace:
|
|
322
|
+
case SelectedItemKeyDownDelete:
|
|
323
|
+
case DropdownKeyDownBackspace:
|
|
324
|
+
case FunctionRemoveSelectedItem:
|
|
325
|
+
{
|
|
326
|
+
clearSelection();
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
215
330
|
}
|
|
216
|
-
|
|
217
|
-
|
|
331
|
+
});
|
|
332
|
+
React.useEffect(() => {
|
|
333
|
+
if (isOpen && !isMenuOpen) {
|
|
334
|
+
openMenu();
|
|
218
335
|
}
|
|
219
|
-
|
|
220
|
-
|
|
336
|
+
});
|
|
337
|
+
function clearInputValue(event) {
|
|
338
|
+
const value = textInput.current?.value;
|
|
339
|
+
if (value?.length === 1 || event && match.match(event, keys.Escape)) {
|
|
340
|
+
setInputValue('');
|
|
221
341
|
} else {
|
|
222
|
-
setInputValue(
|
|
223
|
-
}
|
|
224
|
-
if (inputValue && !isOpen) {
|
|
225
|
-
handleOnMenuChange(true);
|
|
226
|
-
} else if (!inputValue && isOpen) {
|
|
227
|
-
handleOnMenuChange(false);
|
|
342
|
+
setInputValue(value ?? '');
|
|
228
343
|
}
|
|
229
|
-
}
|
|
230
|
-
function clearInputValue(event) {
|
|
231
|
-
textInput.current.value.length === 1 || match.match(event, keys.Escape) ? setInputValue('') : setInputValue(textInput.current.value);
|
|
232
344
|
if (textInput.current) {
|
|
233
345
|
textInput.current.focus();
|
|
234
346
|
}
|
|
@@ -241,239 +353,197 @@ const FilterableMultiSelect = /*#__PURE__*/React__default["default"].forwardRef(
|
|
|
241
353
|
size: 'mini'
|
|
242
354
|
});
|
|
243
355
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
// When we moved the "root node" of Downshift to the <input> for
|
|
305
|
-
// ARIA 1.2 compliance, we unfortunately hit this branch for the
|
|
306
|
-
// "mouseup" event that downshift listens to:
|
|
307
|
-
// https://github.com/downshift-js/downshift/blob/v5.2.1/src/downshift.js#L1051-L1065
|
|
308
|
-
//
|
|
309
|
-
// As a result, it will reset the state of the component and so we
|
|
310
|
-
// stop the event from propagating to prevent this. This allows the
|
|
311
|
-
// toggleMenu behavior for the toggleButton to correctly open and
|
|
312
|
-
// close the menu.
|
|
313
|
-
onMouseUp(event) {
|
|
314
|
-
if (isOpen) {
|
|
315
|
-
event.stopPropagation();
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
const inputProps = getInputProps({
|
|
320
|
-
'aria-controls': isOpen ? menuId : null,
|
|
321
|
-
'aria-describedby': helperText ? helperId : null,
|
|
322
|
-
// Remove excess aria `aria-labelledby`. HTML <label for>
|
|
323
|
-
// provides this aria information.
|
|
324
|
-
'aria-labelledby': null,
|
|
325
|
-
disabled,
|
|
326
|
-
placeholder,
|
|
327
|
-
onClick: () => {
|
|
328
|
-
handleOnMenuChange(true);
|
|
329
|
-
},
|
|
330
|
-
onKeyDown: event => {
|
|
331
|
-
if (match.match(event, keys.Space)) {
|
|
332
|
-
event.stopPropagation();
|
|
333
|
-
}
|
|
334
|
-
if (match.match(event, keys.Enter)) {
|
|
335
|
-
handleOnMenuChange(true);
|
|
336
|
-
}
|
|
337
|
-
if (!disabled) {
|
|
338
|
-
if (match.match(event, keys.Delete) || match.match(event, keys.Escape)) {
|
|
339
|
-
if (isOpen) {
|
|
340
|
-
handleOnMenuChange(true);
|
|
341
|
-
clearInputValue(event);
|
|
342
|
-
event.stopPropagation();
|
|
343
|
-
} else if (!isOpen) {
|
|
344
|
-
clearInputValue(event);
|
|
345
|
-
clearSelection();
|
|
346
|
-
event.stopPropagation();
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
if (match.match(event, keys.Tab)) {
|
|
351
|
-
handleOnMenuChange(false);
|
|
352
|
-
}
|
|
353
|
-
if (match.match(event, keys.Home) && event.code !== 'Numpad7') {
|
|
354
|
-
event.target.setSelectionRange(0, 0);
|
|
355
|
-
}
|
|
356
|
-
if (match.match(event, keys.End) && event.code !== 'Numpad1') {
|
|
357
|
-
event.target.setSelectionRange(event.target.value.length, event.target.value.length);
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
onFocus: () => {
|
|
361
|
-
setInputFocused(true);
|
|
362
|
-
},
|
|
363
|
-
onBlur: () => {
|
|
364
|
-
setInputFocused(false);
|
|
365
|
-
setInputValue('');
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
const menuProps = getMenuProps({}, {
|
|
369
|
-
suppressRefError: true
|
|
370
|
-
});
|
|
371
|
-
const handleFocus = evt => {
|
|
372
|
-
if (evt.target.classList.contains(`${prefix}--tag__close-icon`) || evt.target.classList.contains(`${prefix}--list-box__selection`)) {
|
|
373
|
-
setIsFocused(false);
|
|
374
|
-
} else {
|
|
375
|
-
setIsFocused(evt.type === 'focus' ? true : false);
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
const clearSelectionContent = selectedItems.length > 0 ? /*#__PURE__*/React__default["default"].createElement("span", {
|
|
379
|
-
className: `${prefix}--visually-hidden`
|
|
380
|
-
}, clearSelectionDescription, " ", selectedItems.length, ",", clearSelectionText) : /*#__PURE__*/React__default["default"].createElement("span", {
|
|
381
|
-
className: `${prefix}--visually-hidden`
|
|
382
|
-
}, clearSelectionDescription, ": 0");
|
|
383
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
384
|
-
className: wrapperClasses
|
|
385
|
-
}, titleText ? /*#__PURE__*/React__default["default"].createElement("label", _rollupPluginBabelHelpers["extends"]({
|
|
386
|
-
className: titleClasses
|
|
387
|
-
}, labelProps), titleText, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
388
|
-
className: `${prefix}--visually-hidden`
|
|
389
|
-
}, clearSelectionContent)) : null, /*#__PURE__*/React__default["default"].createElement(index["default"], {
|
|
390
|
-
onFocus: isFluid ? handleFocus : null,
|
|
391
|
-
onBlur: isFluid ? handleFocus : null,
|
|
392
|
-
className: className,
|
|
393
|
-
disabled: disabled,
|
|
394
|
-
light: light,
|
|
395
|
-
ref: ref,
|
|
396
|
-
invalid: invalid,
|
|
397
|
-
invalidText: invalidText,
|
|
398
|
-
warn: warn,
|
|
399
|
-
warnText: warnText,
|
|
400
|
-
isOpen: isOpen,
|
|
401
|
-
size: size
|
|
402
|
-
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
403
|
-
className: `${prefix}--list-box__field`
|
|
404
|
-
}, selectedItem.length > 0 && /*#__PURE__*/React__default["default"].createElement(ListBoxSelection["default"], {
|
|
405
|
-
clearSelection: () => {
|
|
356
|
+
const className = cx__default["default"](`${prefix}--multi-select`, `${prefix}--combo-box`, `${prefix}--multi-select--filterable`, {
|
|
357
|
+
[`${prefix}--multi-select--invalid`]: invalid,
|
|
358
|
+
[`${prefix}--multi-select--invalid--focused`]: invalid && inputFocused,
|
|
359
|
+
[`${prefix}--multi-select--open`]: isOpen,
|
|
360
|
+
[`${prefix}--multi-select--inline`]: inline,
|
|
361
|
+
[`${prefix}--multi-select--selected`]: controlledSelectedItems?.length > 0,
|
|
362
|
+
[`${prefix}--multi-select--filterable--input-focused`]: inputFocused
|
|
363
|
+
});
|
|
364
|
+
const labelProps = getLabelProps();
|
|
365
|
+
const buttonProps = getToggleButtonProps({
|
|
366
|
+
disabled,
|
|
367
|
+
onClick: () => {
|
|
368
|
+
handleMenuChange(!isOpen);
|
|
369
|
+
textInput.current?.focus();
|
|
370
|
+
},
|
|
371
|
+
// When we moved the "root node" of Downshift to the <input> for
|
|
372
|
+
// ARIA 1.2 compliance, we unfortunately hit this branch for the
|
|
373
|
+
// "mouseup" event that downshift listens to:
|
|
374
|
+
// https://github.com/downshift-js/downshift/blob/v5.2.1/src/downshift.js#L1051-L1065
|
|
375
|
+
//
|
|
376
|
+
// As a result, it will reset the state of the component and so we
|
|
377
|
+
// stop the event from propagating to prevent this. This allows the
|
|
378
|
+
// toggleMenu behavior for the toggleButton to correctly open and
|
|
379
|
+
// close the menu.
|
|
380
|
+
onMouseUp(event) {
|
|
381
|
+
if (isOpen) {
|
|
382
|
+
event.stopPropagation();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
const inputProps = getInputProps(getDropdownProps({
|
|
387
|
+
'aria-controls': isOpen ? menuId : undefined,
|
|
388
|
+
'aria-describedby': helperText ? helperId : undefined,
|
|
389
|
+
'aria-haspopup': 'listbox',
|
|
390
|
+
// Remove excess aria `aria-labelledby`. HTML <label for>
|
|
391
|
+
// provides this aria information.
|
|
392
|
+
'aria-labelledby': undefined,
|
|
393
|
+
disabled,
|
|
394
|
+
placeholder,
|
|
395
|
+
preventKeyAction: isOpen,
|
|
396
|
+
onClick: () => handleMenuChange(true),
|
|
397
|
+
onKeyDown(event) {
|
|
398
|
+
const $input = event.target;
|
|
399
|
+
const $value = $input.value;
|
|
400
|
+
if (match.match(event, keys.Space)) {
|
|
401
|
+
event.stopPropagation();
|
|
402
|
+
}
|
|
403
|
+
if (match.match(event, keys.Enter)) {
|
|
404
|
+
handleMenuChange(true);
|
|
405
|
+
}
|
|
406
|
+
if (!disabled) {
|
|
407
|
+
if (match.match(event, keys.Delete) || match.match(event, keys.Escape)) {
|
|
408
|
+
if (isOpen) {
|
|
409
|
+
handleMenuChange(true);
|
|
410
|
+
clearInputValue(event);
|
|
411
|
+
event.stopPropagation();
|
|
412
|
+
} else if (!isOpen) {
|
|
413
|
+
clearInputValue(event);
|
|
406
414
|
clearSelection();
|
|
407
|
-
if (textInput.current) {
|
|
408
|
-
textInput.current.focus();
|
|
409
|
-
}
|
|
410
|
-
},
|
|
411
|
-
selectionCount: selectedItem.length,
|
|
412
|
-
translateWithId: translateWithId,
|
|
413
|
-
disabled: disabled
|
|
414
|
-
}), /*#__PURE__*/React__default["default"].createElement("input", _rollupPluginBabelHelpers["extends"]({
|
|
415
|
-
className: inputClasses
|
|
416
|
-
}, rootProps, inputProps, {
|
|
417
|
-
ref: mergeRefs["default"](textInput, rootProps.ref)
|
|
418
|
-
})), invalid && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningFilled, {
|
|
419
|
-
className: `${prefix}--list-box__invalid-icon`
|
|
420
|
-
}), showWarning && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningAltFilled, {
|
|
421
|
-
className: `${prefix}--list-box__invalid-icon ${prefix}--list-box__invalid-icon--warning`
|
|
422
|
-
}), inputValue && /*#__PURE__*/React__default["default"].createElement(ListBoxSelection["default"], {
|
|
423
|
-
clearSelection: clearInputValue,
|
|
424
|
-
disabled: disabled,
|
|
425
|
-
translateWithId: translateWithId,
|
|
426
|
-
onMouseUp: event => {
|
|
427
|
-
// If we do not stop this event from propagating,
|
|
428
|
-
// it seems like Downshift takes our event and
|
|
429
|
-
// prevents us from getting `onClick` /
|
|
430
|
-
// `clearSelection` from the underlying <button> in
|
|
431
|
-
// ListBoxSelection
|
|
432
415
|
event.stopPropagation();
|
|
433
416
|
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const isChecked = selectedItem.filter(selected => isEqual__default["default"](selected, item)).length > 0;
|
|
451
|
-
const itemProps = getItemProps({
|
|
452
|
-
item,
|
|
453
|
-
disabled: item.disabled,
|
|
454
|
-
['aria-selected']: isChecked
|
|
455
|
-
});
|
|
456
|
-
const itemText = itemToString$1(item);
|
|
457
|
-
return /*#__PURE__*/React__default["default"].createElement(index["default"].MenuItem, _rollupPluginBabelHelpers["extends"]({
|
|
458
|
-
key: itemProps.id,
|
|
459
|
-
"aria-label": itemText,
|
|
460
|
-
isActive: isChecked,
|
|
461
|
-
isHighlighted: highlightedIndex === index$1,
|
|
462
|
-
title: itemText
|
|
463
|
-
}, itemProps), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
464
|
-
className: `${prefix}--checkbox-wrapper`
|
|
465
|
-
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
466
|
-
title: useTitleInItem ? itemText : null,
|
|
467
|
-
className: `${prefix}--checkbox-label`,
|
|
468
|
-
"data-contained-checkbox-state": isChecked,
|
|
469
|
-
id: `${itemProps.id}-item`
|
|
470
|
-
}, ItemToElement ? /*#__PURE__*/React__default["default"].createElement(ItemToElement, _rollupPluginBabelHelpers["extends"]({
|
|
471
|
-
key: itemProps.id
|
|
472
|
-
}, item)) : itemText)));
|
|
473
|
-
})) : null), !inline && !invalid && !warn ? helper : null);
|
|
474
|
-
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (match.match(event, keys.Tab)) {
|
|
420
|
+
handleMenuChange(false);
|
|
421
|
+
}
|
|
422
|
+
if (match.match(event, keys.Home)) {
|
|
423
|
+
$input.setSelectionRange(0, 0);
|
|
424
|
+
}
|
|
425
|
+
if (match.match(event, keys.End)) {
|
|
426
|
+
$input.setSelectionRange($value.length, $value.length);
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
onFocus: () => setInputFocused(true),
|
|
430
|
+
onBlur() {
|
|
431
|
+
setInputFocused(false);
|
|
432
|
+
setInputValue('');
|
|
475
433
|
}
|
|
434
|
+
}));
|
|
435
|
+
const menuProps = getMenuProps({}, {
|
|
436
|
+
suppressRefError: true
|
|
476
437
|
});
|
|
438
|
+
const handleFocus = evt => {
|
|
439
|
+
if (evt?.target.classList.contains(`${prefix}--tag__close-icon`) || evt?.target.classList.contains(`${prefix}--list-box__selection`)) {
|
|
440
|
+
setIsFocused(false);
|
|
441
|
+
} else {
|
|
442
|
+
setIsFocused(evt?.type === 'focus' ? true : false);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const clearSelectionContent = controlledSelectedItems.length > 0 ? /*#__PURE__*/React__default["default"].createElement("span", {
|
|
446
|
+
className: `${prefix}--visually-hidden`
|
|
447
|
+
}, clearSelectionDescription, " ", controlledSelectedItems.length, ",", clearSelectionText) : /*#__PURE__*/React__default["default"].createElement("span", {
|
|
448
|
+
className: `${prefix}--visually-hidden`
|
|
449
|
+
}, clearSelectionDescription, ": 0");
|
|
450
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
451
|
+
className: wrapperClasses
|
|
452
|
+
}, titleText ? /*#__PURE__*/React__default["default"].createElement("label", _rollupPluginBabelHelpers["extends"]({
|
|
453
|
+
className: titleClasses
|
|
454
|
+
}, labelProps), titleText, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
455
|
+
className: `${prefix}--visually-hidden`
|
|
456
|
+
}, clearSelectionContent)) : null, /*#__PURE__*/React__default["default"].createElement(index["default"], {
|
|
457
|
+
onFocus: isFluid ? handleFocus : undefined,
|
|
458
|
+
onBlur: isFluid ? handleFocus : undefined,
|
|
459
|
+
className: className,
|
|
460
|
+
disabled: disabled,
|
|
461
|
+
light: light,
|
|
462
|
+
ref: ref,
|
|
463
|
+
invalid: invalid,
|
|
464
|
+
invalidText: invalidText,
|
|
465
|
+
warn: warn,
|
|
466
|
+
warnText: warnText,
|
|
467
|
+
isOpen: isOpen,
|
|
468
|
+
size: size
|
|
469
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
470
|
+
className: `${prefix}--list-box__field`
|
|
471
|
+
}, controlledSelectedItems.length > 0 &&
|
|
472
|
+
/*#__PURE__*/
|
|
473
|
+
// @ts-expect-error: It is expecting a non-required prop called: "onClearSelection"
|
|
474
|
+
React__default["default"].createElement(ListBoxSelection["default"], {
|
|
475
|
+
clearSelection: () => {
|
|
476
|
+
clearSelection();
|
|
477
|
+
if (textInput.current) {
|
|
478
|
+
textInput.current.focus();
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
selectionCount: controlledSelectedItems.length,
|
|
482
|
+
translateWithId: translateWithId,
|
|
483
|
+
disabled: disabled
|
|
484
|
+
}), /*#__PURE__*/React__default["default"].createElement("input", _rollupPluginBabelHelpers["extends"]({
|
|
485
|
+
className: inputClasses
|
|
486
|
+
}, inputProps, {
|
|
487
|
+
ref: mergeRefs["default"](textInput, inputProps.ref)
|
|
488
|
+
})), invalid && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningFilled, {
|
|
489
|
+
className: `${prefix}--list-box__invalid-icon`
|
|
490
|
+
}), showWarning && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningAltFilled, {
|
|
491
|
+
className: `${prefix}--list-box__invalid-icon ${prefix}--list-box__invalid-icon--warning`
|
|
492
|
+
}), inputValue &&
|
|
493
|
+
/*#__PURE__*/
|
|
494
|
+
// @ts-expect-error: It is expecting two non-required prop called: "onClearSelection" & "selectionCount"
|
|
495
|
+
React__default["default"].createElement(ListBoxSelection["default"], {
|
|
496
|
+
clearSelection: clearInputValue,
|
|
497
|
+
disabled: disabled,
|
|
498
|
+
translateWithId: translateWithId,
|
|
499
|
+
onMouseUp: event => {
|
|
500
|
+
// If we do not stop this event from propagating,
|
|
501
|
+
// it seems like Downshift takes our event and
|
|
502
|
+
// prevents us from getting `onClick` /
|
|
503
|
+
// `clearSelection` from the underlying <button> in
|
|
504
|
+
// ListBoxSelection
|
|
505
|
+
event.stopPropagation();
|
|
506
|
+
}
|
|
507
|
+
}), /*#__PURE__*/React__default["default"].createElement(ListBoxTrigger["default"], _rollupPluginBabelHelpers["extends"]({}, buttonProps, {
|
|
508
|
+
// @ts-expect-error
|
|
509
|
+
isOpen: isOpen,
|
|
510
|
+
translateWithId: translateWithId
|
|
511
|
+
}))), normalizedSlug, /*#__PURE__*/React__default["default"].createElement(index["default"].Menu, menuProps, isOpen ? sortedItems.map((item, index$1) => {
|
|
512
|
+
const isChecked = controlledSelectedItems.filter(selected => isEqual__default["default"](selected, item)).length > 0;
|
|
513
|
+
const itemProps = getItemProps({
|
|
514
|
+
item,
|
|
515
|
+
['aria-selected']: isChecked
|
|
516
|
+
});
|
|
517
|
+
const itemText = itemToString$1(item);
|
|
518
|
+
|
|
519
|
+
// The initial implementation using <Downshift> would place the disabled attribute
|
|
520
|
+
// on disabled menu items. Conversely, useCombobox places aria-disabled instead.
|
|
521
|
+
// To avoid any potential breaking changes, we avoid placing aria-disabled and
|
|
522
|
+
// instead match the old behavior of placing the disabled attribute.
|
|
523
|
+
const disabled = itemProps['aria-disabled'];
|
|
524
|
+
const {
|
|
525
|
+
'aria-disabled': unusedAriaDisabled,
|
|
526
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
527
|
+
...modifiedItemProps
|
|
528
|
+
} = itemProps;
|
|
529
|
+
return /*#__PURE__*/React__default["default"].createElement(index["default"].MenuItem, _rollupPluginBabelHelpers["extends"]({
|
|
530
|
+
key: itemProps.id,
|
|
531
|
+
"aria-label": itemText,
|
|
532
|
+
isActive: isChecked,
|
|
533
|
+
isHighlighted: highlightedIndex === index$1,
|
|
534
|
+
title: itemText,
|
|
535
|
+
disabled: disabled
|
|
536
|
+
}, modifiedItemProps), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
537
|
+
className: `${prefix}--checkbox-wrapper`
|
|
538
|
+
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
539
|
+
title: useTitleInItem ? itemText : undefined,
|
|
540
|
+
className: `${prefix}--checkbox-label`,
|
|
541
|
+
"data-contained-checkbox-state": isChecked,
|
|
542
|
+
id: `${itemProps.id}-item`
|
|
543
|
+
}, ItemToElement ? /*#__PURE__*/React__default["default"].createElement(ItemToElement, _rollupPluginBabelHelpers["extends"]({
|
|
544
|
+
key: itemProps.id
|
|
545
|
+
}, item)) : itemText)));
|
|
546
|
+
}) : null)), !inline && !invalid && !warn ? helper : null);
|
|
477
547
|
});
|
|
478
548
|
FilterableMultiSelect.propTypes = {
|
|
479
549
|
/**
|
|
@@ -505,6 +575,7 @@ FilterableMultiSelect.propTypes = {
|
|
|
505
575
|
/**
|
|
506
576
|
* Additional props passed to Downshift
|
|
507
577
|
*/
|
|
578
|
+
// @ts-ignore
|
|
508
579
|
downshiftProps: PropTypes__default["default"].shape(Downshift__default["default"].propTypes),
|
|
509
580
|
/**
|
|
510
581
|
* Specify whether the title text should be hidden or not
|
|
@@ -592,6 +663,11 @@ FilterableMultiSelect.propTypes = {
|
|
|
592
663
|
*/
|
|
593
664
|
slug: PropTypes__default["default"].node,
|
|
594
665
|
...MultiSelectPropTypes.sortingPropTypes,
|
|
666
|
+
/**
|
|
667
|
+
* Provide text to be used in a `<label>` element that is tied to the
|
|
668
|
+
* combobox via ARIA attributes.
|
|
669
|
+
*/
|
|
670
|
+
titleText: PropTypes__default["default"].node,
|
|
595
671
|
/**
|
|
596
672
|
* Callback function for translating ListBoxMenuIcon SVG title
|
|
597
673
|
*/
|
|
@@ -609,6 +685,5 @@ FilterableMultiSelect.propTypes = {
|
|
|
609
685
|
*/
|
|
610
686
|
warnText: PropTypes__default["default"].node
|
|
611
687
|
};
|
|
612
|
-
var FilterableMultiSelect$1 = FilterableMultiSelect;
|
|
613
688
|
|
|
614
|
-
exports["default"] = FilterableMultiSelect
|
|
689
|
+
exports["default"] = FilterableMultiSelect;
|