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

Function open

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

Source from the content-addressed store, hash-verified

324 defaultOpen: undefined
325 });
326 let open = (focusStrategy: FocusStrategy | null = null, trigger?: MenuTriggerAction) => {
327 let displayAllItems = trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus');
328 // Prevent open operations from triggering if there is nothing to display
329 // Also prevent open operations from triggering if items are uncontrolled but defaultItems is empty, even if displayAllItems is true.
330 // 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)
331 if (
332 allowsEmptyCollection ||
333 filteredCollection.size > 0 ||
334 (displayAllItems && originalCollection.size > 0) ||
335 props.items
336 ) {
337 if (displayAllItems && !triggerState.isOpen && props.items === undefined) {
338 // Show all items if menu is manually opened. Only care about this if items are undefined
339 setShowAllItems(true);
340 }
341
342 menuOpenTrigger.current = trigger;
343 setFocusStrategy(focusStrategy);
344 triggerState.open();
345 }
346 };
347
348 let toggle = (focusStrategy: FocusStrategy | null = null, trigger?: MenuTriggerAction) => {
349 let displayAllItems = trigger === 'manual' || (trigger === 'focus' && menuTrigger === 'focus');

Callers 2

useComboBoxStateFunction · 0.70
setFocusedFunction · 0.70

Calls 1

openMethod · 0.65

Tested by

no test coverage detected