@carbon/react 1.68.0-rc.0 → 1.68.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 +807 -807
- package/es/components/ComboBox/ComboBox.d.ts +5 -0
- package/es/components/ComboBox/ComboBox.js +135 -45
- package/es/components/DatePicker/DatePicker.js +10 -6
- package/es/components/FileUploader/FileUploaderDropContainer.js +1 -1
- package/es/components/FluidComboBox/FluidComboBox.Skeleton.d.ts +15 -0
- package/es/components/FluidComboBox/FluidComboBox.Skeleton.js +1 -2
- package/es/components/FluidComboBox/FluidComboBox.d.ts +102 -0
- package/es/components/FluidComboBox/FluidComboBox.js +2 -3
- package/es/components/FluidComboBox/index.d.ts +13 -0
- package/es/components/FluidDatePicker/FluidDatePicker.Skeleton.d.ts +19 -0
- package/es/components/FluidDatePicker/FluidDatePicker.Skeleton.js +2 -2
- package/es/components/FluidDatePicker/FluidDatePicker.d.ts +39 -0
- package/es/components/FluidDatePicker/FluidDatePicker.js +2 -3
- package/es/components/FluidDatePicker/index.d.ts +13 -0
- package/es/components/FluidDatePickerInput/FluidDatePickerInput.d.ts +10 -0
- package/es/components/FluidDatePickerInput/FluidDatePickerInput.js +1 -2
- package/es/components/FluidDatePickerInput/index.d.ts +9 -0
- package/es/components/Tabs/usePressable.js +2 -0
- package/es/index.js +5 -5
- package/lib/components/ComboBox/ComboBox.d.ts +5 -0
- package/lib/components/ComboBox/ComboBox.js +134 -44
- package/lib/components/DatePicker/DatePicker.js +9 -5
- package/lib/components/FileUploader/FileUploaderDropContainer.js +1 -1
- package/lib/components/FluidComboBox/FluidComboBox.Skeleton.d.ts +15 -0
- package/lib/components/FluidComboBox/FluidComboBox.Skeleton.js +1 -2
- package/lib/components/FluidComboBox/FluidComboBox.d.ts +102 -0
- package/lib/components/FluidComboBox/FluidComboBox.js +2 -3
- package/lib/components/FluidComboBox/index.d.ts +13 -0
- package/lib/components/FluidDatePicker/FluidDatePicker.Skeleton.d.ts +19 -0
- package/lib/components/FluidDatePicker/FluidDatePicker.Skeleton.js +2 -2
- package/lib/components/FluidDatePicker/FluidDatePicker.d.ts +39 -0
- package/lib/components/FluidDatePicker/FluidDatePicker.js +3 -4
- package/lib/components/FluidDatePicker/index.d.ts +13 -0
- package/lib/components/FluidDatePickerInput/FluidDatePickerInput.d.ts +10 -0
- package/lib/components/FluidDatePickerInput/FluidDatePickerInput.js +1 -2
- package/lib/components/FluidDatePickerInput/index.d.ts +9 -0
- package/lib/components/Tabs/usePressable.js +2 -0
- package/lib/index.js +10 -10
- package/package.json +5 -5
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2022
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { DatePickerInputProps } from '../DatePickerInput';
|
|
9
|
+
declare const FluidDatePickerInput: React.ForwardRefExoticComponent<DatePickerInputProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
export default FluidDatePickerInput;
|
|
@@ -22,6 +22,5 @@ const FluidDatePickerInput = /*#__PURE__*/React__default.forwardRef(function Flu
|
|
|
22
22
|
ref: ref
|
|
23
23
|
}, other)));
|
|
24
24
|
});
|
|
25
|
-
var FluidDatePickerInput$1 = FluidDatePickerInput;
|
|
26
25
|
|
|
27
|
-
export { FluidDatePickerInput
|
|
26
|
+
export { FluidDatePickerInput as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2022
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import FluidDatePickerInput from './FluidDatePickerInput';
|
|
8
|
+
export default FluidDatePickerInput;
|
|
9
|
+
export { FluidDatePickerInput };
|
package/es/index.js
CHANGED
|
@@ -159,6 +159,11 @@ export { default as SideNavMenuItem } from './components/UIShell/SideNavMenuItem
|
|
|
159
159
|
export { default as SideNavSwitcher } from './components/UIShell/SideNavSwitcher.js';
|
|
160
160
|
export { default as UnorderedList } from './components/UnorderedList/UnorderedList.js';
|
|
161
161
|
export { FeatureFlags as unstable_FeatureFlags, useFeatureFlag as unstable_useFeatureFlag, useFeatureFlags as unstable_useFeatureFlags } from './components/FeatureFlags/index.js';
|
|
162
|
+
export { default as unstable__FluidComboBox } from './components/FluidComboBox/FluidComboBox.js';
|
|
163
|
+
export { default as unstable__FluidComboBoxSkeleton } from './components/FluidComboBox/FluidComboBox.Skeleton.js';
|
|
164
|
+
export { default as unstable__FluidDatePicker } from './components/FluidDatePicker/FluidDatePicker.js';
|
|
165
|
+
export { default as unstable__FluidDatePickerSkeleton } from './components/FluidDatePicker/FluidDatePicker.Skeleton.js';
|
|
166
|
+
export { default as unstable__FluidDatePickerInput } from './components/FluidDatePickerInput/FluidDatePickerInput.js';
|
|
162
167
|
export { default as unstable__FluidMultiSelect } from './components/FluidMultiSelect/FluidMultiSelect.js';
|
|
163
168
|
export { default as unstable__FluidMultiSelectSkeleton } from './components/FluidMultiSelect/FluidMultiSelect.Skeleton.js';
|
|
164
169
|
export { default as unstable__FluidSelect } from './components/FluidSelect/FluidSelect.js';
|
|
@@ -192,7 +197,6 @@ import './components/Text/index.js';
|
|
|
192
197
|
export { GlobalTheme, Theme, ThemeContext, usePrefersDarkScheme, useTheme } from './components/Theme/index.js';
|
|
193
198
|
export { PrefixContext, usePrefix } from './internal/usePrefix.js';
|
|
194
199
|
export { useIdPrefix } from './internal/useIdPrefix.js';
|
|
195
|
-
export { default as unstable__FluidDatePickerSkeleton } from './components/FluidDatePicker/FluidDatePicker.Skeleton.js';
|
|
196
200
|
export { default as unstable_PageSelector } from './components/Pagination/experimental/PageSelector.js';
|
|
197
201
|
export { default as unstable_Pagination } from './components/Pagination/experimental/Pagination.js';
|
|
198
202
|
export { default as ContainedListItem } from './components/ContainedList/ContainedListItem/ContainedListItem.js';
|
|
@@ -201,10 +205,6 @@ export { default as useContextMenu } from './components/ContextMenu/useContextMe
|
|
|
201
205
|
export { default as SliderSkeleton } from './components/Slider/Slider.Skeleton.js';
|
|
202
206
|
export { default as TextInputSkeleton } from './components/TextInput/TextInput.Skeleton.js';
|
|
203
207
|
export { default as TextInput } from './components/TextInput/TextInput.js';
|
|
204
|
-
export { default as unstable__FluidComboBox } from './components/FluidComboBox/FluidComboBox.js';
|
|
205
|
-
export { default as unstable__FluidComboBoxSkeleton } from './components/FluidComboBox/FluidComboBox.Skeleton.js';
|
|
206
|
-
export { default as unstable__FluidDatePicker } from './components/FluidDatePicker/FluidDatePicker.js';
|
|
207
|
-
export { default as unstable__FluidDatePickerInput } from './components/FluidDatePickerInput/FluidDatePickerInput.js';
|
|
208
208
|
export { default as unstable__FluidDropdown } from './components/FluidDropdown/FluidDropdown.js';
|
|
209
209
|
export { default as unstable__FluidDropdownSkeleton } from './components/FluidDropdown/FluidDropdown.Skeleton.js';
|
|
210
210
|
export { LayoutDirection as unstable_LayoutDirection } from './components/LayoutDirection/LayoutDirection.js';
|
|
@@ -158,6 +158,7 @@ export interface ComboBoxProps<ItemType> extends Omit<InputHTMLAttributes<HTMLIn
|
|
|
158
158
|
* Specify your own filtering logic by passing in a `shouldFilterItem`
|
|
159
159
|
* function that takes in the current input and an item and passes back
|
|
160
160
|
* whether or not the item should be filtered.
|
|
161
|
+
* this prop will be ignored if `typeahead` prop is enabled
|
|
161
162
|
*/
|
|
162
163
|
shouldFilterItem?: (input: {
|
|
163
164
|
item: ItemType;
|
|
@@ -177,6 +178,10 @@ export interface ComboBoxProps<ItemType> extends Omit<InputHTMLAttributes<HTMLIn
|
|
|
177
178
|
* combobox via ARIA attributes.
|
|
178
179
|
*/
|
|
179
180
|
titleText?: ReactNode;
|
|
181
|
+
/**
|
|
182
|
+
* **Experimental**: will enable autcomplete and typeahead for the input field
|
|
183
|
+
*/
|
|
184
|
+
typeahead?: boolean;
|
|
180
185
|
/**
|
|
181
186
|
* Specify whether the control is currently in warning state
|
|
182
187
|
*/
|
|
@@ -46,8 +46,7 @@ const {
|
|
|
46
46
|
ItemMouseMove,
|
|
47
47
|
InputKeyDownArrowUp,
|
|
48
48
|
InputKeyDownArrowDown,
|
|
49
|
-
MenuMouseLeave
|
|
50
|
-
FunctionSelectItem
|
|
49
|
+
MenuMouseLeave
|
|
51
50
|
} = Downshift.useCombobox.stateChangeTypes;
|
|
52
51
|
const defaultItemToString = item => {
|
|
53
52
|
if (typeof item === 'string') {
|
|
@@ -62,26 +61,42 @@ const defaultItemToString = item => {
|
|
|
62
61
|
return '';
|
|
63
62
|
};
|
|
64
63
|
const defaultShouldFilterItem = () => true;
|
|
65
|
-
const
|
|
64
|
+
const autocompleteCustomFilter = _ref => {
|
|
65
|
+
let {
|
|
66
|
+
item,
|
|
67
|
+
inputValue
|
|
68
|
+
} = _ref;
|
|
69
|
+
if (inputValue === null || inputValue === '') {
|
|
70
|
+
return true; // Show all items if there's no input
|
|
71
|
+
}
|
|
72
|
+
const lowercaseItem = item.toLowerCase();
|
|
73
|
+
const lowercaseInput = inputValue.toLowerCase();
|
|
74
|
+
return lowercaseItem.startsWith(lowercaseInput);
|
|
75
|
+
};
|
|
76
|
+
const getInputValue = _ref2 => {
|
|
66
77
|
let {
|
|
67
78
|
initialSelectedItem,
|
|
68
79
|
inputValue,
|
|
69
80
|
itemToString,
|
|
70
|
-
selectedItem
|
|
71
|
-
|
|
81
|
+
selectedItem,
|
|
82
|
+
prevSelectedItem
|
|
83
|
+
} = _ref2;
|
|
72
84
|
if (selectedItem) {
|
|
73
85
|
return itemToString(selectedItem);
|
|
74
86
|
}
|
|
75
87
|
if (initialSelectedItem) {
|
|
76
88
|
return itemToString(initialSelectedItem);
|
|
77
89
|
}
|
|
90
|
+
if (!selectedItem && prevSelectedItem) {
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
78
93
|
return inputValue || '';
|
|
79
94
|
};
|
|
80
|
-
const findHighlightedIndex = (
|
|
95
|
+
const findHighlightedIndex = (_ref3, inputValue) => {
|
|
81
96
|
let {
|
|
82
97
|
items,
|
|
83
98
|
itemToString = defaultItemToString
|
|
84
|
-
} =
|
|
99
|
+
} = _ref3;
|
|
85
100
|
if (!inputValue) {
|
|
86
101
|
return -1;
|
|
87
102
|
}
|
|
@@ -104,6 +119,9 @@ const findHighlightedIndex = (_ref2, inputValue) => {
|
|
|
104
119
|
*/
|
|
105
120
|
|
|
106
121
|
const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
122
|
+
const [cursorPosition, setCursorPosition] = React.useState(0);
|
|
123
|
+
const prevInputLengthRef = React.useRef(0);
|
|
124
|
+
const inputRef = React.useRef(null);
|
|
107
125
|
const {
|
|
108
126
|
['aria-label']: ariaLabel = 'Choose an item',
|
|
109
127
|
ariaLabel: deprecatedAriaLabel,
|
|
@@ -132,6 +150,7 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
132
150
|
size,
|
|
133
151
|
titleText,
|
|
134
152
|
translateWithId,
|
|
153
|
+
typeahead = false,
|
|
135
154
|
warn,
|
|
136
155
|
warnText,
|
|
137
156
|
allowCustomValue = false,
|
|
@@ -165,33 +184,68 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
165
184
|
}
|
|
166
185
|
}
|
|
167
186
|
}, [autoAlign, floatingStyles, refs.floating, parentWidth]);
|
|
168
|
-
const prefix = usePrefix.usePrefix();
|
|
169
|
-
const {
|
|
170
|
-
isFluid
|
|
171
|
-
} = React.useContext(FormContext.FormContext);
|
|
172
|
-
const textInput = React.useRef(null);
|
|
173
|
-
const comboBoxInstanceId = useId.useId();
|
|
174
187
|
const [inputValue, setInputValue] = React.useState(getInputValue({
|
|
175
188
|
initialSelectedItem,
|
|
176
189
|
inputValue: '',
|
|
177
190
|
itemToString,
|
|
178
191
|
selectedItem: selectedItemProp
|
|
179
192
|
}));
|
|
193
|
+
const [typeaheadText, setTypeaheadText] = React.useState('');
|
|
194
|
+
React.useEffect(() => {
|
|
195
|
+
if (typeahead) {
|
|
196
|
+
if (inputValue.length >= prevInputLengthRef.current) {
|
|
197
|
+
if (inputValue) {
|
|
198
|
+
const filteredItems = items.filter(item => autocompleteCustomFilter({
|
|
199
|
+
item: itemToString(item),
|
|
200
|
+
inputValue: inputValue
|
|
201
|
+
}));
|
|
202
|
+
if (filteredItems.length > 0) {
|
|
203
|
+
const suggestion = itemToString(filteredItems[0]);
|
|
204
|
+
setTypeaheadText(suggestion.slice(inputValue.length));
|
|
205
|
+
} else {
|
|
206
|
+
setTypeaheadText('');
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
setTypeaheadText('');
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
setTypeaheadText('');
|
|
213
|
+
}
|
|
214
|
+
prevInputLengthRef.current = inputValue.length;
|
|
215
|
+
}
|
|
216
|
+
}, [typeahead, inputValue, items, itemToString, autocompleteCustomFilter]);
|
|
217
|
+
const prefix = usePrefix.usePrefix();
|
|
218
|
+
const {
|
|
219
|
+
isFluid
|
|
220
|
+
} = React.useContext(FormContext.FormContext);
|
|
221
|
+
const textInput = React.useRef(null);
|
|
222
|
+
const comboBoxInstanceId = useId.useId();
|
|
180
223
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
181
|
-
const [prevSelectedItem, setPrevSelectedItem] = React.useState();
|
|
182
|
-
const [doneInitialSelectedItem, setDoneInitialSelectedItem] = React.useState(false);
|
|
183
224
|
const savedOnInputChange = React.useRef(onInputChange);
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
225
|
+
const prevSelectedItemProp = React.useRef(selectedItemProp);
|
|
226
|
+
|
|
227
|
+
// fully controlled combobox: handle changes to selectedItemProp
|
|
228
|
+
React.useEffect(() => {
|
|
229
|
+
if (prevSelectedItemProp.current !== selectedItemProp) {
|
|
230
|
+
const currentInputValue = getInputValue({
|
|
231
|
+
initialSelectedItem,
|
|
232
|
+
inputValue,
|
|
233
|
+
itemToString,
|
|
234
|
+
selectedItem: selectedItemProp,
|
|
235
|
+
prevSelectedItem: prevSelectedItemProp.current
|
|
236
|
+
});
|
|
237
|
+
setInputValue(currentInputValue);
|
|
238
|
+
onChange({
|
|
239
|
+
selectedItem: selectedItemProp,
|
|
240
|
+
inputValue: currentInputValue
|
|
241
|
+
});
|
|
242
|
+
prevSelectedItemProp.current = selectedItemProp;
|
|
243
|
+
}
|
|
244
|
+
}, [selectedItemProp]);
|
|
245
|
+
const filterItems = (items, itemToString, inputValue) => items.filter(item => typeahead ? autocompleteCustomFilter({
|
|
246
|
+
item: itemToString(item),
|
|
247
|
+
inputValue
|
|
248
|
+
}) : shouldFilterItem ? shouldFilterItem({
|
|
195
249
|
item,
|
|
196
250
|
itemToString,
|
|
197
251
|
inputValue
|
|
@@ -214,7 +268,7 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
214
268
|
...props,
|
|
215
269
|
items: filteredItems(inputValue)
|
|
216
270
|
}, inputValue);
|
|
217
|
-
const stateReducer =
|
|
271
|
+
const stateReducer = React.useCallback((state, actionAndChanges) => {
|
|
218
272
|
const {
|
|
219
273
|
type,
|
|
220
274
|
changes
|
|
@@ -250,14 +304,6 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
250
304
|
}
|
|
251
305
|
return changes;
|
|
252
306
|
}
|
|
253
|
-
case FunctionSelectItem:
|
|
254
|
-
if (onChange) {
|
|
255
|
-
onChange({
|
|
256
|
-
selectedItem: changes.selectedItem,
|
|
257
|
-
inputValue: changes.inputValue
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
return changes;
|
|
261
307
|
case InputKeyDownEnter:
|
|
262
308
|
if (allowCustomValue) {
|
|
263
309
|
setInputValue(inputValue);
|
|
@@ -387,25 +433,34 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
387
433
|
itemToString: item => {
|
|
388
434
|
return itemToString(item);
|
|
389
435
|
},
|
|
390
|
-
onInputValueChange(
|
|
436
|
+
onInputValueChange(_ref4) {
|
|
391
437
|
let {
|
|
392
438
|
inputValue
|
|
393
|
-
} =
|
|
394
|
-
|
|
395
|
-
|
|
439
|
+
} = _ref4;
|
|
440
|
+
const normalizedInput = inputValue || '';
|
|
441
|
+
setInputValue(normalizedInput);
|
|
442
|
+
if (selectedItemProp && !inputValue) {
|
|
443
|
+
// ensure onChange is called when selectedItem is cleared
|
|
444
|
+
onChange({
|
|
445
|
+
selectedItem,
|
|
446
|
+
inputValue: normalizedInput
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
setHighlightedIndex(indexToHighlight(normalizedInput));
|
|
450
|
+
setCursorPosition(inputValue === null ? 0 : normalizedInput.length);
|
|
396
451
|
},
|
|
397
|
-
onSelectedItemChange(
|
|
452
|
+
onSelectedItemChange(_ref5) {
|
|
398
453
|
let {
|
|
399
454
|
selectedItem
|
|
400
|
-
} =
|
|
455
|
+
} = _ref5;
|
|
401
456
|
onChange({
|
|
402
457
|
selectedItem
|
|
403
458
|
});
|
|
404
459
|
},
|
|
405
|
-
onHighlightedIndexChange:
|
|
460
|
+
onHighlightedIndexChange: _ref6 => {
|
|
406
461
|
let {
|
|
407
462
|
highlightedIndex
|
|
408
|
-
} =
|
|
463
|
+
} = _ref6;
|
|
409
464
|
if (highlightedIndex > -1 && typeof window !== undefined) {
|
|
410
465
|
const itemArray = document.querySelectorAll(`li.${prefix}--list-box__menu-item[role="option"]`);
|
|
411
466
|
const highlightedItem = itemArray[highlightedIndex];
|
|
@@ -441,6 +496,11 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
441
496
|
};
|
|
442
497
|
}
|
|
443
498
|
}, [closeMenu, openMenu, reset, selectItem, setHighlightedIndex, downshiftSetInputValue, toggleMenu]);
|
|
499
|
+
React.useEffect(() => {
|
|
500
|
+
if (inputRef.current) {
|
|
501
|
+
inputRef.current.setSelectionRange(cursorPosition, cursorPosition);
|
|
502
|
+
}
|
|
503
|
+
}, [inputValue, cursorPosition]);
|
|
444
504
|
const buttonProps = getToggleButtonProps({
|
|
445
505
|
disabled: disabled || readOnly,
|
|
446
506
|
onClick: handleToggleClick(isOpen),
|
|
@@ -487,6 +547,16 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
487
547
|
'aria-label': deprecatedAriaLabel || ariaLabel,
|
|
488
548
|
ref: autoAlign ? refs.setFloating : null
|
|
489
549
|
}), [autoAlign, deprecatedAriaLabel, ariaLabel, getMenuProps, refs.setFloating]);
|
|
550
|
+
React.useEffect(() => {
|
|
551
|
+
if (textInput.current) {
|
|
552
|
+
if (inputRef.current && typeaheadText) {
|
|
553
|
+
const selectionStart = inputValue.length;
|
|
554
|
+
const selectionEnd = selectionStart + typeaheadText.length;
|
|
555
|
+
inputRef.current.value = inputValue + typeaheadText;
|
|
556
|
+
inputRef.current.setSelectionRange(selectionStart, selectionEnd);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}, [inputValue, typeaheadText]);
|
|
490
560
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
491
561
|
className: wrapperClasses
|
|
492
562
|
}, titleText && /*#__PURE__*/React__default["default"].createElement(Text.Text, _rollupPluginBabelHelpers["extends"]({
|
|
@@ -519,7 +589,12 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
519
589
|
}, getInputProps({
|
|
520
590
|
'aria-controls': isOpen ? undefined : menuProps.id,
|
|
521
591
|
placeholder,
|
|
522
|
-
|
|
592
|
+
value: inputValue,
|
|
593
|
+
onChange: e => {
|
|
594
|
+
const newValue = e.target.value;
|
|
595
|
+
downshiftSetInputValue(newValue);
|
|
596
|
+
},
|
|
597
|
+
ref: mergeRefs["default"](textInput, ref, inputRef),
|
|
523
598
|
onKeyDown: event => {
|
|
524
599
|
if (match.match(event, keys.Space)) {
|
|
525
600
|
event.stopPropagation();
|
|
@@ -567,6 +642,16 @@ const ComboBox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
567
642
|
toggleMenu();
|
|
568
643
|
}
|
|
569
644
|
}
|
|
645
|
+
if (typeahead && event.key === 'Tab') {
|
|
646
|
+
// event.preventDefault();
|
|
647
|
+
const matchingItem = items.find(item => itemToString(item).toLowerCase().startsWith(inputValue.toLowerCase()));
|
|
648
|
+
if (matchingItem) {
|
|
649
|
+
const newValue = itemToString(matchingItem);
|
|
650
|
+
downshiftSetInputValue(newValue);
|
|
651
|
+
setCursorPosition(newValue.length);
|
|
652
|
+
selectItem(matchingItem);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
570
655
|
}
|
|
571
656
|
}), rest, readOnlyEventHandlers, {
|
|
572
657
|
readOnly: readOnly,
|
|
@@ -759,6 +844,7 @@ ComboBox.propTypes = {
|
|
|
759
844
|
* Specify your own filtering logic by passing in a `shouldFilterItem`
|
|
760
845
|
* function that takes in the current input and an item and passes back
|
|
761
846
|
* whether or not the item should be filtered.
|
|
847
|
+
* this prop will be ignored if `typeahead` prop is enabled
|
|
762
848
|
*/
|
|
763
849
|
shouldFilterItem: PropTypes__default["default"].func,
|
|
764
850
|
/**
|
|
@@ -779,6 +865,10 @@ ComboBox.propTypes = {
|
|
|
779
865
|
* and returns the localized string for the message
|
|
780
866
|
*/
|
|
781
867
|
translateWithId: PropTypes__default["default"].func,
|
|
868
|
+
/**
|
|
869
|
+
* **Experimental**: will enable autcomplete and typeahead for the input field
|
|
870
|
+
*/
|
|
871
|
+
typeahead: PropTypes__default["default"].bool,
|
|
782
872
|
/**
|
|
783
873
|
* Specify whether the control is currently in warning state
|
|
784
874
|
*/
|
|
@@ -403,9 +403,6 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
|
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
function handleOnChange(event) {
|
|
406
|
-
if (datePickerType == 'single' && closeOnSelect) {
|
|
407
|
-
calendar.calendarContainer.classList.remove('open');
|
|
408
|
-
}
|
|
409
406
|
const {
|
|
410
407
|
target
|
|
411
408
|
} = event;
|
|
@@ -421,12 +418,16 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
|
|
|
421
418
|
if (calendar.selectedDates.length === 0) {
|
|
422
419
|
return;
|
|
423
420
|
}
|
|
424
|
-
|
|
425
|
-
|
|
421
|
+
}
|
|
422
|
+
function handleKeyPress(event) {
|
|
423
|
+
if (match.match(event, keys.Enter) && closeOnSelect && datePickerType == 'single') {
|
|
424
|
+
calendar.calendarContainer.classList.remove('open');
|
|
425
|
+
}
|
|
426
426
|
}
|
|
427
427
|
if (start) {
|
|
428
428
|
start.addEventListener('keydown', handleArrowDown);
|
|
429
429
|
start.addEventListener('change', handleOnChange);
|
|
430
|
+
start.addEventListener('keypress', handleKeyPress);
|
|
430
431
|
if (calendar && calendar.calendarContainer) {
|
|
431
432
|
// Flatpickr's calendar dialog is not rendered in a landmark causing an
|
|
432
433
|
// error with IBM Equal Access Accessibility Checker so we add an aria
|
|
@@ -439,6 +440,7 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
|
|
|
439
440
|
if (end) {
|
|
440
441
|
end.addEventListener('keydown', handleArrowDown);
|
|
441
442
|
end.addEventListener('change', handleOnChange);
|
|
443
|
+
end.addEventListener('keypress', handleKeyPress);
|
|
442
444
|
}
|
|
443
445
|
|
|
444
446
|
//component did unmount equivalent
|
|
@@ -462,10 +464,12 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
|
|
|
462
464
|
if (start) {
|
|
463
465
|
start.removeEventListener('keydown', handleArrowDown);
|
|
464
466
|
start.removeEventListener('change', handleOnChange);
|
|
467
|
+
start.removeEventListener('keypress', handleKeyPress);
|
|
465
468
|
}
|
|
466
469
|
if (end) {
|
|
467
470
|
end.removeEventListener('keydown', handleArrowDown);
|
|
468
471
|
end.removeEventListener('change', handleOnChange);
|
|
472
|
+
end.removeEventListener('change', handleKeyPress);
|
|
469
473
|
}
|
|
470
474
|
};
|
|
471
475
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
export interface FluidComboBoxSkeletonProps {
|
|
9
|
+
/**
|
|
10
|
+
* Specify an optional className to add.
|
|
11
|
+
*/
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const FluidComboBoxSkeleton: React.FC<FluidComboBoxSkeletonProps>;
|
|
15
|
+
export default FluidComboBoxSkeleton;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2022
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { ComponentType } from 'react';
|
|
8
|
+
import { ComboBoxProps } from '../ComboBox/ComboBox';
|
|
9
|
+
type ItemToStringHandler<ItemType> = (item: ItemType | null) => string;
|
|
10
|
+
interface OnChangeData<ItemType> {
|
|
11
|
+
selectedItem: ItemType | null | undefined;
|
|
12
|
+
inputValue?: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface FluidComboBoxProps<ItemType> extends ComboBoxProps<ItemType> {
|
|
15
|
+
/**
|
|
16
|
+
* Specify an optional className to be applied to the outer FluidForm wrapper
|
|
17
|
+
*/
|
|
18
|
+
className?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Specify the direction of the dropdown. Can be either top or bottom.
|
|
21
|
+
*/
|
|
22
|
+
direction?: 'top' | 'bottom';
|
|
23
|
+
/**
|
|
24
|
+
* Specify whether the `<input>` should be disabled
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Specify a custom `id` for the `<input>`
|
|
29
|
+
*/
|
|
30
|
+
id: string;
|
|
31
|
+
/**
|
|
32
|
+
* Allow users to pass in an arbitrary item or a string (in case their items are an array of strings)
|
|
33
|
+
* from their collection that are pre-selected
|
|
34
|
+
*/
|
|
35
|
+
initialSelectedItem?: ItemType;
|
|
36
|
+
/**
|
|
37
|
+
* Specify if the currently selected value is invalid.
|
|
38
|
+
*/
|
|
39
|
+
invalid?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Provide the text that is displayed when the control is in an invalid state
|
|
42
|
+
*/
|
|
43
|
+
invalidText?: React.ReactNode;
|
|
44
|
+
/**
|
|
45
|
+
* Specify if the `FluidComboBox` should render its menu items in condensed mode
|
|
46
|
+
*/
|
|
47
|
+
isCondensed?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Function to render items as custom components instead of strings.
|
|
50
|
+
* Defaults to null and is overridden by a getter
|
|
51
|
+
*/
|
|
52
|
+
itemToElement?: ComponentType<ItemType> | null;
|
|
53
|
+
/**
|
|
54
|
+
* Helper function passed to downshift that allows the library to render a
|
|
55
|
+
* given item to a string label. By default, it extracts the `label` field
|
|
56
|
+
* from a given item to serve as the item label in the list.
|
|
57
|
+
*/
|
|
58
|
+
itemToString?: ItemToStringHandler<ItemType>;
|
|
59
|
+
/**
|
|
60
|
+
* We try to stay as generic as possible here to allow individuals to pass
|
|
61
|
+
* in a collection of whatever kind of data structure they prefer
|
|
62
|
+
*/
|
|
63
|
+
items: ItemType[];
|
|
64
|
+
/**
|
|
65
|
+
* Generic `label` that will be used as the textual representation of what
|
|
66
|
+
* this field is for
|
|
67
|
+
*/
|
|
68
|
+
label: React.ReactNode;
|
|
69
|
+
/**
|
|
70
|
+
* `onChange` is a utility for this controlled component to communicate to a
|
|
71
|
+
* consuming component what kind of internal state changes are occurring.
|
|
72
|
+
*/
|
|
73
|
+
onChange: (data: OnChangeData<ItemType>) => void;
|
|
74
|
+
/**
|
|
75
|
+
* An optional callback to render the currently selected item as a react element instead of only
|
|
76
|
+
* as a string.
|
|
77
|
+
*/
|
|
78
|
+
renderSelectedItem?: (selectedItem: ItemType) => React.ReactNode;
|
|
79
|
+
/**
|
|
80
|
+
* In the case you want to control the dropdown selection entirely.
|
|
81
|
+
* */
|
|
82
|
+
selectedItem?: ItemType | null;
|
|
83
|
+
/**
|
|
84
|
+
* Provide the title text that will be read by a screen reader when
|
|
85
|
+
* visiting this control
|
|
86
|
+
*/
|
|
87
|
+
titleText?: React.ReactNode;
|
|
88
|
+
/**
|
|
89
|
+
* Callback function for translating ListBoxMenuIcon SVG title
|
|
90
|
+
*/
|
|
91
|
+
translateWithId?: (id: string) => string;
|
|
92
|
+
/**
|
|
93
|
+
* Specify whether the control is currently in warning state
|
|
94
|
+
*/
|
|
95
|
+
warn?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Provide the text that is displayed when the control is in warning state
|
|
98
|
+
*/
|
|
99
|
+
warnText?: React.ReactNode;
|
|
100
|
+
}
|
|
101
|
+
declare const FluidComboBox: React.ForwardRefExoticComponent<FluidComboBoxProps<unknown> & React.RefAttributes<HTMLInputElement>>;
|
|
102
|
+
export default FluidComboBox;
|
|
@@ -101,7 +101,7 @@ FluidComboBox.propTypes = {
|
|
|
101
101
|
* `onChange` is a utility for this controlled component to communicate to a
|
|
102
102
|
* consuming component what kind of internal state changes are occurring.
|
|
103
103
|
*/
|
|
104
|
-
onChange: PropTypes__default["default"].func,
|
|
104
|
+
onChange: PropTypes__default["default"].func.isRequired,
|
|
105
105
|
/**
|
|
106
106
|
* An optional callback to render the currently selected item as a react element instead of only
|
|
107
107
|
* as a string.
|
|
@@ -129,6 +129,5 @@ FluidComboBox.propTypes = {
|
|
|
129
129
|
*/
|
|
130
130
|
warnText: PropTypes__default["default"].node
|
|
131
131
|
};
|
|
132
|
-
var FluidComboBox$1 = FluidComboBox;
|
|
133
132
|
|
|
134
|
-
exports["default"] = FluidComboBox
|
|
133
|
+
exports["default"] = FluidComboBox;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2022
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import FluidComboBox from './FluidComboBox';
|
|
8
|
+
import type { FluidComboBoxProps } from './FluidComboBox';
|
|
9
|
+
import type { FluidComboBoxSkeletonProps } from './FluidComboBox.Skeleton';
|
|
10
|
+
export type { FluidComboBoxProps, FluidComboBoxSkeletonProps };
|
|
11
|
+
export default FluidComboBox;
|
|
12
|
+
export { FluidComboBox };
|
|
13
|
+
export { default as FluidComboBoxSkeleton } from './FluidComboBox.Skeleton';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
export interface FluidDatePickerSkeletonProps {
|
|
9
|
+
/**
|
|
10
|
+
* Specify an optional className to be applied to the outer FluidForm wrapper
|
|
11
|
+
*/
|
|
12
|
+
className?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Specify which variant of the DatePicker the skeleton should mimic
|
|
15
|
+
*/
|
|
16
|
+
datePickerType?: 'simple' | 'single' | 'range';
|
|
17
|
+
}
|
|
18
|
+
declare const FluidDatePickerSkeleton: React.FC<FluidDatePickerSkeletonProps>;
|
|
19
|
+
export default FluidDatePickerSkeleton;
|
|
@@ -23,7 +23,7 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
|
23
23
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
24
24
|
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const FluidDatePickerSkeleton = _ref => {
|
|
27
27
|
let {
|
|
28
28
|
className,
|
|
29
29
|
datePickerType = 'single',
|
|
@@ -60,7 +60,7 @@ function FluidDatePickerSkeleton(_ref) {
|
|
|
60
60
|
role: "img",
|
|
61
61
|
"aria-hidden": "true"
|
|
62
62
|
}))));
|
|
63
|
-
}
|
|
63
|
+
};
|
|
64
64
|
FluidDatePickerSkeleton.propTypes = {
|
|
65
65
|
/**
|
|
66
66
|
* Specify an optional className to be applied to the outer FluidForm wrapper
|