@carbon/react 1.57.0-rc.0 → 1.58.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +1022 -1028
- package/es/components/Button/Button.js +2 -2
- 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 -260
- package/es/components/ComposedModal/ComposedModal.d.ts +1 -2
- 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/TableHeader.d.ts +4 -5
- package/es/components/DataTable/TableSlugRow.d.ts +3 -2
- package/es/components/DataTable/stories/examples/TableToolbarFilter.d.ts +51 -0
- package/es/components/DatePicker/DatePicker.d.ts +9 -9
- package/es/components/DatePicker/plugins/rangePlugin.js +5 -6
- package/es/components/Dialog/index.d.ts +31 -0
- package/es/components/Dropdown/Dropdown.d.ts +5 -6
- package/es/components/IconButton/index.d.ts +3 -4
- package/es/components/ListBox/next/ListBoxTrigger.js +5 -3
- 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/MultiSelect/FilterableMultiSelect.d.ts +176 -0
- package/es/components/MultiSelect/FilterableMultiSelect.js +388 -313
- package/es/components/MultiSelect/MultiSelect.d.ts +10 -9
- 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/Notification/Notification.d.ts +2 -2
- package/es/components/NumberInput/NumberInput.d.ts +1 -2
- package/es/components/Pagination/Pagination.js +9 -9
- 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/RadioButton/RadioButton.d.ts +7 -4
- package/es/components/RadioButton/RadioButton.js +7 -1
- package/es/components/RadioButtonGroup/RadioButtonGroup.d.ts +11 -8
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +7 -1
- 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/Tag/DismissibleTag.d.ts +3 -3
- package/es/components/Tag/OperationalTag.d.ts +3 -3
- package/es/components/Tag/SelectableTag.d.ts +3 -3
- package/es/components/Tag/Tag.d.ts +3 -3
- package/es/components/TextArea/TextArea.d.ts +6 -7
- 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/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/TimePicker/TimePicker.js +1 -1
- package/es/components/Toggle/Toggle.js +1 -1
- package/es/components/Tooltip/DefinitionTooltip.js +1 -1
- package/es/index.js +7 -5
- package/es/prop-types/deprecateValuesWithin.js +35 -0
- package/lib/components/Button/Button.js +2 -2
- 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 -260
- package/lib/components/ComposedModal/ComposedModal.d.ts +1 -2
- 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/TableHeader.d.ts +4 -5
- package/lib/components/DataTable/TableSlugRow.d.ts +3 -2
- package/lib/components/DataTable/stories/examples/TableToolbarFilter.d.ts +51 -0
- package/lib/components/DatePicker/DatePicker.d.ts +9 -9
- package/lib/components/DatePicker/plugins/rangePlugin.js +5 -6
- package/lib/components/Dialog/index.d.ts +31 -0
- package/lib/components/Dropdown/Dropdown.d.ts +5 -6
- package/lib/components/IconButton/index.d.ts +3 -4
- package/lib/components/ListBox/next/ListBoxTrigger.js +5 -3
- 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/MultiSelect/FilterableMultiSelect.d.ts +176 -0
- package/lib/components/MultiSelect/FilterableMultiSelect.js +387 -312
- package/lib/components/MultiSelect/MultiSelect.d.ts +10 -9
- 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/Notification/Notification.d.ts +2 -2
- package/lib/components/NumberInput/NumberInput.d.ts +1 -2
- package/lib/components/Pagination/Pagination.js +9 -9
- 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/RadioButton/RadioButton.d.ts +7 -4
- package/lib/components/RadioButton/RadioButton.js +7 -1
- package/lib/components/RadioButtonGroup/RadioButtonGroup.d.ts +11 -8
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +7 -1
- 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/Tag/DismissibleTag.d.ts +3 -3
- package/lib/components/Tag/OperationalTag.d.ts +3 -3
- package/lib/components/Tag/SelectableTag.d.ts +3 -3
- package/lib/components/Tag/Tag.d.ts +3 -3
- package/lib/components/TextArea/TextArea.d.ts +6 -7
- 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/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/TimePicker/TimePicker.js +1 -1
- package/lib/components/Toggle/Toggle.js +1 -1
- package/lib/components/Tooltip/DefinitionTooltip.js +1 -1
- package/lib/index.js +34 -31
- package/lib/prop-types/deprecateValuesWithin.js +39 -0
- package/package.json +8 -8
- package/es/components/TileGroup/index.js +0 -13
- package/lib/components/TileGroup/index.js +0 -18
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import cx from 'classnames';
|
|
10
|
-
import
|
|
10
|
+
import { useCombobox } from 'downshift';
|
|
11
11
|
import PropTypes from 'prop-types';
|
|
12
12
|
import React__default, { forwardRef, useContext, useRef, useState, useEffect } from 'react';
|
|
13
13
|
import '../Text/index.js';
|
|
@@ -19,24 +19,23 @@ import deprecate from '../../prop-types/deprecate.js';
|
|
|
19
19
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
20
20
|
import '../FluidForm/FluidForm.js';
|
|
21
21
|
import { FormContext } from '../FluidForm/FormContext.js';
|
|
22
|
-
import { match } from '../../internal/keyboard/match.js';
|
|
23
22
|
import { Text } from '../Text/Text.js';
|
|
23
|
+
import { match } from '../../internal/keyboard/match.js';
|
|
24
24
|
import ListBoxSelection from '../ListBox/next/ListBoxSelection.js';
|
|
25
25
|
import ListBoxTrigger from '../ListBox/next/ListBoxTrigger.js';
|
|
26
26
|
import { ListBoxSize } from '../ListBox/ListBoxPropTypes.js';
|
|
27
27
|
import { Space, Enter, Escape, Home, End } from '../../internal/keyboard/keys.js';
|
|
28
28
|
|
|
29
29
|
const {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} = Downshift.stateChangeTypes;
|
|
30
|
+
InputBlur,
|
|
31
|
+
InputKeyDownEnter,
|
|
32
|
+
FunctionToggleMenu,
|
|
33
|
+
ToggleButtonClick,
|
|
34
|
+
ItemMouseMove,
|
|
35
|
+
InputKeyDownArrowUp,
|
|
36
|
+
InputKeyDownArrowDown,
|
|
37
|
+
MenuMouseLeave
|
|
38
|
+
} = useCombobox.stateChangeTypes;
|
|
40
39
|
const defaultItemToString = item => {
|
|
41
40
|
if (typeof item === 'string') {
|
|
42
41
|
return item;
|
|
@@ -76,7 +75,7 @@ const findHighlightedIndex = (_ref2, inputValue) => {
|
|
|
76
75
|
const searchValue = inputValue.toLowerCase();
|
|
77
76
|
for (let i = 0; i < items.length; i++) {
|
|
78
77
|
const item = itemToString(items[i]).toLowerCase();
|
|
79
|
-
if (item.indexOf(searchValue) !== -1) {
|
|
78
|
+
if (!items[i]['disabled'] && item.indexOf(searchValue) !== -1) {
|
|
80
79
|
return i;
|
|
81
80
|
}
|
|
82
81
|
}
|
|
@@ -84,7 +83,6 @@ const findHighlightedIndex = (_ref2, inputValue) => {
|
|
|
84
83
|
};
|
|
85
84
|
const getInstanceId = setupGetInstanceId();
|
|
86
85
|
const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
87
|
-
var _Text;
|
|
88
86
|
const {
|
|
89
87
|
['aria-label']: ariaLabel = 'Choose an item',
|
|
90
88
|
ariaLabel: deprecatedAriaLabel,
|
|
@@ -106,7 +104,7 @@ const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
106
104
|
onToggleClick,
|
|
107
105
|
placeholder,
|
|
108
106
|
readOnly,
|
|
109
|
-
selectedItem,
|
|
107
|
+
selectedItem: selectedItemProp,
|
|
110
108
|
shouldFilterItem = defaultShouldFilterItem,
|
|
111
109
|
size,
|
|
112
110
|
titleText,
|
|
@@ -127,21 +125,20 @@ const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
127
125
|
initialSelectedItem,
|
|
128
126
|
inputValue: '',
|
|
129
127
|
itemToString,
|
|
130
|
-
selectedItem
|
|
128
|
+
selectedItem: selectedItemProp
|
|
131
129
|
}));
|
|
132
130
|
const [isFocused, setIsFocused] = useState(false);
|
|
133
131
|
const [prevSelectedItem, setPrevSelectedItem] = useState();
|
|
134
132
|
const [doneInitialSelectedItem, setDoneInitialSelectedItem] = useState(false);
|
|
135
|
-
const [highlightedIndex, setHighlightedIndex] = useState();
|
|
136
133
|
const savedOnInputChange = useRef(onInputChange);
|
|
137
|
-
if (!doneInitialSelectedItem || prevSelectedItem !==
|
|
134
|
+
if (!doneInitialSelectedItem || prevSelectedItem !== selectedItemProp) {
|
|
138
135
|
setDoneInitialSelectedItem(true);
|
|
139
|
-
setPrevSelectedItem(
|
|
136
|
+
setPrevSelectedItem(selectedItemProp);
|
|
140
137
|
setInputValue(getInputValue({
|
|
141
138
|
initialSelectedItem,
|
|
142
139
|
inputValue,
|
|
143
140
|
itemToString,
|
|
144
|
-
selectedItem
|
|
141
|
+
selectedItem: selectedItemProp
|
|
145
142
|
}));
|
|
146
143
|
}
|
|
147
144
|
const filterItems = (items, itemToString, inputValue) => items.filter(item => shouldFilterItem ? shouldFilterItem({
|
|
@@ -149,16 +146,6 @@ const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
149
146
|
itemToString,
|
|
150
147
|
inputValue
|
|
151
148
|
}) : defaultShouldFilterItem());
|
|
152
|
-
const handleOnChange = selectedItem => {
|
|
153
|
-
if (onChange) {
|
|
154
|
-
onChange({
|
|
155
|
-
selectedItem
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const handleOnInputValueChange = inputValue => {
|
|
160
|
-
setInputValue(inputValue || '');
|
|
161
|
-
};
|
|
162
149
|
useEffect(() => {
|
|
163
150
|
savedOnInputChange.current = onInputChange;
|
|
164
151
|
}, [onInputChange]);
|
|
@@ -172,62 +159,80 @@ const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
172
159
|
textInput.current.focus();
|
|
173
160
|
}
|
|
174
161
|
};
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const indexToHighlight = findHighlightedIndex({
|
|
182
|
-
...props,
|
|
183
|
-
items: filteredItems
|
|
184
|
-
}, inputValue);
|
|
185
|
-
setHighlightedIndex(indexToHighlight);
|
|
186
|
-
return indexToHighlight;
|
|
187
|
-
}
|
|
188
|
-
return highlightedIndex || 0;
|
|
189
|
-
};
|
|
190
|
-
const handleOnStateChange = (changes, _ref3) => {
|
|
191
|
-
let {
|
|
192
|
-
setHighlightedIndex: updateHighlightedIndex
|
|
193
|
-
} = _ref3;
|
|
162
|
+
const filteredItems = inputValue => filterItems(items, itemToString, inputValue || null);
|
|
163
|
+
const indexToHighlight = inputValue => findHighlightedIndex({
|
|
164
|
+
...props,
|
|
165
|
+
items: filteredItems(inputValue)
|
|
166
|
+
}, inputValue);
|
|
167
|
+
const stateReducer = React__default.useCallback((state, actionAndChanges) => {
|
|
194
168
|
const {
|
|
195
|
-
type
|
|
169
|
+
type,
|
|
170
|
+
changes
|
|
171
|
+
} = actionAndChanges;
|
|
172
|
+
const {
|
|
173
|
+
highlightedIndex
|
|
196
174
|
} = changes;
|
|
197
175
|
switch (type) {
|
|
198
|
-
case
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
176
|
+
case InputBlur:
|
|
177
|
+
if (state.inputValue && highlightedIndex == '-1' && !allowCustomValue) {
|
|
178
|
+
return {
|
|
179
|
+
...changes,
|
|
180
|
+
inputValue: ''
|
|
181
|
+
};
|
|
204
182
|
}
|
|
205
|
-
|
|
206
|
-
case
|
|
207
|
-
case keyDownEscape:
|
|
208
|
-
setHighlightedIndex(changes.highlightedIndex);
|
|
209
|
-
break;
|
|
210
|
-
case changeInput:
|
|
211
|
-
updateHighlightedIndex(getHighlightedIndex(changes));
|
|
212
|
-
break;
|
|
213
|
-
case blurInput:
|
|
183
|
+
return changes;
|
|
184
|
+
case InputKeyDownEnter:
|
|
214
185
|
if (allowCustomValue) {
|
|
215
186
|
setInputValue(inputValue);
|
|
187
|
+
setHighlightedIndex(changes.selectedItem);
|
|
216
188
|
if (onChange) {
|
|
217
189
|
onChange({
|
|
218
|
-
selectedItem
|
|
219
|
-
inputValue
|
|
190
|
+
selectedItem: changes.selectedItem
|
|
220
191
|
});
|
|
221
192
|
}
|
|
193
|
+
return changes;
|
|
194
|
+
} else if (changes.selectedItem && !allowCustomValue) {
|
|
195
|
+
return changes;
|
|
196
|
+
} else {
|
|
197
|
+
return {
|
|
198
|
+
...changes,
|
|
199
|
+
isOpen: true
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
case FunctionToggleMenu:
|
|
203
|
+
case ToggleButtonClick:
|
|
204
|
+
if (changes.isOpen && !changes.selectedItem) {
|
|
205
|
+
return {
|
|
206
|
+
...changes,
|
|
207
|
+
highlightedIndex: 0
|
|
208
|
+
};
|
|
222
209
|
}
|
|
223
|
-
|
|
224
|
-
case
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
210
|
+
return changes;
|
|
211
|
+
case MenuMouseLeave:
|
|
212
|
+
return {
|
|
213
|
+
...changes,
|
|
214
|
+
highlightedIndex: state.highlightedIndex
|
|
215
|
+
};
|
|
216
|
+
case InputKeyDownArrowUp:
|
|
217
|
+
case InputKeyDownArrowDown:
|
|
218
|
+
if (highlightedIndex === -1) {
|
|
219
|
+
return {
|
|
220
|
+
...changes,
|
|
221
|
+
highlightedIndex: 0
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
return changes;
|
|
225
|
+
case ItemMouseMove:
|
|
226
|
+
return {
|
|
227
|
+
...changes,
|
|
228
|
+
highlightedIndex: state.highlightedIndex
|
|
229
|
+
};
|
|
230
|
+
default:
|
|
231
|
+
return changes;
|
|
229
232
|
}
|
|
230
|
-
}
|
|
233
|
+
},
|
|
234
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
235
|
+
[allowCustomValue, inputValue, onChange]);
|
|
231
236
|
const handleToggleClick = isOpen => event => {
|
|
232
237
|
if (onToggleClick) {
|
|
233
238
|
onToggleClick(event);
|
|
@@ -272,204 +277,208 @@ const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
272
277
|
size: 'mini'
|
|
273
278
|
});
|
|
274
279
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
280
|
+
const {
|
|
281
|
+
getInputProps,
|
|
282
|
+
getItemProps,
|
|
283
|
+
getLabelProps,
|
|
284
|
+
getMenuProps,
|
|
285
|
+
getToggleButtonProps,
|
|
286
|
+
isOpen,
|
|
287
|
+
highlightedIndex,
|
|
288
|
+
selectItem,
|
|
289
|
+
selectedItem,
|
|
290
|
+
toggleMenu,
|
|
291
|
+
setHighlightedIndex
|
|
292
|
+
} = useCombobox({
|
|
293
|
+
...downshiftProps,
|
|
294
|
+
items,
|
|
295
|
+
inputValue: inputValue,
|
|
296
|
+
itemToString: item => {
|
|
297
|
+
return itemToString(item);
|
|
298
|
+
},
|
|
299
|
+
onInputValueChange(_ref3) {
|
|
300
|
+
let {
|
|
301
|
+
inputValue
|
|
302
|
+
} = _ref3;
|
|
303
|
+
setInputValue(inputValue || '');
|
|
304
|
+
setHighlightedIndex(indexToHighlight(inputValue));
|
|
305
|
+
},
|
|
306
|
+
onSelectedItemChange(_ref4) {
|
|
307
|
+
let {
|
|
308
|
+
selectedItem
|
|
309
|
+
} = _ref4;
|
|
310
|
+
onChange({
|
|
311
|
+
selectedItem
|
|
312
|
+
});
|
|
284
313
|
},
|
|
285
|
-
inputValue: inputValue || '',
|
|
286
|
-
itemToString: itemToString,
|
|
287
314
|
initialSelectedItem: initialSelectedItem,
|
|
288
315
|
inputId: id,
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
//
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const labelProps = getLabelProps();
|
|
310
|
-
const buttonProps = getToggleButtonProps({
|
|
311
|
-
disabled: disabled || readOnly,
|
|
312
|
-
onClick: handleToggleClick(isOpen),
|
|
313
|
-
// When we moved the "root node" of Downshift to the <input> for
|
|
314
|
-
// ARIA 1.2 compliance, we unfortunately hit this branch for the
|
|
315
|
-
// "mouseup" event that downshift listens to:
|
|
316
|
-
// https://github.com/downshift-js/downshift/blob/v5.2.1/src/downshift.js#L1051-L1065
|
|
317
|
-
//
|
|
318
|
-
// As a result, it will reset the state of the component and so we
|
|
319
|
-
// stop the event from propagating to prevent this if the menu is already open.
|
|
320
|
-
// This allows the toggleMenu behavior for the toggleButton to correctly open and
|
|
321
|
-
// close the menu.
|
|
322
|
-
onMouseUp(event) {
|
|
323
|
-
if (isOpen) {
|
|
324
|
-
event.stopPropagation();
|
|
325
|
-
}
|
|
316
|
+
stateReducer,
|
|
317
|
+
isItemDisabled(item, _index) {
|
|
318
|
+
return item.disabled;
|
|
319
|
+
}
|
|
320
|
+
});
|
|
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();
|
|
326
336
|
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
const handleFocus = evt => {
|
|
340
|
+
setIsFocused(evt.type === 'focus');
|
|
341
|
+
};
|
|
342
|
+
const readOnlyEventHandlers = readOnly ? {
|
|
343
|
+
onKeyDown: evt => {
|
|
344
|
+
// This prevents the select from opening for the above keys
|
|
345
|
+
if (evt.key !== 'Tab') {
|
|
346
|
+
evt.preventDefault();
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
} : {};
|
|
350
|
+
|
|
351
|
+
// The input should be described by the appropriate message text id
|
|
352
|
+
// when both the message is supplied *and* when the component is in
|
|
353
|
+
// the matching state (invalid, warn, etc).
|
|
354
|
+
const ariaDescribedBy = invalid && invalidText && invalidTextId || warn && warnText && warnTextId || helperText && !isFluid && helperTextId || undefined;
|
|
355
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
|
356
|
+
className: wrapperClasses
|
|
357
|
+
}, titleText && /*#__PURE__*/React__default.createElement(Text, _extends({
|
|
358
|
+
as: "label",
|
|
359
|
+
className: titleClasses
|
|
360
|
+
}, getLabelProps()), titleText), /*#__PURE__*/React__default.createElement(ListBox, {
|
|
361
|
+
onFocus: handleFocus,
|
|
362
|
+
onBlur: handleFocus,
|
|
363
|
+
className: className,
|
|
364
|
+
disabled: disabled,
|
|
365
|
+
invalid: invalid,
|
|
366
|
+
invalidText: invalidText,
|
|
367
|
+
invalidTextId: invalidTextId,
|
|
368
|
+
isOpen: isOpen,
|
|
369
|
+
light: light,
|
|
370
|
+
size: size,
|
|
371
|
+
warn: warn,
|
|
372
|
+
warnText: warnText,
|
|
373
|
+
warnTextId: warnTextId
|
|
374
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
375
|
+
className: `${prefix}--list-box__field`
|
|
376
|
+
}, /*#__PURE__*/React__default.createElement("input", _extends({
|
|
377
|
+
disabled: disabled,
|
|
378
|
+
className: inputClasses,
|
|
379
|
+
type: "text",
|
|
380
|
+
tabIndex: 0,
|
|
381
|
+
"aria-haspopup": "listbox",
|
|
382
|
+
"aria-owns": getMenuProps().id,
|
|
383
|
+
title: textInput?.current?.value
|
|
384
|
+
}, getInputProps({
|
|
385
|
+
placeholder,
|
|
386
|
+
ref: {
|
|
387
|
+
...mergeRefs(textInput, ref)
|
|
388
|
+
},
|
|
389
|
+
onKeyDown: event => {
|
|
390
|
+
if (match(event, Space)) {
|
|
391
|
+
event.stopPropagation();
|
|
392
|
+
}
|
|
393
|
+
if (match(event, Enter) && (!inputValue || allowCustomValue)) {
|
|
332
394
|
toggleMenu();
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (match(event, Space)) {
|
|
336
|
-
event.stopPropagation();
|
|
395
|
+
if (highlightedIndex !== -1) {
|
|
396
|
+
selectItem(items[highlightedIndex]);
|
|
337
397
|
}
|
|
338
|
-
|
|
398
|
+
event.preventDownshiftDefault = true;
|
|
399
|
+
event?.persist?.();
|
|
400
|
+
}
|
|
401
|
+
if (match(event, Escape) && inputValue) {
|
|
402
|
+
if (event.target === textInput.current && isOpen) {
|
|
339
403
|
toggleMenu();
|
|
340
|
-
|
|
341
|
-
// Since `onChange` does not normally fire when the menu is closed, we should
|
|
342
|
-
// manually fire it when `allowCustomValue` is provided, the menu is closing,
|
|
343
|
-
// and there is a value.
|
|
344
|
-
if (allowCustomValue && isOpen && inputValue) {
|
|
345
|
-
onChange({
|
|
346
|
-
selectedItem,
|
|
347
|
-
inputValue
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (match(event, Escape) && inputValue) {
|
|
352
|
-
if (event.target === textInput.current && isOpen) {
|
|
353
|
-
toggleMenu();
|
|
354
|
-
event.preventDownshiftDefault = true;
|
|
355
|
-
event?.persist?.();
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
if (match(event, Home) && event.code !== 'Numpad7') {
|
|
359
|
-
event.target.setSelectionRange(0, 0);
|
|
360
|
-
}
|
|
361
|
-
if (match(event, End) && event.code !== 'Numpad1') {
|
|
362
|
-
event.target.setSelectionRange(event.target.value.length, event.target.value.length);
|
|
363
|
-
}
|
|
364
|
-
if (event.altKey && event.key == 'ArrowDown') {
|
|
365
404
|
event.preventDownshiftDefault = true;
|
|
366
|
-
|
|
367
|
-
toggleMenu();
|
|
368
|
-
}
|
|
405
|
+
event?.persist?.();
|
|
369
406
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
407
|
+
}
|
|
408
|
+
if (match(event, Home) && event.code !== 'Numpad7') {
|
|
409
|
+
event.target.setSelectionRange(0, 0);
|
|
410
|
+
}
|
|
411
|
+
if (match(event, End) && event.code !== 'Numpad1') {
|
|
412
|
+
event.target.setSelectionRange(event.target.value.length, event.target.value.length);
|
|
413
|
+
}
|
|
414
|
+
if (event.altKey && event.key == 'ArrowDown') {
|
|
415
|
+
event.preventDownshiftDefault = true;
|
|
416
|
+
if (!isOpen) {
|
|
417
|
+
toggleMenu();
|
|
375
418
|
}
|
|
376
419
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const readOnlyEventHandlers = readOnly ? {
|
|
382
|
-
onKeyDown: evt => {
|
|
383
|
-
// This prevents the select from opening for the above keys
|
|
384
|
-
if (evt.key !== 'Tab') {
|
|
385
|
-
evt.preventDefault();
|
|
420
|
+
if (event.altKey && event.key == 'ArrowUp') {
|
|
421
|
+
event.preventDownshiftDefault = true;
|
|
422
|
+
if (isOpen) {
|
|
423
|
+
toggleMenu();
|
|
386
424
|
}
|
|
387
425
|
}
|
|
388
|
-
}
|
|
426
|
+
}
|
|
427
|
+
}), rest, readOnlyEventHandlers, {
|
|
428
|
+
readOnly: readOnly,
|
|
429
|
+
"aria-describedby": ariaDescribedBy
|
|
430
|
+
})), invalid && /*#__PURE__*/React__default.createElement(WarningFilled, {
|
|
431
|
+
className: `${prefix}--list-box__invalid-icon`
|
|
432
|
+
}), showWarning && /*#__PURE__*/React__default.createElement(WarningAltFilled, {
|
|
433
|
+
className: `${prefix}--list-box__invalid-icon ${prefix}--list-box__invalid-icon--warning`
|
|
434
|
+
}), inputValue && /*#__PURE__*/React__default.createElement(ListBoxSelection, {
|
|
435
|
+
clearSelection: () => {
|
|
436
|
+
selectItem(null);
|
|
437
|
+
},
|
|
438
|
+
translateWithId: translateWithId,
|
|
439
|
+
disabled: disabled || readOnly,
|
|
440
|
+
onClearSelection: handleSelectionClear,
|
|
441
|
+
selectionCount: 0
|
|
442
|
+
}), /*#__PURE__*/React__default.createElement(ListBoxTrigger, _extends({}, buttonProps, {
|
|
443
|
+
// @ts-expect-error
|
|
444
|
+
isOpen: isOpen,
|
|
445
|
+
translateWithId: translateWithId
|
|
446
|
+
}))), normalizedSlug, /*#__PURE__*/React__default.createElement(ListBox.Menu, getMenuProps({
|
|
447
|
+
'aria-label': deprecatedAriaLabel || ariaLabel
|
|
448
|
+
}), isOpen ? filterItems(items, itemToString, inputValue).map((item, index) => {
|
|
449
|
+
const isObject = item !== null && typeof item === 'object';
|
|
450
|
+
const title = isObject && 'text' in item && itemToElement ? item.text?.toString() : itemToString(item);
|
|
451
|
+
const itemProps = getItemProps({
|
|
452
|
+
item,
|
|
453
|
+
index
|
|
454
|
+
});
|
|
389
455
|
|
|
390
|
-
// The
|
|
391
|
-
//
|
|
392
|
-
//
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
role: "combobox",
|
|
417
|
-
disabled: disabled,
|
|
418
|
-
className: inputClasses,
|
|
419
|
-
type: "text",
|
|
420
|
-
tabIndex: 0,
|
|
421
|
-
"aria-autocomplete": "list",
|
|
422
|
-
"aria-expanded": rootProps['aria-expanded'],
|
|
423
|
-
"aria-haspopup": "listbox",
|
|
424
|
-
"aria-controls": inputProps['aria-controls'],
|
|
425
|
-
"aria-owns": getMenuProps().id,
|
|
426
|
-
title: textInput?.current?.value
|
|
427
|
-
}, inputProps, rest, readOnlyEventHandlers, {
|
|
428
|
-
readOnly: readOnly,
|
|
429
|
-
ref: mergeRefs(textInput, ref),
|
|
430
|
-
"aria-describedby": ariaDescribedBy
|
|
431
|
-
})), invalid && /*#__PURE__*/React__default.createElement(WarningFilled, {
|
|
432
|
-
className: `${prefix}--list-box__invalid-icon`
|
|
433
|
-
}), showWarning && /*#__PURE__*/React__default.createElement(WarningAltFilled, {
|
|
434
|
-
className: `${prefix}--list-box__invalid-icon ${prefix}--list-box__invalid-icon--warning`
|
|
435
|
-
}), inputValue && /*#__PURE__*/React__default.createElement(ListBoxSelection, {
|
|
436
|
-
clearSelection: clearSelection,
|
|
437
|
-
translateWithId: translateWithId,
|
|
438
|
-
disabled: disabled || readOnly,
|
|
439
|
-
onClearSelection: handleSelectionClear,
|
|
440
|
-
selectionCount: 0
|
|
441
|
-
}), /*#__PURE__*/React__default.createElement(ListBoxTrigger, _extends({}, buttonProps, {
|
|
442
|
-
isOpen: isOpen,
|
|
443
|
-
translateWithId: translateWithId
|
|
444
|
-
}))), normalizedSlug, /*#__PURE__*/React__default.createElement(ListBox.Menu, getMenuProps({
|
|
445
|
-
'aria-label': deprecatedAriaLabel || ariaLabel
|
|
446
|
-
}), isOpen ? filterItems(items, itemToString, inputValue).map((item, index) => {
|
|
447
|
-
const isObject = item !== null && typeof item === 'object';
|
|
448
|
-
const title = isObject && 'text' in item && itemToElement ? item.text?.toString() : itemToString(item);
|
|
449
|
-
const disabled = isObject && 'disabled' in item ? !!item.disabled : undefined;
|
|
450
|
-
const itemProps = getItemProps({
|
|
451
|
-
item,
|
|
452
|
-
index,
|
|
453
|
-
['aria-current']: selectedItem === item ? 'true' : 'false',
|
|
454
|
-
['aria-selected']: highlightedIndex === index ? 'true' : 'false',
|
|
455
|
-
disabled
|
|
456
|
-
});
|
|
457
|
-
return /*#__PURE__*/React__default.createElement(ListBox.MenuItem, _extends({
|
|
458
|
-
key: itemProps.id,
|
|
459
|
-
isActive: selectedItem === item,
|
|
460
|
-
isHighlighted: highlightedIndex === index,
|
|
461
|
-
title: title
|
|
462
|
-
}, itemProps), ItemToElement ? /*#__PURE__*/React__default.createElement(ItemToElement, _extends({
|
|
463
|
-
key: itemProps.id
|
|
464
|
-
}, item)) : itemToString(item), selectedItem === item && /*#__PURE__*/React__default.createElement(Checkmark, {
|
|
465
|
-
className: `${prefix}--list-box__menu-item__selected-icon`
|
|
466
|
-
}));
|
|
467
|
-
}) : null)), helperText && !invalid && !warn && !isFluid && (_Text || (_Text = /*#__PURE__*/React__default.createElement(Text, {
|
|
468
|
-
as: "div",
|
|
469
|
-
id: helperTextId,
|
|
470
|
-
className: helperClasses
|
|
471
|
-
}, helperText))));
|
|
472
|
-
});
|
|
456
|
+
// The initial implementation using <Downshift> would place the disabled attribute
|
|
457
|
+
// on disabled menu items. Conversely, useCombobox places aria-disabled instead.
|
|
458
|
+
// To avoid any potential breaking changes, we avoid placing aria-disabled and
|
|
459
|
+
// instead match the old behavior of placing the disabled attribute.
|
|
460
|
+
const disabled = itemProps['aria-disabled'];
|
|
461
|
+
const {
|
|
462
|
+
'aria-disabled': unusedAriaDisabled,
|
|
463
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
464
|
+
...modifiedItemProps
|
|
465
|
+
} = itemProps;
|
|
466
|
+
return /*#__PURE__*/React__default.createElement(ListBox.MenuItem, _extends({
|
|
467
|
+
key: itemProps.id,
|
|
468
|
+
isActive: selectedItem === item,
|
|
469
|
+
isHighlighted: highlightedIndex === index,
|
|
470
|
+
title: title,
|
|
471
|
+
disabled: disabled
|
|
472
|
+
}, modifiedItemProps), ItemToElement ? /*#__PURE__*/React__default.createElement(ItemToElement, _extends({
|
|
473
|
+
key: itemProps.id
|
|
474
|
+
}, item)) : itemToString(item), selectedItem === item && /*#__PURE__*/React__default.createElement(Checkmark, {
|
|
475
|
+
className: `${prefix}--list-box__menu-item__selected-icon`
|
|
476
|
+
}));
|
|
477
|
+
}) : null)), helperText && !invalid && !warn && !isFluid && /*#__PURE__*/React__default.createElement(Text, {
|
|
478
|
+
as: "div",
|
|
479
|
+
id: helperTextId,
|
|
480
|
+
className: helperClasses
|
|
481
|
+
}, helperText));
|
|
473
482
|
});
|
|
474
483
|
ComboBox.displayName = 'ComboBox';
|
|
475
484
|
ComboBox.propTypes = {
|
|
@@ -504,8 +513,7 @@ ComboBox.propTypes = {
|
|
|
504
513
|
/**
|
|
505
514
|
* Additional props passed to Downshift
|
|
506
515
|
*/
|
|
507
|
-
|
|
508
|
-
downshiftProps: PropTypes.shape(Downshift.propTypes),
|
|
516
|
+
downshiftProps: PropTypes.object,
|
|
509
517
|
/**
|
|
510
518
|
* Provide helper text that is used alongside the control label for
|
|
511
519
|
* 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;
|
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React, { ReactNode } from 'react';
|
|
8
|
+
import ContainedListItem from './ContainedListItem';
|
|
8
9
|
declare const variants: readonly ["on-page", "disclosed"];
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
interface ContainedListType extends React.FC<ContainedListProps> {
|
|
11
|
+
ContainedListItem: typeof ContainedListItem;
|
|
12
|
+
}
|
|
13
|
+
export type Variants = (typeof variants)[number];
|
|
14
|
+
export interface ContainedListProps {
|
|
11
15
|
/**
|
|
12
16
|
* A slot for a possible interactive element to render.
|
|
13
17
|
*/
|
|
@@ -37,5 +41,5 @@ interface ContainedListProps {
|
|
|
37
41
|
*/
|
|
38
42
|
size?: 'sm' | 'md' | 'lg' | 'xl';
|
|
39
43
|
}
|
|
40
|
-
declare const ContainedList:
|
|
44
|
+
declare const ContainedList: ContainedListType;
|
|
41
45
|
export default ContainedList;
|