diff --git a/Autocomplete/Autocomplete.js b/Autocomplete/Autocomplete.js index f352608eb91c5b5c494f20b0a7326bb4d93bccec..5b3f92b882c6cb2803f54165584470f7851b9be1 100644 --- a/Autocomplete/Autocomplete.js +++ b/Autocomplete/Autocomplete.js @@ -620,43 +620,56 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(function Autocomplete(inProps children: children })) })); - let autocompletePopper = null; - if (groupedOptions.length > 0) { - autocompletePopper = renderAutocompletePopperChildren( /*#__PURE__*/_jsx(AutocompleteListbox, _extends({ - as: ListboxComponent, - className: classes.listbox, - ownerState: ownerState - }, otherListboxProps, ListboxProps, { - ref: combinedListboxRef, - children: groupedOptions.map((option, index) => { - if (groupBy) { - return renderGroup({ - key: option.key, - group: option.group, - children: option.options.map((option2, index2) => renderListOption(option2, option.index + index2)) - }); - } - return renderListOption(option, index); - }) - }))); - } else if (loading && groupedOptions.length === 0) { - autocompletePopper = renderAutocompletePopperChildren( /*#__PURE__*/_jsx(AutocompleteLoading, { - className: classes.loading, - ownerState: ownerState, - children: loadingText - })); - } else if (groupedOptions.length === 0 && !freeSolo && !loading) { - autocompletePopper = renderAutocompletePopperChildren( /*#__PURE__*/_jsx(AutocompleteNoOptions, { - className: classes.noOptions, - ownerState: ownerState, - role: "presentation", - onMouseDown: event => { - // Prevent input blur when interacting with the "no options" content - event.preventDefault(); - }, - children: noOptionsText - })); - } + let autocompletePopper = renderAutocompletePopperChildren( + (function () { + let children = []; + if (loading && groupedOptions.length === 0) { + children.push( + /*#__PURE__*/_jsx(AutocompleteLoading, { + className: classes.loading, + ownerState: ownerState, + children: loadingText + }) + ); + } + if (groupedOptions.length === 0 && !freeSolo && !loading) { + children.push( + /*#__PURE__*/_jsx(AutocompleteNoOptions, { + className: classes.noOptions, + ownerState: ownerState, + role: "presentation", + onMouseDown: event => { + // Prevent input blur when interacting with the "no options" content + event.preventDefault(); + }, + children: noOptionsText + }) + ); + } + if (groupedOptions.length > 0) { + children.push( + /*#__PURE__*/_jsx(AutocompleteListbox, _extends({ + as: ListboxComponent, + className: classes.listbox, + ownerState: ownerState + }, otherListboxProps, ListboxProps, { + ref: combinedListboxRef, + children: groupedOptions.map((option, index) => { + if (groupBy) { + return renderGroup({ + key: option.key, + group: option.group, + children: option.options.map((option2, index2) => renderListOption(option2, option.index + index2)) + }); + } + return renderListOption(option, index); + }) + })) + ); + } + return children; + })() + ); return /*#__PURE__*/_jsxs(React.Fragment, { children: [/*#__PURE__*/_jsx(AutocompleteRoot, _extends({ ref: ref,