@react-stately/combobox 3.0.0-beta.1 → 3.0.0-nightly-641446f65-240905

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/dist/module.js CHANGED
@@ -1,308 +1,17 @@
1
- import { useMenuTriggerState } from "@react-stately/menu";
2
- import { useEffect, useMemo, useRef, useState } from "react";
3
- import { useControlledState } from "@react-stately/utils";
4
- import { ListCollection, useSingleSelectListState } from "@react-stately/list";
5
- import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
6
-
7
- /**
8
- * Provides state management for a combo box component. Handles building a collection
9
- * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,
10
- * focus state, and other properties of the combo box.
11
- */
12
- export function useComboBoxState(props) {
13
- var _props$defaultInputVa, _props$items, _ref, _props$selectedKey, _collection$getItem$t2, _collection$getItem2;
14
-
15
- let {
16
- defaultFilter,
17
- menuTrigger = 'input',
18
- allowsEmptyCollection = false,
19
- allowsCustomValue,
20
- shouldCloseOnBlur = true
21
- } = props;
22
- let [showAllItems, setShowAllItems] = useState(false);
23
- let [isFocused, setFocusedState] = useState(false);
24
- let [inputValue, setInputValue] = useControlledState(props.inputValue, (_props$defaultInputVa = props.defaultInputValue) != null ? _props$defaultInputVa : '', props.onInputChange);
25
-
26
- let onSelectionChange = key => {
27
- if (props.onSelectionChange) {
28
- props.onSelectionChange(key);
29
- } // If open state or selectedKey is uncontrolled and key is the same, reset the inputValue and close the menu
30
- // (scenario: user clicks on already selected option)
31
-
32
-
33
- if (props.isOpen === undefined || props.selectedKey === undefined) {
34
- if (key === selectedKey) {
35
- resetInputValue();
36
- triggerState.close();
37
- }
38
- }
39
- };
40
-
41
- let {
42
- collection,
43
- selectionManager,
44
- selectedKey,
45
- setSelectedKey,
46
- selectedItem,
47
- disabledKeys
48
- } = useSingleSelectListState(_babelRuntimeHelpersEsmExtends({}, props, {
49
- onSelectionChange,
50
- items: (_props$items = props.items) != null ? _props$items : props.defaultItems
51
- })); // Preserve original collection so we can show all items on demand
52
-
53
- let originalCollection = collection;
54
- let filteredCollection = useMemo(() => // No default filter if items are controlled.
55
- props.items != null || !defaultFilter ? collection : $b1b6afed698df4428b7ed319af4b90$var$filterCollection(collection, inputValue, defaultFilter), [collection, inputValue, defaultFilter, props.items]); // Track what action is attempting to open the menu
56
-
57
- let menuOpenTrigger = useRef('focus');
58
-
59
- let onOpenChange = open => {
60
- if (props.onOpenChange) {
61
- props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);
62
- }
63
- };
64
-
65
- let triggerState = useMenuTriggerState(_babelRuntimeHelpersEsmExtends({}, props, {
66
- onOpenChange
67
- }));
68
-
69
- let open = (focusStrategy, trigger) => {
70
- let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus'; // Prevent open operations from triggering if there is nothing to display
71
- // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.
72
- // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)
73
-
74
- if (allowsEmptyCollection || filteredCollection.size > 0 || displayAllItems && originalCollection.size > 0 || props.items) {
75
- if (displayAllItems && !triggerState.isOpen && props.items === undefined) {
76
- // Show all items if menu is manually opened. Only care about this if items are undefined
77
- setShowAllItems(true);
78
- }
79
-
80
- menuOpenTrigger.current = trigger;
81
- triggerState.open(focusStrategy);
82
- }
83
- };
84
-
85
- let toggle = (focusStrategy, trigger) => {
86
- let displayAllItems = trigger === 'manual' || trigger === 'focus' && menuTrigger === 'focus'; // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange
87
-
88
- if (!(allowsEmptyCollection || filteredCollection.size > 0 || displayAllItems && originalCollection.size > 0 || props.items) && !triggerState.isOpen) {
89
- return;
90
- }
91
-
92
- if (displayAllItems && !triggerState.isOpen && props.items === undefined) {
93
- // Show all items if menu is toggled open. Only care about this if items are undefined
94
- setShowAllItems(true);
95
- } // Only update the menuOpenTrigger if menu is currently closed
96
-
97
-
98
- if (!triggerState.isOpen) {
99
- menuOpenTrigger.current = trigger;
100
- }
101
-
102
- triggerState.toggle(focusStrategy);
103
- };
104
-
105
- let lastValue = useRef(inputValue);
106
-
107
- let resetInputValue = () => {
108
- var _collection$getItem$t, _collection$getItem;
109
-
110
- let itemText = (_collection$getItem$t = (_collection$getItem = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem.textValue) != null ? _collection$getItem$t : '';
111
- lastValue.current = itemText;
112
- setInputValue(itemText);
113
- };
114
-
115
- let isInitialRender = useRef(true);
116
- let lastSelectedKey = useRef((_ref = (_props$selectedKey = props.selectedKey) != null ? _props$selectedKey : props.defaultSelectedKey) != null ? _ref : null);
117
- let lastSelectedKeyText = useRef((_collection$getItem$t2 = (_collection$getItem2 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem2.textValue) != null ? _collection$getItem$t2 : ''); // intentional omit dependency array, want this to happen on every render
118
- // eslint-disable-next-line react-hooks/exhaustive-deps
119
-
120
- useEffect(() => {
121
- var _collection$getItem$t3, _collection$getItem3;
122
-
123
- // If open state or inputValue is uncontrolled, open and close automatically when the input value changes,
124
- // the input is if focused, and there are items in the collection or allowEmptyCollection is true.
125
- if (isFocused && (filteredCollection.size > 0 || allowsEmptyCollection) && !triggerState.isOpen && inputValue !== lastValue.current && menuTrigger !== 'manual' && (props.isOpen === undefined || props.inputValue === undefined)) {
126
- open(null, 'input');
127
- } // Close the menu if the collection is empty and either open state or items are uncontrolled.
128
- // Don't close menu if filtered collection size is 0 but we are currently showing all items via button press (only applies to uncontrolled items)
129
-
130
-
131
- if (!showAllItems && !allowsEmptyCollection && triggerState.isOpen && filteredCollection.size === 0 && (props.isOpen === undefined || props.items === undefined)) {
132
- triggerState.close();
133
- } // Close when an item is selected, if open state or selectedKey is uncontrolled.
134
-
135
-
136
- if (selectedKey != null && selectedKey !== lastSelectedKey.current && (props.isOpen === undefined || props.selectedKey === undefined)) {
137
- triggerState.close();
138
- } // Clear focused key when input value changes and display filtered collection again.
139
-
140
-
141
- if (inputValue !== lastValue.current) {
142
- selectionManager.setFocusedKey(null);
143
- setShowAllItems(false); // Set selectedKey to null when the user clears the input.
144
- // If controlled, this is the application developer's responsibility.
145
-
146
- if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {
147
- setSelectedKey(null);
148
- }
149
- } // If it is the intial render and inputValue isn't controlled nor has an intial value, set input to match current selected key if any
150
-
151
-
152
- if (isInitialRender.current && props.inputValue === undefined && props.defaultInputValue === undefined) {
153
- resetInputValue();
154
- } // If the selectedKey changed, update the input value.
155
- // Do nothing if both inputValue and selectedKey are controlled.
156
- // In this case, it's the user's responsibility to update inputValue in onSelectionChange.
157
-
158
-
159
- if (selectedKey !== lastSelectedKey.current && (props.inputValue === undefined || props.selectedKey === undefined)) {
160
- resetInputValue();
161
- } else {
162
- lastValue.current = inputValue;
163
- } // Update the inputValue if the selected item's text changes from its last tracked value.
164
- // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.
165
- // Only reset if the user isn't currently within the field so we don't erroneously modify user input.
166
- // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.
167
-
168
-
169
- let selectedItemText = (_collection$getItem$t3 = (_collection$getItem3 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem3.textValue) != null ? _collection$getItem$t3 : '';
170
-
171
- if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {
172
- if (lastSelectedKeyText.current !== selectedItemText) {
173
- lastValue.current = selectedItemText;
174
- setInputValue(selectedItemText);
175
- }
176
- }
177
-
178
- isInitialRender.current = false;
179
- lastSelectedKey.current = selectedKey;
180
- lastSelectedKeyText.current = selectedItemText;
181
- });
182
- useEffect(() => {
183
- // Reset focused key when the menu closes
184
- if (!triggerState.isOpen) {
185
- selectionManager.setFocusedKey(null);
186
- }
187
- }, [triggerState.isOpen, selectionManager]);
188
-
189
- let commitCustomValue = () => {
190
- let shouldClose = false;
191
- lastSelectedKey.current = null;
192
- setSelectedKey(null); // If previous key was already null, need to manually call onSelectionChange since it won't be triggered by a setSelectedKey call
193
- // This allows the application to control whether or not to close the menu on custom value commit
194
-
195
- if (selectedKey === null && props.onSelectionChange) {
196
- props.onSelectionChange(null);
197
- } // Should close menu ourselves if component open state or selected key is uncontrolled and therefore won't be closed by a user defined event handler
198
-
199
-
200
- shouldClose = props.isOpen == null || props.selectedKey === undefined; // Close if no other event will be fired. Otherwise, allow the
201
- // application to control this based on that event.
202
-
203
- if (shouldClose) {
204
- triggerState.close();
205
- }
206
- };
207
-
208
- let commitSelection = () => {
209
- // If multiple things are controlled, call onSelectionChange
210
- // Note that users who control open state and input value MUST also have a onSelectionChange handler to properly close the menu and reset input value
211
- if (props.selectedKey !== undefined && props.inputValue !== undefined || props.inputValue !== undefined && props.isOpen !== undefined || props.selectedKey !== undefined && props.isOpen !== undefined) {
212
- props.onSelectionChange(selectedKey); // If multiple things are controlled but inputValue isn't, reset the input value for the user
213
-
214
- if (props.inputValue === undefined) {
215
- resetInputValue();
216
- } // If multiple things are controlled but isOpen isn't, close the menu for the user
217
-
218
-
219
- if (props.isOpen === undefined) {
220
- var _collection$getItem$t4, _collection$getItem4;
221
-
222
- // Stop menu from reopening from useEffect
223
- let itemText = (_collection$getItem$t4 = (_collection$getItem4 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem4.textValue) != null ? _collection$getItem$t4 : '';
224
- lastValue.current = itemText;
225
- triggerState.close();
226
- }
227
- } else {
228
- // If only a single aspect of combobox is controlled, reset input value and close menu for the user
229
- resetInputValue();
230
- triggerState.close();
231
- }
232
- };
233
-
234
- let commit = () => {
235
- if (triggerState.isOpen && selectionManager.focusedKey != null) {
236
- // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise
237
- // fire onSelectionChange to allow the application to control the closing.
238
- if (selectedKey === selectionManager.focusedKey) {
239
- commitSelection();
240
- } else {
241
- setSelectedKey(selectionManager.focusedKey);
242
- }
243
- } else if (allowsCustomValue) {
244
- commitCustomValue();
245
- }
246
- };
247
-
248
- let setFocused = isFocused => {
249
- if (isFocused) {
250
- if (menuTrigger === 'focus') {
251
- open(null, 'focus');
252
- }
253
- } else if (shouldCloseOnBlur) {
254
- var _collection$getItem$t5, _collection$getItem5;
255
-
256
- let itemText = (_collection$getItem$t5 = (_collection$getItem5 = collection.getItem(selectedKey)) == null ? void 0 : _collection$getItem5.textValue) != null ? _collection$getItem$t5 : '';
257
-
258
- if (allowsCustomValue && inputValue !== itemText) {
259
- commitCustomValue();
260
- } else {
261
- commitSelection();
262
- }
263
- }
264
-
265
- setFocusedState(isFocused);
266
- };
267
-
268
- return _babelRuntimeHelpersEsmExtends({}, triggerState, {
269
- toggle,
270
- open,
271
- selectionManager,
272
- selectedKey,
273
- setSelectedKey,
274
- disabledKeys,
275
- isFocused,
276
- setFocused,
277
- selectedItem,
278
- collection: showAllItems ? originalCollection : filteredCollection,
279
- inputValue,
280
- setInputValue,
281
- commit
282
- });
283
- }
284
-
285
- function $b1b6afed698df4428b7ed319af4b90$var$filterCollection(collection, inputValue, filter) {
286
- return new ListCollection($b1b6afed698df4428b7ed319af4b90$var$filterNodes(collection, inputValue, filter));
287
- }
288
-
289
- function $b1b6afed698df4428b7ed319af4b90$var$filterNodes(nodes, inputValue, filter) {
290
- let filteredNode = [];
291
-
292
- for (let node of nodes) {
293
- if (node.type === 'section' && node.hasChildNodes) {
294
- let filtered = $b1b6afed698df4428b7ed319af4b90$var$filterNodes(node.childNodes, inputValue, filter);
295
-
296
- if ([...filtered].length > 0) {
297
- filteredNode.push(_babelRuntimeHelpersEsmExtends({}, node, {
298
- childNodes: filtered
299
- }));
300
- }
301
- } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {
302
- filteredNode.push(_babelRuntimeHelpersEsmExtends({}, node));
303
- }
304
- }
305
-
306
- return filteredNode;
307
- }
1
+ import {useComboBoxState as $a9e7382a7d111cb5$export$b453a3bfd4a5fa9e} from "./useComboBoxState.module.js";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+
16
+ export {$a9e7382a7d111cb5$export$b453a3bfd4a5fa9e as useComboBoxState};
308
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;AA2CA;;;;;OAKO,SAASA,gBAAT,CAA4CC,KAA5C,EAA4F;AAAA;;AACjG,MAAI;AACFC,IAAAA,aADE;AAEFC,IAAAA,WAAW,GAAG,OAFZ;AAGFC,IAAAA,qBAAqB,GAAG,KAHtB;AAIFC,IAAAA,iBAJE;AAKFC,IAAAA,iBAAiB,GAAG;AALlB,MAMAL,KANJ;AAQA,MAAI,CAACM,YAAD,EAAeC,eAAf,IAAkCC,QAAQ,CAAC,KAAD,CAA9C;AACA,MAAI,CAACC,SAAD,EAAYC,eAAZ,IAA+BF,QAAQ,CAAC,KAAD,CAA3C;AACA,MAAI,CAACG,UAAD,EAAaC,aAAb,IAA8BC,kBAAkB,CAClDb,KAAK,CAACW,UAD4C,2BAElDX,KAAK,CAACc,iBAF4C,oCAEvB,EAFuB,EAGlDd,KAAK,CAACe,aAH4C,CAApD;;AAMA,MAAIC,iBAAiB,GAAIC,GAAD,IAAS;AAC/B,QAAIjB,KAAK,CAACgB,iBAAV,EAA6B;AAC3BhB,MAAAA,KAAK,CAACgB,iBAAN,CAAwBC,GAAxB;AACD,KAH8B,CAK/B;AACA;;;AACA,QAAIjB,KAAK,CAACkB,MAAN,KAAiBC,SAA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AAIC,QAAQ,GAAGN,+CAAW,CAACG,IAAI,CAACI,UAAN,EAAkB9D,UAAlB,EAA8BqD,MAA9B,CAA1B;;AACA,UAAI,CAAC,GAAGQ,QAAJ,EAAcE,MAAd,GAAuB,CAA3B,EAA8B;AAC5BN,QAAAA,YAAY,CAACO,IAAb,oCAAsBN,IAAtB;AAA4BI,UAAAA,UAAU,EAAED;AAAxC;AACD;AACF,KALD,MAKO,IAAIH,IAAI,CAACC,IAAL,KAAc,SAAd,IAA2BN,MAAM,CAACK,IAAI,CAACnB,SAAN,EAAiBvC,UAAjB,CAArC,EAAmE;AACxEyD,MAAAA,YAAY,CAACO,IAAb,oCAAsBN,IAAtB;AACD;AACF;;AACD,SAAOD,YAAP;AACD","sources":["./packages/@react-stately/combobox/src/useComboBoxState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, FocusStrategy, Node} from '@react-types/shared';\nimport {ComboBoxProps, MenuTriggerAction} from '@react-types/combobox';\nimport {ListCollection, useSingleSelectListState} from '@react-stately/list';\nimport {SelectState} from '@react-stately/select';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\nimport {useMenuTriggerState} from '@react-stately/menu';\n\nexport interface ComboBoxState<T> extends SelectState<T> {\n /** The current value of the combo box input. */\n inputValue: string,\n /** Sets the value of the combo box input. */\n setInputValue(value: string): void,\n /** Selects the currently focused item and updates the input value. */\n commit(): void,\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void,\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void\n}\n\ntype FilterFn = (textValue: string, inputValue: string) => boolean;\ninterface ComboBoxStateProps<T> extends ComboBoxProps<T> {\n /** The filter function used to determine if a option should be included in the combo box list. */\n defaultFilter?: FilterFn,\n /** Whether the combo box allows the menu to be open when the collection is empty. */\n allowsEmptyCollection?: boolean,\n /** Whether the combo box menu should close on blur. */\n shouldCloseOnBlur?: boolean\n}\n\n/**\n * Provides state management for a combo box component. Handles building a collection\n * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,\n * focus state, and other properties of the combo box.\n */\nexport function useComboBoxState<T extends object>(props: ComboBoxStateProps<T>): ComboBoxState<T> {\n let {\n defaultFilter,\n menuTrigger = 'input',\n allowsEmptyCollection = false,\n allowsCustomValue,\n shouldCloseOnBlur = true\n } = props;\n\n let [showAllItems, setShowAllItems] = useState(false);\n let [isFocused, setFocusedState] = useState(false);\n let [inputValue, setInputValue] = useControlledState(\n props.inputValue,\n props.defaultInputValue ?? '',\n props.onInputChange\n );\n\n let onSelectionChange = (key) => {\n if (props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n // If open state or selectedKey is uncontrolled and key is the same, reset the inputValue and close the menu\n // (scenario: user clicks on already selected option)\n if (props.isOpen === undefined || props.selectedKey === undefined) {\n if (key === selectedKey) {\n resetInputValue();\n triggerState.close();\n }\n }\n };\n\n let {collection, selectionManager, selectedKey, setSelectedKey, selectedItem, disabledKeys} = useSingleSelectListState({\n ...props,\n onSelectionChange,\n items: props.items ?? props.defaultItems\n });\n\n // Preserve original collection so we can show all items on demand\n let originalCollection = collection;\n let filteredCollection = useMemo(() => (\n // No default filter if items are controlled.\n props.items != null || !defaultFilter\n ? collection\n : filterCollection(collection, inputValue, defaultFilter)\n ), [collection, inputValue, defaultFilter, props.items]);\n\n // Track what action is attempting to open the menu\n let menuOpenTrigger = useRef('focus' as MenuTriggerAction);\n let onOpenChange = (open: boolean) => {\n if (props.onOpenChange) {\n props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);\n }\n };\n\n let triggerState = useMenuTriggerState({...props, onOpenChange});\n let open = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // Prevent open operations from triggering if there is nothing to display\n // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.\n // This is to prevent comboboxes with empty defaultItems from opening but allow controlled items comboboxes to open even if the inital list is empty (assumption is user will provide swap the empty list with a base list via onOpenChange returning `menuTrigger` manual)\n if (allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) {\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is manually opened. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n menuOpenTrigger.current = trigger;\n triggerState.open(focusStrategy);\n }\n };\n\n let toggle = (focusStrategy?: FocusStrategy, trigger?: MenuTriggerAction) => {\n let displayAllItems = (trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus'));\n // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange\n if (!(allowsEmptyCollection || filteredCollection.size > 0 || (displayAllItems && originalCollection.size > 0) || props.items) && !triggerState.isOpen) {\n return;\n }\n\n if (displayAllItems && !triggerState.isOpen && props.items === undefined) {\n // Show all items if menu is toggled open. Only care about this if items are undefined\n setShowAllItems(true);\n }\n\n // Only update the menuOpenTrigger if menu is currently closed\n if (!triggerState.isOpen) {\n menuOpenTrigger.current = trigger;\n }\n\n triggerState.toggle(focusStrategy);\n };\n\n let lastValue = useRef(inputValue);\n let resetInputValue = () => {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n setInputValue(itemText);\n };\n\n let isInitialRender = useRef(true);\n let lastSelectedKey = useRef(props.selectedKey ?? props.defaultSelectedKey ?? null);\n let lastSelectedKeyText = useRef(collection.getItem(selectedKey)?.textValue ?? '');\n // intentional omit dependency array, want this to happen on every render\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(() => {\n // If open state or inputValue is uncontrolled, open and close automatically when the input value changes,\n // the input is if focused, and there are items in the collection or allowEmptyCollection is true.\n if (\n isFocused &&\n (filteredCollection.size > 0 || allowsEmptyCollection) &&\n !triggerState.isOpen &&\n inputValue !== lastValue.current &&\n menuTrigger !== 'manual' &&\n (props.isOpen === undefined || props.inputValue === undefined)\n ) {\n open(null, 'input');\n }\n\n // Close the menu if the collection is empty and either open state or items are uncontrolled.\n // Don't close menu if filtered collection size is 0 but we are currently showing all items via button press (only applies to uncontrolled items)\n if (\n !showAllItems &&\n !allowsEmptyCollection &&\n triggerState.isOpen &&\n filteredCollection.size === 0 &&\n (props.isOpen === undefined || props.items === undefined)\n ) {\n triggerState.close();\n }\n\n // Close when an item is selected, if open state or selectedKey is uncontrolled.\n if (\n selectedKey != null &&\n selectedKey !== lastSelectedKey.current &&\n (props.isOpen === undefined || props.selectedKey === undefined)\n ) {\n triggerState.close();\n }\n\n // Clear focused key when input value changes and display filtered collection again.\n if (inputValue !== lastValue.current) {\n selectionManager.setFocusedKey(null);\n setShowAllItems(false);\n\n // Set selectedKey to null when the user clears the input.\n // If controlled, this is the application developer's responsibility.\n if (inputValue === '' && (props.inputValue === undefined || props.selectedKey === undefined)) {\n setSelectedKey(null);\n }\n }\n\n // If it is the intial render and inputValue isn't controlled nor has an intial value, set input to match current selected key if any\n if (isInitialRender.current && (props.inputValue === undefined && props.defaultInputValue === undefined)) {\n resetInputValue();\n }\n\n // If the selectedKey changed, update the input value.\n // Do nothing if both inputValue and selectedKey are controlled.\n // In this case, it's the user's responsibility to update inputValue in onSelectionChange.\n if (\n selectedKey !== lastSelectedKey.current &&\n (props.inputValue === undefined || props.selectedKey === undefined)\n ) {\n resetInputValue();\n } else {\n lastValue.current = inputValue;\n }\n\n // Update the inputValue if the selected item's text changes from its last tracked value.\n // This is to handle cases where a selectedKey is specified but the items aren't available (async loading) or the selected item's text value updates.\n // Only reset if the user isn't currently within the field so we don't erroneously modify user input.\n // If inputValue is controlled, it is the user's responsibility to update the inputValue when items change.\n let selectedItemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (!isFocused && selectedKey != null && props.inputValue === undefined && selectedKey === lastSelectedKey.current) {\n if (lastSelectedKeyText.current !== selectedItemText) {\n lastValue.current = selectedItemText;\n setInputValue(selectedItemText);\n }\n }\n\n isInitialRender.current = false;\n lastSelectedKey.current = selectedKey;\n lastSelectedKeyText.current = selectedItemText;\n });\n\n useEffect(() => {\n // Reset focused key when the menu closes\n if (!triggerState.isOpen) {\n selectionManager.setFocusedKey(null);\n }\n }, [triggerState.isOpen, selectionManager]);\n\n let commitCustomValue = () => {\n let shouldClose = false;\n lastSelectedKey.current = null;\n setSelectedKey(null);\n\n // If previous key was already null, need to manually call onSelectionChange since it won't be triggered by a setSelectedKey call\n // This allows the application to control whether or not to close the menu on custom value commit\n if (selectedKey === null && props.onSelectionChange) {\n props.onSelectionChange(null);\n }\n\n // Should close menu ourselves if component open state or selected key is uncontrolled and therefore won't be closed by a user defined event handler\n shouldClose = props.isOpen == null || props.selectedKey === undefined;\n\n // Close if no other event will be fired. Otherwise, allow the\n // application to control this based on that event.\n if (shouldClose) {\n triggerState.close();\n }\n };\n\n let commitSelection = () => {\n // If multiple things are controlled, call onSelectionChange\n // Note that users who control open state and input value MUST also have a onSelectionChange handler to properly close the menu and reset input value\n if (\n (props.selectedKey !== undefined && props.inputValue !== undefined) ||\n (props.inputValue !== undefined && props.isOpen !== undefined) ||\n (props.selectedKey !== undefined && props.isOpen !== undefined)\n ) {\n props.onSelectionChange(selectedKey);\n\n // If multiple things are controlled but inputValue isn't, reset the input value for the user\n if (props.inputValue === undefined) {\n resetInputValue();\n }\n\n // If multiple things are controlled but isOpen isn't, close the menu for the user\n if (props.isOpen === undefined) {\n // Stop menu from reopening from useEffect\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n lastValue.current = itemText;\n triggerState.close();\n }\n } else {\n // If only a single aspect of combobox is controlled, reset input value and close menu for the user\n resetInputValue();\n triggerState.close();\n }\n };\n\n let commit = () => {\n if (triggerState.isOpen && selectionManager.focusedKey != null) {\n // Reset inputValue and close menu here if the selected key is already the focused key. Otherwise\n // fire onSelectionChange to allow the application to control the closing.\n if (selectedKey === selectionManager.focusedKey) {\n commitSelection();\n } else {\n setSelectedKey(selectionManager.focusedKey);\n }\n } else if (allowsCustomValue) {\n commitCustomValue();\n }\n };\n\n let setFocused = (isFocused: boolean) => {\n if (isFocused) {\n if (menuTrigger === 'focus') {\n open(null, 'focus');\n }\n } else if (shouldCloseOnBlur) {\n let itemText = collection.getItem(selectedKey)?.textValue ?? '';\n if (allowsCustomValue && inputValue !== itemText) {\n commitCustomValue();\n } else {\n commitSelection();\n }\n }\n\n setFocusedState(isFocused);\n };\n\n return {\n ...triggerState,\n toggle,\n open,\n selectionManager,\n selectedKey,\n setSelectedKey,\n disabledKeys,\n isFocused,\n setFocused,\n selectedItem,\n collection: showAllItems ? originalCollection : filteredCollection,\n inputValue,\n setInputValue,\n commit\n };\n}\n\nfunction filterCollection<T extends object>(collection: Collection<Node<T>>, inputValue: string, filter: FilterFn): Collection<Node<T>> {\n return new ListCollection(filterNodes(collection, inputValue, filter));\n}\n\nfunction filterNodes<T>(nodes: Iterable<Node<T>>, inputValue: string, filter: FilterFn): Iterable<Node<T>> {\n let filteredNode = [];\n for (let node of nodes) {\n if (node.type === 'section' && node.hasChildNodes) {\n let filtered = filterNodes(node.childNodes, inputValue, filter);\n if ([...filtered].length > 0) {\n filteredNode.push({...node, childNodes: filtered});\n }\n } else if (node.type !== 'section' && filter(node.textValue, inputValue)) {\n filteredNode.push({...node});\n }\n }\n return filteredNode;\n}\n"],"names":["useComboBoxState","props","defaultFilter","menuTrigger","allowsEmptyCollection","allowsCustomValue","shouldCloseOnBlur","showAllItems","setShowAllItems","useState","isFocused","setFocusedState","inputValue","setInputValue","useControlledState","defaultInputValue","onInputChange","onSelectionChange","key","isOpen","undefined","selectedKey","resetInputValue","triggerState","close","collection","selectionManager","setSelectedKey","selectedItem","disabledKeys","useSingleSelectListState","items","defaultItems","originalCollection","filteredCollection","useMemo","filterCollection","menuOpenTrigger","useRef","onOpenChange","open","current","useMenuTriggerState","focusStrategy","trigger","displayAllItems","size","toggle","lastValue","itemText","getItem","textValue","isInitialRender","lastSelectedKey","defaultSelectedKey","lastSelectedKeyText","useEffect","setFocusedKey","selectedItemText","commitCustomValue","shouldClose","commitSelection","commit","focusedKey","setFocused","filter","ListCollection","filterNodes","nodes","filteredNode","node","type","hasChildNodes","filtered","childNodes","length","push"],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/combobox/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useComboBoxState} from './useComboBoxState';\n\nexport type {ComboBoxStateOptions, ComboBoxState} from './useComboBoxState';\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,20 +1,25 @@
1
- import { FocusStrategy } from "@react-types/shared";
1
+ import { CollectionStateBase, FocusStrategy } from "@react-types/shared";
2
2
  import { ComboBoxProps, MenuTriggerAction } from "@react-types/combobox";
3
+ import { FormValidationState } from "@react-stately/form";
3
4
  import { SelectState } from "@react-stately/select";
4
- export interface ComboBoxState<T> extends SelectState<T> {
5
+ export interface ComboBoxState<T> extends SelectState<T>, FormValidationState {
5
6
  /** The current value of the combo box input. */
6
7
  inputValue: string;
7
8
  /** Sets the value of the combo box input. */
8
9
  setInputValue(value: string): void;
9
10
  /** Selects the currently focused item and updates the input value. */
10
11
  commit(): void;
12
+ /** Controls which item will be auto focused when the menu opens. */
13
+ readonly focusStrategy: FocusStrategy | null;
11
14
  /** Opens the menu. */
12
15
  open(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void;
13
16
  /** Toggles the menu. */
14
17
  toggle(focusStrategy?: FocusStrategy | null, trigger?: MenuTriggerAction): void;
18
+ /** Resets the input value to the previously selected item's text if any and closes the menu. */
19
+ revert(): void;
15
20
  }
16
21
  type FilterFn = (textValue: string, inputValue: string) => boolean;
17
- interface ComboBoxStateProps<T> extends ComboBoxProps<T> {
22
+ export interface ComboBoxStateOptions<T> extends Omit<ComboBoxProps<T>, 'children'>, CollectionStateBase<T> {
18
23
  /** The filter function used to determine if a option should be included in the combo box list. */
19
24
  defaultFilter?: FilterFn;
20
25
  /** Whether the combo box allows the menu to be open when the collection is empty. */
@@ -27,6 +32,6 @@ interface ComboBoxStateProps<T> extends ComboBoxProps<T> {
27
32
  * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value,
28
33
  * focus state, and other properties of the combo box.
29
34
  */
30
- export function useComboBoxState<T extends object>(props: ComboBoxStateProps<T>): ComboBoxState<T>;
35
+ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T>): ComboBoxState<T>;
31
36
 
32
37
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":"A;A;A;AAoBA,+BAA+B,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC;IACtD,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,sEAAsE;IACtE,MAAM,IAAI,IAAI,CAAC;IACf,sBAAsB;IACtB,IAAI,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC9E,wBAAwB;IACxB,MAAM,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAChF;AAED,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;AACnE,6BAA6B,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC;IACtD,kGAAkG;IAClG,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,qFAAqF;IACrF,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,uDAAuD;IACvD,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B;AAED;A;A;A;GAIG;AACH,iCAAiC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAiSjG","sources":["./packages/@react-stately/combobox/src/packages/@react-stately/combobox/src/useComboBoxState.ts","./packages/@react-stately/combobox/src/packages/@react-stately/combobox/src/index.ts"],"sourcesContent":[null,null],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;;AAsBA,+BAA+B,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,EAAE,mBAAmB;IAC3E,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,sEAAsE;IACtE,MAAM,IAAI,IAAI,CAAC;IACf,oEAAoE;IACpE,QAAQ,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAC7C,sBAAsB;IACtB,IAAI,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC9E,wBAAwB;IACxB,MAAM,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAChF,iGAAiG;IACjG,MAAM,IAAI,IAAI,CAAA;CACf;AAED,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;AAEnE,sCAAsC,CAAC,CAAE,SAAQ,IAAI,CAAC,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,oBAAoB,CAAC,CAAC;IACzG,kGAAkG;IAClG,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,qFAAqF;IACrF,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,uDAAuD;IACvD,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B;AAED;;;;GAIG;AACH,iCAAiC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CA4UnG","sources":["packages/@react-stately/combobox/src/packages/@react-stately/combobox/src/useComboBoxState.ts","packages/@react-stately/combobox/src/packages/@react-stately/combobox/src/index.ts","packages/@react-stately/combobox/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useComboBoxState} from './useComboBoxState';\n\nexport type {ComboBoxStateOptions, ComboBoxState} from './useComboBoxState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}