@rescui/select 0.15.1-RUI-280-Update-select-component-separate-components-e772abaa1.56 → 0.15.1-RUI-280-Update-select-component-downshift-cd2a98813.66
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/lib/_virtual/index.css.js +12 -12
- package/lib/constants.d.ts +0 -1
- package/lib/constants.js +1 -2
- package/lib/hooks/use-a11y.d.ts +29 -0
- package/lib/hooks/use-a11y.js +53 -0
- package/lib/hooks/use-backward-compatible-id.d.ts +4 -0
- package/lib/hooks/use-backward-compatible-id.js +14 -0
- package/lib/hooks/use-label-focus.d.ts +1 -3
- package/lib/hooks/use-label-focus.js +3 -9
- package/lib/hooks/use-multi-handlers.d.ts +11 -0
- package/lib/hooks/use-multi-handlers.js +48 -0
- package/lib/hooks/use-options.d.ts +13 -0
- package/lib/hooks/use-options.js +89 -0
- package/lib/index.css +323 -371
- package/lib/multiselect.d.ts +3 -29
- package/lib/multiselect.js +249 -174
- package/lib/native-select.js +67 -46
- package/lib/parts/hidden-select.d.ts +13 -0
- package/lib/parts/hidden-select.js +45 -0
- package/lib/parts/icons.d.ts +3 -1
- package/lib/parts/icons.js +11 -14
- package/lib/parts/list-box.d.ts +7 -15
- package/lib/parts/list-box.js +50 -82
- package/lib/parts/multi-trigger.d.ts +5 -4
- package/lib/parts/multi-trigger.js +27 -15
- package/lib/parts/native-select-trigger.d.ts +6 -8
- package/lib/parts/native-select-trigger.js +14 -23
- package/lib/select-basic.d.ts +2 -2
- package/lib/select-basic.js +161 -97
- package/lib/select-searchable.d.ts +2 -2
- package/lib/select-searchable.js +208 -122
- package/lib/select.d.ts +1 -1
- package/lib/select.js +38 -31
- package/lib/styles/common.p.module.css.js +25 -24
- package/lib/styles/form-trigger.p.module.css.js +12 -12
- package/lib/styles/list-box.p.module.css.js +11 -13
- package/lib/styles/native-select-trigger.p.module.css.js +15 -14
- package/lib/styles/native-select.p.module.css.js +6 -6
- package/lib/types.d.ts +26 -27
- package/lib/utils/get-real-items-cnt.d.ts +2 -2
- package/lib/utils/get-real-items-cnt.js +8 -10
- package/lib/utils/item-to-string.d.ts +2 -0
- package/lib/utils/item-to-string.js +7 -0
- package/lib/utils/merge-props.d.ts +29 -0
- package/lib/utils/merge-props.js +106 -0
- package/package.json +13 -22
- package/lib/hooks/use-css-context-transfer.d.ts +0 -14
- package/lib/hooks/use-css-context-transfer.js +0 -40
- package/lib/hooks/use-multi-option-serialization.d.ts +0 -10
- package/lib/hooks/use-multi-option-serialization.js +0 -82
- package/lib/hooks/use-observable-force-rerender.d.ts +0 -2
- package/lib/hooks/use-observable-force-rerender.js +0 -16
- package/lib/hooks/use-option-serialization.d.ts +0 -10
- package/lib/hooks/use-option-serialization.js +0 -59
- package/lib/parts/popover.d.ts +0 -12
- package/lib/parts/popover.js +0 -64
- package/lib/parts/popup-content.d.ts +0 -19
- package/lib/parts/popup-content.js +0 -76
- package/lib/styles/popover.p.module.css.js +0 -10
- package/lib/utils/convert-options.d.ts +0 -3
- package/lib/utils/convert-options.js +0 -52
- package/lib/utils/convert-placement.d.ts +0 -3
- package/lib/utils/convert-placement.js +0 -22
- package/lib/utils/css-vars-utils.d.ts +0 -3
- package/lib/utils/css-vars-utils.js +0 -20
package/lib/multiselect.d.ts
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export declare function Multiselect({ options, value, onChange, error, note, size, mode, theme: themeFromProps, placement, isSingleLine, boldLabel, reserveErrorLine, maxVisibleItems, isClearable, isLoading, isDisabled, ...props }: MultiselectProps): JSX.Element;
|
|
5
|
-
export declare namespace Multiselect {
|
|
6
|
-
var propTypes: {
|
|
7
|
-
className: PropTypes.Requireable<string>;
|
|
8
|
-
style: PropTypes.Requireable<object>;
|
|
9
|
-
options: React.Validator<SelectOptionOrGroup[]>;
|
|
10
|
-
value: React.Validator<SelectOption[]>;
|
|
11
|
-
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
12
|
-
size: PropTypes.Requireable<string>;
|
|
13
|
-
mode: PropTypes.Requireable<string>;
|
|
14
|
-
theme: PropTypes.Requireable<string>;
|
|
15
|
-
placeholder: PropTypes.Requireable<string>;
|
|
16
|
-
isSingleLine: PropTypes.Requireable<boolean>;
|
|
17
|
-
isClearable: PropTypes.Requireable<boolean>;
|
|
18
|
-
isDisabled: PropTypes.Requireable<boolean>;
|
|
19
|
-
isLoading: PropTypes.Requireable<boolean>;
|
|
20
|
-
error: React.Validator<React.ReactNode>;
|
|
21
|
-
label: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
22
|
-
note: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
23
|
-
id: PropTypes.Requireable<string>;
|
|
24
|
-
noOptionsMessage: React.Validator<NoOptionsMessage>;
|
|
25
|
-
placement: PropTypes.Requireable<string>;
|
|
26
|
-
name: PropTypes.Requireable<string>;
|
|
27
|
-
boldLabel: PropTypes.Requireable<boolean>;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { MultiselectProps } from './types';
|
|
3
|
+
export declare function Multiselect({ options, value: selectedItems, onChange, error, label, note, size, mode, theme: themeFromProps, placement, isSingleLine, boldLabel, reserveErrorLine, maxVisibleItems, isClearable, isLoading, isDisabled, name, noOptionsMessage, className, id, style, placeholder, ...rest }: MultiselectProps): JSX.Element;
|
package/lib/multiselect.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { useRef } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
4
2
|
import cn from 'classnames';
|
|
5
|
-
import {
|
|
6
|
-
import { useSelect
|
|
7
|
-
import { useButton } from '@react-aria/button';
|
|
8
|
-
import { useFocusRing } from '@react-aria/focus';
|
|
9
|
-
import { mergeProps } from '@react-aria/utils';
|
|
3
|
+
import { Dropdown } from '@rescui/dropdown';
|
|
4
|
+
import { useSelect } from 'downshift';
|
|
10
5
|
import { useThemeWithUndefined } from '@rescui/ui-contexts';
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
6
|
+
import { useFocusRing } from '@react-aria/focus';
|
|
7
|
+
import scrollIntoView from 'scroll-into-view-if-needed';
|
|
8
|
+
import { useLabelFocus } from './hooks/use-label-focus.js';
|
|
9
|
+
import { useOptions } from './hooks/use-options.js';
|
|
10
|
+
import { useMultiHandlers } from './hooks/use-multi-handlers.js';
|
|
11
|
+
import { useA11y } from './hooks/use-a11y.js';
|
|
12
|
+
import { ListBox } from './parts/list-box.js';
|
|
14
13
|
import { Icons } from './parts/icons.js';
|
|
15
|
-
import { FormTriggerWrapper } from './parts/form-trigger-wrapper.js';
|
|
16
14
|
import { MultiTrigger } from './parts/multi-trigger.js';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
15
|
+
import { HiddenSelect } from './parts/hidden-select.js';
|
|
16
|
+
import { FormTriggerWrapper } from './parts/form-trigger-wrapper.js';
|
|
19
17
|
import { getEmptyMessage } from './utils/get-empty-message.js';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
18
|
+
import { mergeProps } from './utils/merge-props.js';
|
|
19
|
+
import { itemToString } from './utils/item-to-string.js';
|
|
22
20
|
import { getOptionValue } from './utils/get-option-value.js';
|
|
21
|
+
import { getRealItemsCnt } from './utils/get-real-items-cnt.js';
|
|
23
22
|
import styles from './styles/common.p.module.css.js';
|
|
24
23
|
const THEME_STYLES = {
|
|
25
24
|
light: styles.themeLight,
|
|
@@ -33,65 +32,188 @@ const SIZE_STYLES = {
|
|
|
33
32
|
const MODE_STYLES = {
|
|
34
33
|
classic: styles.classic,
|
|
35
34
|
rock: styles.rock
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const stateReducer = (state, actionAndChanges) => {
|
|
38
|
+
const {
|
|
39
|
+
changes,
|
|
40
|
+
type
|
|
41
|
+
} = actionAndChanges; // console.log(type, state, changes);
|
|
42
|
+
|
|
43
|
+
switch (type) {
|
|
44
|
+
case useSelect.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
45
|
+
case useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
46
|
+
case useSelect.stateChangeTypes.ItemClick:
|
|
47
|
+
return { ...changes,
|
|
48
|
+
isOpen: true,
|
|
49
|
+
highlightedIndex: state.highlightedIndex
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
default:
|
|
53
|
+
return { ...changes,
|
|
54
|
+
selectedItem: null
|
|
55
|
+
};
|
|
56
|
+
}
|
|
36
57
|
}; // eslint-disable-next-line complexity
|
|
37
58
|
|
|
38
|
-
|
|
59
|
+
|
|
60
|
+
function Multiselect(_ref) {
|
|
39
61
|
let {
|
|
62
|
+
options = [],
|
|
63
|
+
value: selectedItems = [],
|
|
64
|
+
onChange,
|
|
65
|
+
error,
|
|
66
|
+
label,
|
|
67
|
+
note,
|
|
68
|
+
size = 'm',
|
|
69
|
+
mode = 'classic',
|
|
70
|
+
theme: themeFromProps,
|
|
71
|
+
placement = 'bottom',
|
|
72
|
+
isSingleLine = false,
|
|
73
|
+
boldLabel = true,
|
|
74
|
+
reserveErrorLine = false,
|
|
75
|
+
maxVisibleItems = 5,
|
|
76
|
+
isClearable = false,
|
|
77
|
+
isLoading = false,
|
|
78
|
+
isDisabled = false,
|
|
79
|
+
name,
|
|
80
|
+
noOptionsMessage,
|
|
81
|
+
className,
|
|
40
82
|
id,
|
|
41
|
-
size,
|
|
42
|
-
mode,
|
|
43
|
-
theme,
|
|
44
83
|
style,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
isLoading,
|
|
48
|
-
placement,
|
|
49
|
-
boldLabel,
|
|
50
|
-
reserveErrorLine,
|
|
51
|
-
noOptionsMessage,
|
|
52
|
-
maxVisibleItems,
|
|
53
|
-
isSingleLine,
|
|
54
|
-
...ariaProps
|
|
84
|
+
placeholder,
|
|
85
|
+
...rest
|
|
55
86
|
} = _ref;
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
87
|
+
const theme = useThemeWithUndefined(themeFromProps);
|
|
88
|
+
const triggerRef = React.useRef(null);
|
|
89
|
+
const menuRef = React.useRef(null);
|
|
90
|
+
const dropdownRef = React.useRef(null);
|
|
91
|
+
const {
|
|
92
|
+
selectedMap,
|
|
93
|
+
removeItem: removeSelectedItem,
|
|
94
|
+
addItem: addSelectedItem,
|
|
95
|
+
removeAllItems: reset
|
|
96
|
+
} = useMultiHandlers({
|
|
97
|
+
selectedItems,
|
|
98
|
+
onChange
|
|
60
99
|
});
|
|
61
|
-
const hasValue = state.selectedItems.length > 0; // Get props for child elements from useSelect
|
|
62
|
-
|
|
63
|
-
const triggerRef = useRef(null);
|
|
64
100
|
const {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
101
|
+
flattenedOptions,
|
|
102
|
+
listBoxItems
|
|
103
|
+
} = useOptions(options);
|
|
104
|
+
const isListBoxEmpty = getRealItemsCnt(listBoxItems) === 0;
|
|
105
|
+
const {
|
|
106
|
+
fieldProps,
|
|
70
107
|
errorMessageProps,
|
|
71
|
-
descriptionProps
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
108
|
+
descriptionProps,
|
|
109
|
+
baseId
|
|
110
|
+
} = useA11y({
|
|
111
|
+
prefix: 'multiselect',
|
|
112
|
+
error,
|
|
113
|
+
description: note
|
|
114
|
+
});
|
|
115
|
+
const {
|
|
116
|
+
isOpen,
|
|
117
|
+
getToggleButtonProps,
|
|
118
|
+
getLabelProps,
|
|
119
|
+
getMenuProps,
|
|
120
|
+
highlightedIndex,
|
|
121
|
+
getItemProps,
|
|
122
|
+
setHighlightedIndex
|
|
123
|
+
} = useSelect({
|
|
124
|
+
items: flattenedOptions,
|
|
125
|
+
itemToString,
|
|
126
|
+
id: baseId,
|
|
127
|
+
|
|
128
|
+
onIsOpenChange(newIsOpen) {
|
|
129
|
+
if (newIsOpen) {
|
|
130
|
+
// set the first selected item as a highlighted item if the popup is opened
|
|
131
|
+
const firstSelectedKey = [...selectedMap.keys()][0];
|
|
132
|
+
|
|
133
|
+
if (firstSelectedKey) {
|
|
134
|
+
setHighlightedIndex(flattenedOptions.findIndex(item => firstSelectedKey === getOptionValue(item)));
|
|
79
135
|
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
stateReducer,
|
|
140
|
+
// there's no actual selection happening in the hook, we're doing it custom via controlled props.
|
|
141
|
+
selectedItem: null,
|
|
142
|
+
// defining our scroll behavior because on the first menu render the hook
|
|
143
|
+
// doesn't know menuRef and use page as the scroll boundary
|
|
144
|
+
scrollIntoView: (listItemEl, listEl) => {
|
|
145
|
+
scrollIntoView(listItemEl, {
|
|
146
|
+
scrollMode: 'if-needed',
|
|
147
|
+
block: 'nearest',
|
|
148
|
+
boundary: listEl ?? menuRef.current
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
onSelectedItemChange: _ref2 => {
|
|
152
|
+
let {
|
|
153
|
+
selectedItem
|
|
154
|
+
} = _ref2;
|
|
155
|
+
|
|
156
|
+
if (!selectedItem) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const changedValue = getOptionValue(selectedItem);
|
|
161
|
+
|
|
162
|
+
if (selectedMap.has(changedValue)) {
|
|
163
|
+
removeSelectedItem(selectedItem);
|
|
164
|
+
} else {
|
|
165
|
+
addSelectedItem(selectedItem);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
80
168
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
169
|
+
isItemDisabled(item) {
|
|
170
|
+
return item && item.disabled;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
});
|
|
174
|
+
const menuProps = getMenuProps({
|
|
175
|
+
ref: menuRef,
|
|
176
|
+
'aria-multiselectable': isListBoxEmpty ? undefined : 'true'
|
|
177
|
+
}, {
|
|
178
|
+
suppressRefError: true
|
|
179
|
+
});
|
|
180
|
+
const triggerProps = getToggleButtonProps({
|
|
181
|
+
ref: triggerRef,
|
|
182
|
+
// eslint-disable-next-line complexity
|
|
183
|
+
onKeyDown: event => {
|
|
184
|
+
// shift + arrow up/down selection (when popup is open)
|
|
185
|
+
if (isOpen && event.shiftKey && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) {
|
|
186
|
+
const newHighlightedIndex = event.key === 'ArrowUp' ? Math.max(highlightedIndex - 1, 0) : Math.min(highlightedIndex + 1, flattenedOptions.length - 1);
|
|
187
|
+
|
|
188
|
+
if (newHighlightedIndex === highlightedIndex) {
|
|
189
|
+
return;
|
|
84
190
|
}
|
|
191
|
+
|
|
192
|
+
addSelectedItem(flattenedOptions[newHighlightedIndex]);
|
|
193
|
+
} // backspace removing the last selected item (when popup is closed)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
if (!isOpen && event.key === 'Backspace') {
|
|
197
|
+
removeSelectedItem(selectedItems[selectedItems.length - 1]);
|
|
198
|
+
} // delete removing all selected items (when popup is closed)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
if (!isOpen && event.key === 'Delete') {
|
|
202
|
+
reset();
|
|
85
203
|
}
|
|
204
|
+
},
|
|
205
|
+
// fix screen-reader focus on an opened popup with an empty list
|
|
206
|
+
...(isOpen && isListBoxEmpty ? {
|
|
207
|
+
'aria-activedescendant': menuProps.id
|
|
208
|
+
} : {})
|
|
209
|
+
}); // recalculate the popup position after a possible trigger height change
|
|
210
|
+
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
if (dropdownRef.current) {
|
|
213
|
+
dropdownRef.current.scheduleUpdate();
|
|
86
214
|
}
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
buttonProps
|
|
90
|
-
} = useButton({ ...triggerProps,
|
|
91
|
-
elementType: 'div'
|
|
92
|
-
}, triggerRef);
|
|
93
|
-
const isDisabled = ariaProps.isDisabled;
|
|
94
|
-
const isOpen = state.isOpen;
|
|
215
|
+
}, [selectedItems]); // use it instead of ":has(:focus-visible), :focus-visible"
|
|
216
|
+
|
|
95
217
|
const {
|
|
96
218
|
isFocusVisible,
|
|
97
219
|
focusProps
|
|
@@ -102,14 +224,21 @@ function MultiselectInner(_ref) {
|
|
|
102
224
|
isFocusedByLabel,
|
|
103
225
|
labelClickProps,
|
|
104
226
|
triggerFocusProps: labelFocusForTriggerProps
|
|
105
|
-
} = useLabelFocus(
|
|
227
|
+
} = useLabelFocus();
|
|
106
228
|
const emptyListMessage = getEmptyMessage({
|
|
107
229
|
isLoading,
|
|
108
230
|
isNothingFound: false,
|
|
109
231
|
noOptionsMessage
|
|
110
232
|
});
|
|
233
|
+
const listBoxState = {
|
|
234
|
+
selectedMap,
|
|
235
|
+
selectionMode: 'multiple',
|
|
236
|
+
highlightedIndex,
|
|
237
|
+
getItemProps,
|
|
238
|
+
menuProps
|
|
239
|
+
};
|
|
111
240
|
return /*#__PURE__*/React.createElement("div", {
|
|
112
|
-
className: cn(className, styles.root, THEME_STYLES[theme], SIZE_STYLES[size], MODE_STYLES[mode], isDisabled ? styles.disabled : styles.enabled, Boolean(
|
|
241
|
+
className: cn(className, styles.root, THEME_STYLES[theme], SIZE_STYLES[size], MODE_STYLES[mode], isDisabled ? styles.disabled : styles.enabled, Boolean(error) && styles.error),
|
|
113
242
|
id: id,
|
|
114
243
|
style: style,
|
|
115
244
|
"data-test": "multiselect"
|
|
@@ -117,126 +246,72 @@ function MultiselectInner(_ref) {
|
|
|
117
246
|
theme: theme,
|
|
118
247
|
size: size,
|
|
119
248
|
disabled: isDisabled,
|
|
120
|
-
label:
|
|
121
|
-
labelProps: mergeProps(
|
|
249
|
+
label: label,
|
|
250
|
+
labelProps: mergeProps(getLabelProps(), labelClickProps),
|
|
122
251
|
boldLabel: boldLabel,
|
|
123
|
-
error:
|
|
252
|
+
error: error,
|
|
124
253
|
reserveErrorLine: reserveErrorLine,
|
|
125
254
|
errorMessageProps: errorMessageProps,
|
|
126
|
-
note:
|
|
255
|
+
note: note,
|
|
127
256
|
descriptionProps: descriptionProps
|
|
128
|
-
}, /*#__PURE__*/React.createElement(HiddenSelect, {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
"data-test": "multiselect__trigger"
|
|
136
|
-
}, /*#__PURE__*/React.createElement(MultiTrigger, {
|
|
137
|
-
state: state,
|
|
138
|
-
valueProps: valueProps,
|
|
139
|
-
isSingleLine: isSingleLine,
|
|
140
|
-
isDisabled: isDisabled,
|
|
141
|
-
placeholder: ariaProps.placeholder,
|
|
142
|
-
triggerRef: triggerRef
|
|
143
|
-
}), /*#__PURE__*/React.createElement(Icons, {
|
|
144
|
-
isLoading: isLoading,
|
|
145
|
-
canHaveClearIcon: isClearable && !isDisabled && hasValue,
|
|
146
|
-
onClear: () => {
|
|
147
|
-
var _triggerRef$current;
|
|
148
|
-
|
|
149
|
-
state.setValue([]);
|
|
150
|
-
(_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 || _triggerRef$current.focus();
|
|
151
|
-
},
|
|
152
|
-
triggerId: triggerProps.id
|
|
153
|
-
})), /*#__PURE__*/React.createElement(PopupContent, {
|
|
257
|
+
}, /*#__PURE__*/React.createElement(HiddenSelect, {
|
|
258
|
+
name: name,
|
|
259
|
+
value: selectedItems,
|
|
260
|
+
isMultiple: true,
|
|
261
|
+
options: flattenedOptions
|
|
262
|
+
}), /*#__PURE__*/React.createElement(Dropdown, {
|
|
263
|
+
mode: mode,
|
|
154
264
|
theme: theme,
|
|
155
|
-
|
|
156
|
-
triggerRef: triggerRef,
|
|
265
|
+
ref: dropdownRef,
|
|
157
266
|
placement: placement,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
findOptionsByKeys,
|
|
191
|
-
virtualOptions
|
|
192
|
-
} = useMultiOptionSerialization(options, value);
|
|
193
|
-
|
|
194
|
-
const handleSelectionChange = keys => {
|
|
195
|
-
const newValue = findOptionsByKeys(keys);
|
|
196
|
-
onChange === null || onChange === void 0 || onChange(newValue);
|
|
197
|
-
};
|
|
267
|
+
maxWidth: "trigger",
|
|
268
|
+
minWidth: "trigger",
|
|
269
|
+
isOpen: isOpen,
|
|
270
|
+
cancelCloseAnimation: true,
|
|
271
|
+
disableFocusLock: true,
|
|
272
|
+
trigger: _ref3 => {
|
|
273
|
+
let {
|
|
274
|
+
ref: triggerRefForDropdown
|
|
275
|
+
} = _ref3;
|
|
276
|
+
return /*#__PURE__*/React.createElement("div", { ...rest,
|
|
277
|
+
...mergeProps(fieldProps, // aria-invalid & aria-describedby, rest are overridden by triggerProps
|
|
278
|
+
triggerProps, focusProps, labelFocusForTriggerProps, {
|
|
279
|
+
ref: triggerRefForDropdown
|
|
280
|
+
}),
|
|
281
|
+
className: cn(styles.trigger, !isSingleLine && styles.canBeMultiline),
|
|
282
|
+
"data-open": isOpen,
|
|
283
|
+
"data-has-focus-visible": isFocusVisible,
|
|
284
|
+
"data-label-focused": isFocusedByLabel,
|
|
285
|
+
"data-test": "multiselect__trigger"
|
|
286
|
+
}, /*#__PURE__*/React.createElement(MultiTrigger, {
|
|
287
|
+
selectedItems: selectedItems,
|
|
288
|
+
valueProps: {},
|
|
289
|
+
isSingleLine: isSingleLine,
|
|
290
|
+
isDisabled: isDisabled,
|
|
291
|
+
placeholder: placeholder,
|
|
292
|
+
triggerRef: triggerRef,
|
|
293
|
+
removeSelectedItem: removeSelectedItem
|
|
294
|
+
}), /*#__PURE__*/React.createElement(Icons, {
|
|
295
|
+
isLoading: isLoading,
|
|
296
|
+
canHaveClearIcon: isClearable && !isDisabled && selectedItems.length > 0,
|
|
297
|
+
onClear: () => {
|
|
298
|
+
var _triggerRef$current;
|
|
198
299
|
|
|
199
|
-
|
|
300
|
+
reset();
|
|
301
|
+
(_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 || _triggerRef$current.focus({
|
|
302
|
+
focusVisible: false
|
|
303
|
+
});
|
|
304
|
+
},
|
|
305
|
+
triggerId: triggerProps.id
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
}, /*#__PURE__*/React.createElement(ListBox, {
|
|
309
|
+
state: listBoxState,
|
|
200
310
|
size: size,
|
|
201
|
-
mode: mode,
|
|
202
|
-
theme: theme,
|
|
203
|
-
value: selectedKeys,
|
|
204
|
-
onChange: handleSelectionChange,
|
|
205
|
-
errorMessage: error,
|
|
206
|
-
description: note,
|
|
207
|
-
placement: convertPlacement(placement),
|
|
208
|
-
isSingleLine: isSingleLine,
|
|
209
|
-
disabledKeys: virtualOptions.map(option => getOptionValue(option)),
|
|
210
|
-
boldLabel: boldLabel,
|
|
211
|
-
reserveErrorLine: reserveErrorLine,
|
|
212
311
|
maxVisibleItems: maxVisibleItems,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}, convertOptions(options, virtualOptions));
|
|
312
|
+
emptyListMessage: emptyListMessage,
|
|
313
|
+
items: listBoxItems
|
|
314
|
+
}))));
|
|
217
315
|
}
|
|
218
316
|
|
|
219
|
-
Multiselect.propTypes = {
|
|
220
|
-
className: PropTypes.string,
|
|
221
|
-
style: PropTypes.object,
|
|
222
|
-
options: PropTypes.arrayOf(PropTypes.oneOfType([optionType, optionsGroupType])),
|
|
223
|
-
value: PropTypes.arrayOf(optionType),
|
|
224
|
-
onChange: PropTypes.func,
|
|
225
|
-
size: PropTypes.oneOf(['m', 's', 'l']),
|
|
226
|
-
mode: PropTypes.oneOf(['classic', 'rock']),
|
|
227
|
-
theme: PropTypes.oneOf(['light', 'dark']),
|
|
228
|
-
placeholder: PropTypes.string,
|
|
229
|
-
isSingleLine: PropTypes.bool,
|
|
230
|
-
isClearable: PropTypes.bool,
|
|
231
|
-
isDisabled: PropTypes.bool,
|
|
232
|
-
isLoading: PropTypes.bool,
|
|
233
|
-
error: ErrorMessage.propTypes.children,
|
|
234
|
-
label: PropTypes.node,
|
|
235
|
-
note: PropTypes.node,
|
|
236
|
-
id: PropTypes.string,
|
|
237
|
-
noOptionsMessage: noOptionsMessageType,
|
|
238
|
-
placement: PropTypes.oneOf(['auto-start', 'auto', 'auto-end', 'top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start']),
|
|
239
|
-
name: PropTypes.string,
|
|
240
|
-
boldLabel: PropTypes.bool
|
|
241
|
-
};
|
|
242
317
|
export { Multiselect };
|