@ringcentral/juno 1.12.4-beta.5873-31100a7c → 1.12.4-beta.5882-b67a215e
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/components/Downshift/Downshift.d.ts +1 -1
- package/components/Downshift/Downshift.js +1 -2
- package/components/Downshift/SuggestionList/SuggestionList.js +4 -5
- package/components/Downshift/SuggestionList/utils/useSuggestionList.d.ts +20 -7
- package/components/Downshift/SuggestionList/utils/useSuggestionList.js +88 -70
- package/components/Downshift/utils/DownshiftUtils.d.ts +2 -0
- package/components/Downshift/utils/DownshiftUtils.js +6 -0
- package/components/Downshift/utils/SelectItem.d.ts +3 -1
- package/components/Downshift/utils/index.d.ts +2 -0
- package/components/Downshift/utils/index.js +2 -0
- package/components/Downshift/utils/useDownshift.d.ts +13 -272
- package/components/Downshift/utils/useDownshift.js +132 -429
- package/components/Downshift/utils/useDownshiftGroup.js +1 -0
- package/components/Downshift/utils/useDownshiftTag.d.ts +554 -0
- package/components/Downshift/utils/useDownshiftTag.js +229 -0
- package/es6/components/Downshift/Downshift.js +1 -2
- package/es6/components/Downshift/SuggestionList/SuggestionList.js +4 -5
- package/es6/components/Downshift/SuggestionList/utils/useSuggestionList.js +90 -72
- package/es6/components/Downshift/utils/DownshiftUtils.js +5 -0
- package/es6/components/Downshift/utils/index.js +2 -0
- package/es6/components/Downshift/utils/useDownshift.js +135 -432
- package/es6/components/Downshift/utils/useDownshiftGroup.js +1 -0
- package/es6/components/Downshift/utils/useDownshiftTag.js +227 -0
- package/es6/foundation/hooks/useRefState/useRefState.js +6 -1
- package/foundation/hooks/useRefState/useRefState.js +6 -1
- package/package.json +1 -1
|
@@ -157,7 +157,7 @@ declare type RcDownshiftProps<T extends RcDownshiftSelectedItem = RcDownshiftSel
|
|
|
157
157
|
* render when not have any options,
|
|
158
158
|
* if set that the freeSolo auto add items will not be cover
|
|
159
159
|
*/
|
|
160
|
-
renderNoOptions?: (getNoOptionsProps: (additionProps?: HTMLAttributes<HTMLElement>) => HTMLAttributes<HTMLElement>, additionItem
|
|
160
|
+
renderNoOptions?: (getNoOptionsProps: (additionProps?: HTMLAttributes<HTMLElement>) => HTMLAttributes<HTMLElement>, additionItem: RcDownshiftSelectedItem | null) => React.ReactNode;
|
|
161
161
|
/**
|
|
162
162
|
* one of that character, also can be confirm a tag
|
|
163
163
|
* @default
|
|
@@ -66,7 +66,7 @@ var _RcDownshift = react_1.memo(react_1.forwardRef(function (inProps, ref) {
|
|
|
66
66
|
onKeyDown: onKeyDownProp,
|
|
67
67
|
disabledItemsHighlightable: disabledItemsHighlightable,
|
|
68
68
|
onGroupExpanded: onGroupExpanded,
|
|
69
|
-
}), focusInput = _z.focusInput, optionItems = _z.optionItems, optionsGroupList = _z.optionsGroupList, selectedItems = _z.
|
|
69
|
+
}), focusInput = _z.focusInput, optionItems = _z.optionItems, optionsGroupList = _z.optionsGroupList, selectedItems = _z.tags, highlightedIndex = _z.highlightedIndex, getToggleButtonProps = _z.getToggleButtonProps, getTagProps = _z.getTagProps, getTagListBoxProps = _z.getTagListBoxProps, getMenuProps = _z.getMenuProps, getPopperProps = _z.getPopperProps, getInputProps = _z.getInputProps, getInputAriaProps = _z.getInputAriaProps, getLabelProps = _z.getLabelProps, getItemProps = _z.getItemProps, isOpen = _z.isOpen, inputValue = _z.inputValue, activeIndex = _z.activeIndex, setActiveIndex = _z.setActiveIndex, setHighlightedIndex = _z.setHighlightedIndex, onInputChange = _z.onInputChange, keepHighlightedIndex = _z.keepHighlightedIndex, changeHighlightedIndexReason = _z.changeHighlightedIndexReason, closeMenu = _z.closeMenu, openMenu = _z.openMenu, reset = _z.reset, getClearButtonProps = _z.getClearButtonProps, noOptionItem = _z.noOptionItem, getNoOptionsProps = _z.getNoOptionsProps, isKeepHighlightedIndex = _z.isKeepHighlightedIndex, isDownshiftFocused = _z.focused;
|
|
70
70
|
var open = Boolean((isOpen || noOptionItem) && textFieldRef.current);
|
|
71
71
|
var _0 = getInputProps(), onBlur = _0.onBlur, InputProps = tslib_1.__rest(_0, ["onBlur"]);
|
|
72
72
|
var helperText = isNew
|
|
@@ -128,7 +128,6 @@ var _RcDownshift = react_1.memo(react_1.forwardRef(function (inProps, ref) {
|
|
|
128
128
|
} })));
|
|
129
129
|
});
|
|
130
130
|
})();
|
|
131
|
-
var isDownshiftFocused = focused !== null && focused !== void 0 ? focused : (isTagsFocus || isFocused ? true : undefined);
|
|
132
131
|
var endAdornment = (toggleButton || clearBtn) && (react_1.default.createElement(styles_1.EndAdornment, null,
|
|
133
132
|
clearBtn && (react_1.default.createElement(ClearIconButton_1.ClearIconButton, tslib_1.__assign({}, getClearButtonProps(clearButtonProps)))),
|
|
134
133
|
toggleButton && (react_1.default.createElement(styles_1.ArrowDownButton, tslib_1.__assign({ variant: "plain", "aria-hidden": true, color: isDownshiftFocused
|
|
@@ -23,7 +23,7 @@ var SuggestionList = react_1.forwardRef(function (inProps, ref) {
|
|
|
23
23
|
var highlightedIndex = props.highlightedIndex, options = props.options, getItemProps = props.getItemProps, getMenuProps = props.getMenuProps, renderOption = props.renderOption, inputValue = props.inputValue, groupVariant = props.groupVariant, groupExpanded = props.groupExpanded, renderGroup = props.renderGroup, optionsGroupList = props.optionsGroupList, getOptionDisabled = props.getOptionDisabled, MenuItem = props.MenuItem, changeHighlightedIndexReason = props.changeHighlightedIndexReason, isKeepHighlightedIndex = props.isKeepHighlightedIndex, componentsProp = props.components, onUpdatePopper = props.onUpdatePopper, getOptionLabel = props.getOptionLabel, padding = props.padding, _a = props.maxContainerHeight, maxContainerHeight = _a === void 0 ? '100%' : _a, classNameProp = props.className, classesProp = props.classes, rest = tslib_1.__rest(props, ["highlightedIndex", "options", "getItemProps", "getMenuProps", "renderOption", "inputValue", "groupVariant", "groupExpanded", "renderGroup", "optionsGroupList", "getOptionDisabled", "MenuItem", "changeHighlightedIndexReason", "isKeepHighlightedIndex", "components", "onUpdatePopper", "getOptionLabel", "padding", "maxContainerHeight", "className", "classes"]);
|
|
24
24
|
var vlRef = react_1.useRef(null);
|
|
25
25
|
var forkVlRef = foundation_1.useForkRef(ref, vlRef);
|
|
26
|
-
var
|
|
26
|
+
var isTitleMode = groupVariant === 'normal';
|
|
27
27
|
var listRef = react_1.useRef(null);
|
|
28
28
|
var itemData = options;
|
|
29
29
|
var itemCount = options.length;
|
|
@@ -81,7 +81,7 @@ var SuggestionList = react_1.forwardRef(function (inProps, ref) {
|
|
|
81
81
|
changeHighlightedIndexReason !== 'mouse') {
|
|
82
82
|
scrollToHighlightedIndex(prevHighlightedIndex, highlightedIndex,
|
|
83
83
|
// when title group topHighlightIndex to be 1, first item is group title
|
|
84
|
-
|
|
84
|
+
isTitleMode ? 1 : 0);
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
var handleScrolling = function (scrolling) {
|
|
@@ -100,9 +100,8 @@ var SuggestionList = react_1.forwardRef(function (inProps, ref) {
|
|
|
100
100
|
var _b, _c, _d, _e;
|
|
101
101
|
var currGroup = option.group;
|
|
102
102
|
var isGroupTitle = option === (currGroup === null || currGroup === void 0 ? void 0 : currGroup.options[0]);
|
|
103
|
-
var groupIndex = (optionsGroupList === null || optionsGroupList === void 0 ? void 0 : optionsGroupList.findIndex(function (x) { return x.group === (currGroup === null || currGroup === void 0 ? void 0 : currGroup.group); })) || 0;
|
|
104
103
|
var isFixedGroupExpanded = typeof groupExpanded === 'boolean';
|
|
105
|
-
var expandIconProps = !
|
|
104
|
+
var expandIconProps = !isTitleMode && !isFixedGroupExpanded && isGroupTitle
|
|
106
105
|
? (_c = (_b = option.group) === null || _b === void 0 ? void 0 : _b.getExpandIconProps) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
107
106
|
className: clsx_1.default(classes.toggle, (_a = {},
|
|
108
107
|
_a[classes.expanded] = (_d = option.group) === null || _d === void 0 ? void 0 : _d.expanded,
|
|
@@ -114,7 +113,7 @@ var SuggestionList = react_1.forwardRef(function (inProps, ref) {
|
|
|
114
113
|
className: isGroupTitle ? classes.groupTitle : undefined,
|
|
115
114
|
});
|
|
116
115
|
var selected = highlightedIndex === index;
|
|
117
|
-
var resultProps = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, option), itemProps), {
|
|
116
|
+
var resultProps = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, option), itemProps), { key: itemProps.id });
|
|
118
117
|
var indexInOwnGroup = resultProps.indexInOwnGroup;
|
|
119
118
|
delete resultProps.indexInOwnGroup;
|
|
120
119
|
// * when item is not disabled, that should check outside is that disabled
|
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
/// <reference types="styled-jsx" />
|
|
2
|
-
import { HTMLAttributes } from 'react';
|
|
2
|
+
import { ChangeEvent, HTMLAttributes } from 'react';
|
|
3
3
|
import { RcIconButtonProps } from '../../../Buttons/IconButton';
|
|
4
4
|
import { RcDownshiftProps } from '../../Downshift';
|
|
5
|
-
import {
|
|
5
|
+
import { RcDownshiftSelectedItem } from '../../utils/SelectItem';
|
|
6
|
+
import { RcDownshiftGetItemPropsOptions, RcDownshiftHighlightChangeReason } from '../../utils/useDownshift.interface';
|
|
6
7
|
declare type UseDownshiftParams<T = RcDownshiftSelectedItem> = {
|
|
8
|
+
/** current suggestion list unique id */
|
|
9
|
+
id?: string;
|
|
7
10
|
/** that input ref you binding event */
|
|
8
11
|
inputRef: React.RefObject<HTMLInputElement>;
|
|
12
|
+
/** process filtered options result, let you can handle result after filter */
|
|
13
|
+
processFilteredResult?: (options: T[], inputValue: string) => T[];
|
|
9
14
|
/** emit when item be select */
|
|
10
15
|
onSelect?: (event: React.ChangeEvent<{}>, selectedItems: T) => void;
|
|
11
16
|
} & Pick<RcDownshiftProps<T>, 'options' | 'value' | 'getOptionLabel' | 'filterOptions' | 'inputValue' | 'onInputChange' | 'onKeyDown' | 'onClear' | 'getOptionDisabled' | 'disabledItemsHighlightable' | 'variant' | 'groupBy' | 'getExpandIconProps' | 'groupExpanded' | 'groupDefaultExpanded' | 'onGroupExpanded' | 'groupVariant'>;
|
|
12
17
|
/**
|
|
13
18
|
* provide suggestion list with search function and expandable group with virtualized list
|
|
14
19
|
*/
|
|
15
|
-
export declare const useSuggestionList: <T extends RcDownshiftSelectedItem = RcDownshiftSelectedItem>({ inputValue: inputValueProp, getOptionLabel, filterOptions, disabledItemsHighlightable, options, onInputChange: onInputChangeProp, inputRef, onKeyDown: onKeyDownProp, onSelect, onClear, getOptionDisabled, groupBy, onGroupExpanded, groupVariant, groupExpanded, groupDefaultExpanded, getExpandIconProps, }: UseDownshiftParams<T>) => {
|
|
20
|
+
export declare const useSuggestionList: <T extends RcDownshiftSelectedItem = RcDownshiftSelectedItem>({ id, inputValue: inputValueProp, getOptionLabel, filterOptions, disabledItemsHighlightable, options, onInputChange: onInputChangeProp, inputRef, onKeyDown: onKeyDownProp, onSelect, onClear, getOptionDisabled, groupBy, onGroupExpanded, groupVariant, groupExpanded, groupDefaultExpanded, getExpandIconProps, processFilteredResult, }: UseDownshiftParams<T>) => {
|
|
21
|
+
reset: (isFocus?: boolean | undefined) => void;
|
|
22
|
+
clearInput: () => void;
|
|
23
|
+
forceUpdate: () => void;
|
|
16
24
|
focusInput: () => void | undefined;
|
|
25
|
+
updateInputValue: (newValue: string) => void;
|
|
26
|
+
selectItem: (e: ChangeEvent<{}>, selectedItem: T | null) => boolean;
|
|
27
|
+
onKeyFocusedIndexHandle: (event: import("react").KeyboardEvent<any>) => void;
|
|
17
28
|
getClearButtonProps: (props?: RcIconButtonProps | undefined) => RcIconButtonProps;
|
|
18
29
|
getLabelProps: (props?: Partial<import("@material-ui/core").InputLabelProps> | undefined) => Partial<import("@material-ui/core").InputLabelProps>;
|
|
19
30
|
getMenuProps: (restMenuProps?: HTMLAttributes<HTMLElement> | undefined) => HTMLAttributes<HTMLElement>;
|
|
@@ -280,6 +291,7 @@ export declare const useSuggestionList: <T extends RcDownshiftSelectedItem = RcD
|
|
|
280
291
|
onTransitionEnd?: ((event: import("react").TransitionEvent<HTMLElement>) => void) | undefined;
|
|
281
292
|
onTransitionEndCapture?: ((event: import("react").TransitionEvent<HTMLElement>) => void) | undefined;
|
|
282
293
|
};
|
|
294
|
+
highlightedIndexRef: import("react").MutableRefObject<number>;
|
|
283
295
|
highlightedIndex: number;
|
|
284
296
|
optionItems: T[];
|
|
285
297
|
inputValue: string;
|
|
@@ -288,11 +300,12 @@ export declare const useSuggestionList: <T extends RcDownshiftSelectedItem = RcD
|
|
|
288
300
|
reRender?: boolean | undefined;
|
|
289
301
|
reason?: RcDownshiftHighlightChangeReason;
|
|
290
302
|
}) => void;
|
|
303
|
+
changeHighlightedIndexReasonRef: import("react").MutableRefObject<RcDownshiftHighlightChangeReason>;
|
|
291
304
|
changeHighlightedIndexReason: RcDownshiftHighlightChangeReason;
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
optionsGroupList: import("../../utils").RcDownshiftGroupedOption<T>[];
|
|
295
|
-
/** current suggestion list id */
|
|
305
|
+
optionsGroupList: import("../../utils/SelectItem").RcDownshiftGroupedOption<T>[];
|
|
306
|
+
/** current unique id */
|
|
296
307
|
id: string;
|
|
308
|
+
getNextFocusableOption: (index?: number, isInfinite?: any) => number;
|
|
309
|
+
handleF10KeyDown: (e: import("react").KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
297
310
|
};
|
|
298
311
|
export {};
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var react_1 = require("react");
|
|
5
|
-
var uniqueId_1 = tslib_1.__importDefault(require("lodash/uniqueId"));
|
|
6
5
|
var utils_1 = require("@material-ui/core/utils");
|
|
7
6
|
var foundation_1 = require("../../../../foundation");
|
|
8
|
-
var
|
|
7
|
+
var DownshiftUtils_1 = require("../../utils/DownshiftUtils");
|
|
9
8
|
var useDownshiftGroup_1 = require("../../utils/useDownshiftGroup");
|
|
10
9
|
var DEFAULT_HIGHLIGHTED_INDEX = -1;
|
|
11
10
|
var componentName = 'useSuggestionList';
|
|
@@ -13,7 +12,8 @@ var componentName = 'useSuggestionList';
|
|
|
13
12
|
* provide suggestion list with search function and expandable group with virtualized list
|
|
14
13
|
*/
|
|
15
14
|
exports.useSuggestionList = function (_a) {
|
|
16
|
-
var inputValueProp = _a.inputValue, _b = _a.getOptionLabel, getOptionLabel = _b === void 0 ?
|
|
15
|
+
var id = _a.id, inputValueProp = _a.inputValue, _b = _a.getOptionLabel, getOptionLabel = _b === void 0 ? DownshiftUtils_1.DEFAULT_GET_OPTION_LABEL : _b, filterOptions = _a.filterOptions, disabledItemsHighlightable = _a.disabledItemsHighlightable, options = _a.options, onInputChangeProp = _a.onInputChange, inputRef = _a.inputRef, onKeyDownProp = _a.onKeyDown, onSelect = _a.onSelect, onClear = _a.onClear, getOptionDisabled = _a.getOptionDisabled, groupBy = _a.groupBy, onGroupExpanded = _a.onGroupExpanded, groupVariant = _a.groupVariant, groupExpanded = _a.groupExpanded, groupDefaultExpanded = _a.groupDefaultExpanded, getExpandIconProps = _a.getExpandIconProps, processFilteredResult = _a.processFilteredResult;
|
|
16
|
+
var isTitleMode = groupVariant === 'normal';
|
|
17
17
|
var _c = tslib_1.__read(utils_1.useControlled({
|
|
18
18
|
controlled: inputValueProp,
|
|
19
19
|
default: '',
|
|
@@ -24,44 +24,44 @@ exports.useSuggestionList = function (_a) {
|
|
|
24
24
|
setInputValue(newValue);
|
|
25
25
|
};
|
|
26
26
|
var focusInput = function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
27
|
-
var
|
|
28
|
-
return uniqueId_1.default("suggestion-list-");
|
|
29
|
-
}).current;
|
|
30
|
-
// * use -2 for us know that is init state, for recalculate defaultHighlightedIndex
|
|
27
|
+
var currUniqueId = foundation_1.useId(id || 'suggestion-list', !id);
|
|
31
28
|
var highlightedIndexRef = react_1.useRef(DEFAULT_HIGHLIGHTED_INDEX);
|
|
32
|
-
var
|
|
29
|
+
var changeHighlightedIndexReasonRef = react_1.useRef();
|
|
33
30
|
var forceUpdate = foundation_1.useForceUpdate();
|
|
31
|
+
var getFilteredItems = react_1.useCallback(function (items) {
|
|
32
|
+
if (filterOptions) {
|
|
33
|
+
return filterOptions(items, {
|
|
34
|
+
inputValue: inputValue,
|
|
35
|
+
getOptionLabel: getOptionLabel,
|
|
36
|
+
selectedItems: [],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return items;
|
|
40
|
+
}, [filterOptions, getOptionLabel, inputValue]);
|
|
34
41
|
var filteredResult = react_1.useMemo(function () {
|
|
35
|
-
var getFilteredItems = function (items) {
|
|
36
|
-
if (filterOptions) {
|
|
37
|
-
return filterOptions(items, {
|
|
38
|
-
inputValue: inputValue,
|
|
39
|
-
getOptionLabel: getOptionLabel,
|
|
40
|
-
selectedItems: [],
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return items;
|
|
44
|
-
};
|
|
45
42
|
// * only when isOpen calculate the filtered result
|
|
46
43
|
var results = getFilteredItems(options);
|
|
44
|
+
results = processFilteredResult
|
|
45
|
+
? processFilteredResult(results, inputValue)
|
|
46
|
+
: results;
|
|
47
47
|
return results;
|
|
48
|
-
}, [
|
|
48
|
+
}, [getFilteredItems, inputValue, options, processFilteredResult]);
|
|
49
49
|
var _d = useDownshiftGroup_1.useDownshiftGroup({
|
|
50
|
-
|
|
50
|
+
id: currUniqueId,
|
|
51
51
|
options: options,
|
|
52
52
|
filteredResult: filteredResult,
|
|
53
|
-
getExpandIconProps: getExpandIconProps,
|
|
54
53
|
groupExpanded: groupExpanded,
|
|
55
54
|
groupDefaultExpanded: groupDefaultExpanded,
|
|
56
|
-
onGroupExpanded: onGroupExpanded,
|
|
57
55
|
groupVariant: groupVariant,
|
|
56
|
+
groupBy: groupBy,
|
|
57
|
+
getExpandIconProps: getExpandIconProps,
|
|
58
|
+
onGroupExpanded: onGroupExpanded,
|
|
58
59
|
getOptionDisabled: getOptionDisabled,
|
|
59
|
-
id: suggestionListId,
|
|
60
60
|
}), groupedResult = _d.groupedResult, handleGroupExpandedChange = _d.handleGroupExpandedChange, optionsGroupList = _d.optionsGroupList;
|
|
61
61
|
var optionItems = groupBy ? groupedResult : filteredResult;
|
|
62
62
|
var setHighlightedIndex = function (index, _a) {
|
|
63
63
|
var _b = _a.reRender, reRender = _b === void 0 ? false : _b, reason = _a.reason;
|
|
64
|
-
|
|
64
|
+
changeHighlightedIndexReasonRef.current = reason;
|
|
65
65
|
if (highlightedIndexRef.current !== index) {
|
|
66
66
|
highlightedIndexRef.current = index;
|
|
67
67
|
if (reRender)
|
|
@@ -77,27 +77,27 @@ exports.useSuggestionList = function (_a) {
|
|
|
77
77
|
};
|
|
78
78
|
var getIsItemCanSelected = function (item) {
|
|
79
79
|
return ((!!item && item.freeSolo) ||
|
|
80
|
-
(
|
|
80
|
+
(DownshiftUtils_1.isItemCanSelected(item) && !(getOptionDisabled === null || getOptionDisabled === void 0 ? void 0 : getOptionDisabled(item))));
|
|
81
81
|
};
|
|
82
|
-
var
|
|
82
|
+
var selectItem = function (e, selectedItem) {
|
|
83
83
|
if (getIsItemCanSelected(selectedItem)) {
|
|
84
84
|
onSelect === null || onSelect === void 0 ? void 0 : onSelect(e, selectedItem);
|
|
85
85
|
return true;
|
|
86
86
|
}
|
|
87
87
|
return false;
|
|
88
88
|
};
|
|
89
|
-
var
|
|
89
|
+
var clearInput = function () {
|
|
90
90
|
if (inputRef.current && inputRef.current.value.length > 0) {
|
|
91
91
|
updateInputValue('');
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
var reset = function (isFocus) {
|
|
95
|
-
|
|
95
|
+
clearInput();
|
|
96
96
|
onInputChangeProp === null || onInputChangeProp === void 0 ? void 0 : onInputChangeProp('');
|
|
97
97
|
if (isFocus)
|
|
98
98
|
focusInput();
|
|
99
99
|
};
|
|
100
|
-
var
|
|
100
|
+
var _e = foundation_1.useKeyboardMoveFocus({
|
|
101
101
|
options: optionItems,
|
|
102
102
|
focusedIndexRef: highlightedIndexRef,
|
|
103
103
|
infinite: true,
|
|
@@ -110,29 +110,44 @@ exports.useSuggestionList = function (_a) {
|
|
|
110
110
|
: function (child) {
|
|
111
111
|
return !getIsItemCanSelected(child);
|
|
112
112
|
},
|
|
113
|
-
}).onKeyFocusedIndexHandle;
|
|
113
|
+
}), onKeyFocusedIndexHandle = _e.onKeyFocusedIndexHandle, getNextFocusableOption = _e.getNextFocusableOption;
|
|
114
114
|
var getItemProps = function (_a) {
|
|
115
|
-
var item = _a.item,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
onMouseDown: function (e) {
|
|
115
|
+
var item = _a.item, _b = _a.index, index = _b === void 0 ? 0 : _b, itemRest = tslib_1.__rest(_a, ["item", "index"]);
|
|
116
|
+
var currGroup = item.group;
|
|
117
|
+
var isGroupTitle = item === (currGroup === null || currGroup === void 0 ? void 0 : currGroup.options[0]);
|
|
118
|
+
var itemCount = optionItems.length;
|
|
119
|
+
var groupOrder = (currGroup === null || currGroup === void 0 ? void 0 : currGroup.order) || 0;
|
|
120
|
+
return foundation_1.combineProps(tslib_1.__assign({ id: currUniqueId + "-option-" + index, onClick: function (e) {
|
|
121
|
+
selectItem(e, item);
|
|
122
|
+
}, onMouseDown: function (e) {
|
|
123
123
|
e.preventDefault();
|
|
124
124
|
e.stopPropagation();
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
}, onMouseOver: function () {
|
|
126
|
+
if (highlightedIndexRef.current !== index &&
|
|
127
|
+
getIsItemCanSelected(item)) {
|
|
128
128
|
setHighlightedIndex(index, { reason: 'mouse', reRender: true });
|
|
129
129
|
}
|
|
130
|
-
},
|
|
131
|
-
|
|
130
|
+
} }, (isTitleMode && isGroupTitle
|
|
131
|
+
? {}
|
|
132
|
+
: {
|
|
133
|
+
role: 'option',
|
|
134
|
+
'aria-setsize': itemCount - (isTitleMode ? (optionsGroupList === null || optionsGroupList === void 0 ? void 0 : optionsGroupList.length) || 0 : 0),
|
|
135
|
+
'aria-posinset': index - (isTitleMode ? groupOrder + 1 : 0),
|
|
136
|
+
})), itemRest);
|
|
137
|
+
};
|
|
138
|
+
var handleF10KeyDown = function (e) {
|
|
139
|
+
var highlightedIndex = highlightedIndexRef.current;
|
|
140
|
+
if (e.shiftKey) {
|
|
141
|
+
var currOption = optionItems[highlightedIndex];
|
|
142
|
+
var currentGroup = currOption.group;
|
|
143
|
+
if (currentGroup && currentGroup.options.length > 1) {
|
|
144
|
+
handleGroupExpandedChange(currentGroup.group);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
132
147
|
};
|
|
133
148
|
var getInputProps = function (props) {
|
|
134
149
|
return foundation_1.combineProps({
|
|
135
|
-
id:
|
|
150
|
+
id: currUniqueId + "-input",
|
|
136
151
|
autoComplete: 'off',
|
|
137
152
|
onChange: function (e) {
|
|
138
153
|
var changeValue = e.target.value;
|
|
@@ -141,18 +156,12 @@ exports.useSuggestionList = function (_a) {
|
|
|
141
156
|
onKeyDown: function (e) {
|
|
142
157
|
var _a;
|
|
143
158
|
onKeyDownProp === null || onKeyDownProp === void 0 ? void 0 : onKeyDownProp(e, highlightedIndexRef.current);
|
|
144
|
-
var highlightedIndex = highlightedIndexRef.current;
|
|
145
159
|
switch (e.key) {
|
|
146
160
|
case 'F10':
|
|
147
|
-
|
|
148
|
-
var currOption = optionItems[highlightedIndex];
|
|
149
|
-
var currentGroup = currOption.group;
|
|
150
|
-
if (currentGroup && currentGroup.options.length > 1) {
|
|
151
|
-
handleGroupExpandedChange(currentGroup.group);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
161
|
+
handleF10KeyDown(e);
|
|
154
162
|
break;
|
|
155
|
-
case 'Enter':
|
|
163
|
+
case 'Enter': {
|
|
164
|
+
var highlightedIndex = highlightedIndexRef.current;
|
|
156
165
|
if (e.which === 229)
|
|
157
166
|
return;
|
|
158
167
|
if (highlightedIndex !== DEFAULT_HIGHLIGHTED_INDEX) {
|
|
@@ -163,13 +172,14 @@ exports.useSuggestionList = function (_a) {
|
|
|
163
172
|
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
164
173
|
}
|
|
165
174
|
else {
|
|
166
|
-
|
|
175
|
+
selectItem(e, currOption);
|
|
167
176
|
}
|
|
168
177
|
e.stopPropagation();
|
|
169
178
|
}
|
|
170
179
|
// always preventDefault for not inset all enter into textarea
|
|
171
180
|
e.preventDefault();
|
|
172
181
|
break;
|
|
182
|
+
}
|
|
173
183
|
default:
|
|
174
184
|
onKeyFocusedIndexHandle(e);
|
|
175
185
|
break;
|
|
@@ -183,57 +193,65 @@ exports.useSuggestionList = function (_a) {
|
|
|
183
193
|
onContainerClick: focusInput,
|
|
184
194
|
role: 'combobox',
|
|
185
195
|
'aria-autocomplete': 'list',
|
|
186
|
-
// TODO
|
|
187
196
|
'aria-expanded': true,
|
|
188
197
|
'aria-haspopup': true,
|
|
189
|
-
'aria-owns':
|
|
198
|
+
'aria-owns': currUniqueId + "-menu",
|
|
190
199
|
'aria-activedescendant': highlightedIndexRef.current > -1
|
|
191
|
-
?
|
|
200
|
+
? currUniqueId + "-option-" + highlightedIndexRef.current
|
|
192
201
|
: undefined,
|
|
193
202
|
}, props);
|
|
194
203
|
};
|
|
195
204
|
var getLabelProps = function (props) {
|
|
196
205
|
return foundation_1.combineProps({
|
|
197
|
-
htmlFor:
|
|
198
|
-
id:
|
|
206
|
+
htmlFor: currUniqueId + "-input",
|
|
207
|
+
id: currUniqueId + "-label",
|
|
199
208
|
}, props);
|
|
200
209
|
};
|
|
201
210
|
var getMenuProps = function (restMenuProps) {
|
|
202
211
|
return foundation_1.combineProps({
|
|
203
|
-
'aria-labelledby':
|
|
204
|
-
id:
|
|
212
|
+
'aria-labelledby': currUniqueId + "-label",
|
|
213
|
+
id: currUniqueId + "-menu",
|
|
205
214
|
role: 'listbox',
|
|
206
215
|
}, restMenuProps);
|
|
207
216
|
};
|
|
208
217
|
var getClearButtonProps = function (props) {
|
|
209
218
|
return foundation_1.combineProps({
|
|
210
|
-
id:
|
|
219
|
+
id: currUniqueId + "-clear-button",
|
|
211
220
|
onClick: function (e) {
|
|
212
221
|
onClear === null || onClear === void 0 ? void 0 : onClear(e);
|
|
213
222
|
reset(true);
|
|
214
223
|
},
|
|
215
224
|
}, props);
|
|
216
225
|
};
|
|
217
|
-
|
|
226
|
+
react_1.useEffect(function () {
|
|
227
|
+
changeHighlightedIndexReasonRef.current = undefined;
|
|
228
|
+
});
|
|
229
|
+
return {
|
|
230
|
+
reset: reset,
|
|
231
|
+
clearInput: clearInput,
|
|
232
|
+
forceUpdate: forceUpdate,
|
|
218
233
|
focusInput: focusInput,
|
|
234
|
+
updateInputValue: updateInputValue,
|
|
235
|
+
selectItem: selectItem,
|
|
236
|
+
onKeyFocusedIndexHandle: onKeyFocusedIndexHandle,
|
|
219
237
|
getClearButtonProps: getClearButtonProps,
|
|
220
238
|
getLabelProps: getLabelProps,
|
|
221
239
|
getMenuProps: getMenuProps,
|
|
222
240
|
getInputProps: getInputProps,
|
|
223
241
|
getInputAriaProps: getInputAriaProps,
|
|
224
242
|
getItemProps: getItemProps,
|
|
243
|
+
highlightedIndexRef: highlightedIndexRef,
|
|
225
244
|
highlightedIndex: highlightedIndexRef.current,
|
|
226
245
|
optionItems: optionItems,
|
|
227
246
|
inputValue: inputValue,
|
|
228
247
|
onInputChange: handleInputChange,
|
|
229
248
|
setHighlightedIndex: setHighlightedIndex,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
forceUpdate: forceUpdate,
|
|
249
|
+
changeHighlightedIndexReasonRef: changeHighlightedIndexReasonRef,
|
|
250
|
+
changeHighlightedIndexReason: changeHighlightedIndexReasonRef.current,
|
|
233
251
|
optionsGroupList: optionsGroupList,
|
|
234
|
-
/** current
|
|
235
|
-
id:
|
|
252
|
+
/** current unique id */
|
|
253
|
+
id: currUniqueId,
|
|
254
|
+
getNextFocusableOption: getNextFocusableOption,
|
|
255
|
+
handleF10KeyDown: handleF10KeyDown,
|
|
236
256
|
};
|
|
237
|
-
changeHighlightedIndexReason.current = undefined;
|
|
238
|
-
return resultObj;
|
|
239
257
|
};
|
|
@@ -19,3 +19,5 @@ export declare const RcDownshiftDefaultFilterOptions: RcDownshiftProps['filterOp
|
|
|
19
19
|
* - only filter options by input value when have input value changed
|
|
20
20
|
*/
|
|
21
21
|
export declare const RcAutocompleteDefaultFilterOptions: RcDownshiftProps['filterOptions'];
|
|
22
|
+
export declare const downshiftComponentName = "RcDownshift";
|
|
23
|
+
export declare function stringArrToRegExp(keyToTags?: string[]): RegExp;
|
|
@@ -40,3 +40,9 @@ exports.RcAutocompleteDefaultFilterOptions = function (options, _a) {
|
|
|
40
40
|
}
|
|
41
41
|
return options.filter(function (item) { return getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(item).toLowerCase().startsWith((inputValue === null || inputValue === void 0 ? void 0 : inputValue.toLowerCase()) || ''); });
|
|
42
42
|
};
|
|
43
|
+
exports.downshiftComponentName = 'RcDownshift';
|
|
44
|
+
function stringArrToRegExp(keyToTags) {
|
|
45
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
46
|
+
return new RegExp((keyToTags === null || keyToTags === void 0 ? void 0 : keyToTags.join('|')) || '', 'g');
|
|
47
|
+
}
|
|
48
|
+
exports.stringArrToRegExp = stringArrToRegExp;
|
|
@@ -50,8 +50,10 @@ export declare type RcDownshiftSelectedItemAdditionProps = {
|
|
|
50
50
|
export interface RcDownshiftGroupedOption<T = RcDownshiftSelectedItem> {
|
|
51
51
|
/** group key */
|
|
52
52
|
key: number;
|
|
53
|
-
/** group index */
|
|
53
|
+
/** group index in all options */
|
|
54
54
|
index: number;
|
|
55
|
+
/** group order in all group */
|
|
56
|
+
order: number;
|
|
55
57
|
/** group title */
|
|
56
58
|
group: string;
|
|
57
59
|
/** expanded state */
|
|
@@ -4,3 +4,5 @@ var tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./DownshiftUtils"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./useDownshift"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./useDownshiftError"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./useDownshiftGroup"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./useDownshiftTag"), exports);
|