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

Function open

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

Source from the content-addressed store, hash-verified

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