MCPcopy Create free account
hub / github.com/adobe/react-spectrum / toggle

Function toggle

packages/react-stately/src/combobox/useComboBoxState.ts:349–375  ·  view source on GitHub ↗
(focusStrategy: FocusStrategy | null = null, trigger?: MenuTriggerAction)

Source from the content-addressed store, hash-verified

347 };
348
349 let toggle = (focusStrategy: FocusStrategy | null = null, trigger?: MenuTriggerAction) => {
350 let displayAllItems = trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus');
351 // If the menu is closed and there is nothing to display, early return so toggle isn't called to prevent extraneous onOpenChange
352 if (
353 !(
354 allowsEmptyCollection ||
355 filteredCollection.size > 0 ||
356 (displayAllItems && originalCollection.size > 0) ||
357 props.items
358 ) &&
359 !triggerState.isOpen
360 ) {
361 return;
362 }
363
364 if (displayAllItems && !triggerState.isOpen && props.items === undefined) {
365 // Show all items if menu is toggled open. Only care about this if items are undefined
366 setShowAllItems(true);
367 }
368
369 // Only update the menuOpenTrigger if menu is currently closed
370 if (!triggerState.isOpen) {
371 menuOpenTrigger.current = trigger;
372 }
373
374 toggleMenu(focusStrategy);
375 };
376
377 let updateLastCollection = useCallback(() => {
378 setLastCollection(showAllItems ? originalCollection : filteredCollection);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected