@sproutsocial/seeds-react-menu 1.2.2 → 1.2.3
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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +6 -0
- package/dist/esm/index.js +35 -29
- package/dist/esm/index.js.map +1 -1
- package/dist/index.js +64 -57
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Autocomplete/MultiAutocomplete.tsx +26 -18
- package/src/Autocomplete/SingleAutocomplete.tsx +18 -6
- package/src/MenuRoot/MenuRoot.tsx +0 -7
package/package.json
CHANGED
|
@@ -74,18 +74,20 @@ export const MultiAutocomplete = <
|
|
|
74
74
|
[selectedItemIds, showSelectedItemsInDropdown, getIsItemVisible]
|
|
75
75
|
);
|
|
76
76
|
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
77
|
+
const downshiftDefaults = useDownshiftDefaults({
|
|
78
|
+
isCombobox: true,
|
|
79
|
+
isMulti: true,
|
|
80
|
+
// handles the prop name mapping for multi select
|
|
81
|
+
multiSelectProps: {
|
|
82
|
+
getA11yMultiStatusMessage,
|
|
83
|
+
onMultiSelectStateChange,
|
|
84
|
+
multiSelectStateReducer,
|
|
85
|
+
...useComboboxProps,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const { setHiddenItemsMap, defaultDownshiftProps, hiddenItemsCount } =
|
|
90
|
+
downshiftDefaults;
|
|
89
91
|
|
|
90
92
|
// used to handle filtering of items
|
|
91
93
|
const { updateFilteredItems } = useItemFiltering({
|
|
@@ -118,9 +120,8 @@ export const MultiAutocomplete = <
|
|
|
118
120
|
/**
|
|
119
121
|
* Destructure Downshift props and call the core useCombobox with items and state handler
|
|
120
122
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
>({
|
|
123
|
+
|
|
124
|
+
const useComboboxReturnProps = useCombobox<(typeof allMenuItems)[number]>({
|
|
124
125
|
...defaultDownshiftProps.combobox,
|
|
125
126
|
items: allMenuItems,
|
|
126
127
|
itemToString,
|
|
@@ -160,24 +161,31 @@ export const MultiAutocomplete = <
|
|
|
160
161
|
...useComboboxProps,
|
|
161
162
|
});
|
|
162
163
|
|
|
164
|
+
const { isOpen, closeMenu, inputValue } = useComboboxReturnProps;
|
|
165
|
+
|
|
166
|
+
React.useEffect(() => {
|
|
167
|
+
if (!inputValue) return;
|
|
168
|
+
if (allMenuItems && hiddenItemsCount >= allMenuItems.length && isOpen) {
|
|
169
|
+
closeMenu?.();
|
|
170
|
+
}
|
|
171
|
+
}, [hiddenItemsCount, allMenuItems?.length, isOpen, inputValue]);
|
|
172
|
+
|
|
163
173
|
return (
|
|
164
174
|
<MenuRootComponent
|
|
165
175
|
{...{
|
|
166
176
|
isListbox: true,
|
|
167
177
|
items: allMenuItems,
|
|
168
178
|
itemToString,
|
|
169
|
-
isOpen,
|
|
170
179
|
initialSelectedItems,
|
|
171
180
|
onStateChange,
|
|
172
181
|
onSelectedItemsChange,
|
|
173
182
|
getA11yMultiStatusMessage,
|
|
174
183
|
onMultiSelectStateChange,
|
|
175
184
|
multiSelectStateReducer,
|
|
176
|
-
setHiddenItemsMap,
|
|
177
185
|
...useComboboxProps,
|
|
178
186
|
...useComboboxReturnProps,
|
|
179
187
|
...useMultipleSelectionReturnProps,
|
|
180
|
-
...
|
|
188
|
+
...downshiftDefaults,
|
|
181
189
|
}}
|
|
182
190
|
popoutProps={{
|
|
183
191
|
focusOnContent: false,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import { useCombobox } from "downshift";
|
|
2
3
|
import { useMenuChildren } from "../hooks/useMenuChildren";
|
|
3
4
|
import { itemToString as defaultItemToString } from "../utils/downshiftDefaults";
|
|
@@ -27,8 +28,12 @@ export const SingleAutocomplete = <
|
|
|
27
28
|
menuItems,
|
|
28
29
|
MenuItemComponent,
|
|
29
30
|
});
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
const downshiftDefaults = useDownshiftDefaults({ isCombobox: true });
|
|
33
|
+
|
|
34
|
+
const { setHiddenItemsMap, defaultDownshiftProps, hiddenItemsCount } =
|
|
35
|
+
downshiftDefaults;
|
|
36
|
+
|
|
32
37
|
const { updateFilteredItems } = useItemFiltering({
|
|
33
38
|
allMenuItems,
|
|
34
39
|
itemToString,
|
|
@@ -39,7 +44,7 @@ export const SingleAutocomplete = <
|
|
|
39
44
|
/**
|
|
40
45
|
* Destructure Downshift props and call the core useCombobox with items and state handler
|
|
41
46
|
*/
|
|
42
|
-
const
|
|
47
|
+
const useComboboxReturnProps = useCombobox({
|
|
43
48
|
...defaultDownshiftProps.combobox,
|
|
44
49
|
items: allMenuItems,
|
|
45
50
|
itemToString,
|
|
@@ -51,17 +56,24 @@ export const SingleAutocomplete = <
|
|
|
51
56
|
...useComboboxProps,
|
|
52
57
|
});
|
|
53
58
|
|
|
59
|
+
const { isOpen, closeMenu, inputValue } = useComboboxReturnProps;
|
|
60
|
+
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
if (!inputValue) return;
|
|
63
|
+
if (allMenuItems && hiddenItemsCount >= allMenuItems.length && isOpen) {
|
|
64
|
+
closeMenu?.();
|
|
65
|
+
}
|
|
66
|
+
}, [hiddenItemsCount, allMenuItems?.length, isOpen, inputValue]);
|
|
67
|
+
|
|
54
68
|
return (
|
|
55
69
|
<MenuRootComponent
|
|
56
70
|
{...{
|
|
57
71
|
isListbox: true,
|
|
58
72
|
items: allMenuItems,
|
|
59
73
|
itemToString,
|
|
60
|
-
isOpen,
|
|
61
|
-
setHiddenItemsMap,
|
|
62
74
|
...useComboboxProps,
|
|
63
75
|
...useComboboxReturnProps,
|
|
64
|
-
...
|
|
76
|
+
...downshiftDefaults,
|
|
65
77
|
}}
|
|
66
78
|
popoutProps={{
|
|
67
79
|
focusOnContent: false,
|
|
@@ -150,13 +150,6 @@ export const MenuRoot = ({
|
|
|
150
150
|
}
|
|
151
151
|
}, [width, toggleElementRef.current?.offsetWidth]);
|
|
152
152
|
|
|
153
|
-
useEffect(() => {
|
|
154
|
-
if (!inputValue) return;
|
|
155
|
-
if (items && hiddenItemsCount >= items.length && isOpen) {
|
|
156
|
-
closeMenu?.();
|
|
157
|
-
}
|
|
158
|
-
}, [hiddenItemsCount, items?.length, isOpen, inputValue]);
|
|
159
|
-
|
|
160
153
|
const menuContext = useMenu(contextProps);
|
|
161
154
|
|
|
162
155
|
// Hack to suppress error: "downshift: You forgot to call the getMenuProps getter function on your component / element."
|