Repository: adobe/react-spectrum
File: packages/@react-aria/combobox/src/useComboBox.ts (TypeScript)

Code before:
  }, [state.isOpen, inputRef, popoverRef]);

  useUpdateEffect(() => {
    // Re-show focus ring when there is no virtually focused item.
    if (!focusedItem && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) === inputRef.current) {
      dispatchVirtualFocus(inputRef.current, null);
    }
  }, [focusedItem]);

  useEvent(listBoxRef, 'react-aria-item-action', state.isOpen ? () => {
    state.close();
  } : undefined);

  // usePopover -> useOverlay calls useInteractOutside, but ComboBox is non-modal, so `isDismissable` is false
  // Because of this, onInteractOutside is not passed to useInteractOutside, so we need to call it here.
  useInteractOutside({
    ref: popoverRef,
    onInteractOutside: (e) => {
      if (nodeContains(buttonRef?.current, getEventTarget(e) as Element)) {
        return;
      }
      state.close();
    },
    isDisabled: !state.isOpen
  });

  return {
    labelProps,
    buttonProps: {
      ...menuTriggerProps,
      ...triggerLabelProps,
      excludeFromTabOrder: true,
      preventFocusOnPress: true,
      onPress,
      onPressStart,
      isDisabled: isDisabled || isReadOnly
    },
    inputProps: mergeProps(inputProps, {
      role: 'combobox',
      'aria-expanded': menuTriggerProps['aria-expanded'],
      'aria-controls': state.isOpen ? menuProps.id : undefined,
      // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)
      'aria-autocomplete': 'list',
      'aria-activedescendant': focusedItem ? getItemId(state, focusedItem.key) : undefined,
      onTouchEnd,
      // This disable's iOS's autocorrect suggestions, since the combo box provides its own suggestions.
      autoCorrect: 'off',
      // This disable's the macOS Safari spell check auto corrections.
      spellCheck: 'false'
    }),
    listBoxProps: mergeProps(menuProps, listBoxProps, {

Review comment (suggestion):
This will cause the combobox to close its dropdown if the user clicks in the input field to move the text cursor while the input field is open, thus also clearing the input value prematurely. To reproduce, try going to https://reactspectrum.blob.core.windows.net/reactspectrum/00b9c9579f9dbff5d7f0a850d1add047a221832c/storybook-s2/index.html?path=/docs/combobox--docs, typing "Mi", then trying to click inbetween "M" and "i" to move the cursor

Code after:
  }, [state.isOpen, inputRef, popoverRef]);

  useUpdateEffect(() => {
    // Re-show focus ring when there is no virtually focused item.
    if (!focusedItem && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) === inputRef.current) {
      dispatchVirtualFocus(inputRef.current, null);
    }
  }, [focusedItem]);

  useEvent(listBoxRef, 'react-aria-item-action', state.isOpen ? () => {
    state.close();
  } : undefined);

  // usePopover -> useOverlay calls useInteractOutside, but ComboBox is non-modal, so `isDismissable` is false
  // Because of this, onInteractOutside is not passed to useInteractOutside, so we need to call it here.
  useInteractOutside({
    ref: popoverRef,
    onInteractOutside: (e) => {
      let target = getEventTarget(e) as Element;
      if (nodeContains(buttonRef?.current, target) || nodeContains(inputRef.current, target)) {
        return;
      }
      state.close();
    },
    isDisabled: !state.isOpen
  });

  return {
    labelProps,
    buttonProps: {
      ...menuTriggerProps,
      ...triggerLabelProps,
      excludeFromTabOrder: true,
      preventFocusOnPress: true,
      onPress,
      onPressStart,
      isDisabled: isDisabled || isReadOnly
    },
    inputProps: mergeProps(inputProps, {
      role: 'combobox',
      'aria-expanded': menuTriggerProps['aria-expanded'],
      'aria-controls': state.isOpen ? menuProps.id : undefined,
      // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)
      'aria-autocomplete': 'list',
      'aria-activedescendant': focusedItem ? getItemId(state, focusedItem.key) : undefined,
      onTouchEnd,
      // This disable's iOS's autocorrect suggestions, since the combo box provides its own suggestions.
      autoCorrect: 'off',
      // This disable's the macOS Safari spell check auto corrections.
      spellCheck: 'false'
    }),