From 0c70ca0eb616f7f4a4d9d8184ab9cfe1354d5d66 Mon Sep 17 00:00:00 2001 From: ZeeshanTamboli Date: Wed, 25 Dec 2024 18:46:47 +0530 Subject: [PATCH] revert 41300 --- .../src/Autocomplete/Autocomplete.js | 91 ++++++++----------- .../src/Autocomplete/Autocomplete.test.js | 16 ---- 2 files changed, 40 insertions(+), 67 deletions(-) diff --git a/packages/mui-material/src/Autocomplete/Autocomplete.js b/packages/mui-material/src/Autocomplete/Autocomplete.js index d144af535c10c2..97f782403fc3c6 100644 --- a/packages/mui-material/src/Autocomplete/Autocomplete.js +++ b/packages/mui-material/src/Autocomplete/Autocomplete.js @@ -671,56 +671,6 @@ const Autocomplete = React.forwardRef(function Autocomplete(inProps, ref) { const clearIndicatorSlotProps = externalForwardedProps.slotProps.clearIndicator; const popupIndicatorSlotProps = externalForwardedProps.slotProps.popupIndicator; - const renderAutocompletePopperChildren = (children) => ( - - - {children} - - - ); - - let autocompletePopper = null; - if (groupedOptions.length > 0) { - autocompletePopper = renderAutocompletePopperChildren( - // TODO v7: remove `as` prop and move ListboxComponentProp to externalForwardedProps or remove ListboxComponentProp entirely - // https://github.com/mui/material-ui/pull/43994#issuecomment-2401945800 - - {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( - - {loadingText} - , - ); - } else if (groupedOptions.length === 0 && !freeSolo && !loading) { - autocompletePopper = renderAutocompletePopperChildren( - { - // Prevent input blur when interacting with the "no options" content - event.preventDefault(); - }} - > - {noOptionsText} - , - ); - } - return ( - {anchorEl ? autocompletePopper : null} + {anchorEl ? ( + + + {loading && groupedOptions.length === 0 ? ( + + {loadingText} + + ) : null} + {groupedOptions.length === 0 && !freeSolo && !loading ? ( + { + // Prevent input blur when interacting with the "no options" content + event.preventDefault(); + }} + > + {noOptionsText} + + ) : null} + {groupedOptions.length > 0 ? ( + + {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); + })} + + ) : null} + + + ) : null} ); }); diff --git a/packages/mui-material/src/Autocomplete/Autocomplete.test.js b/packages/mui-material/src/Autocomplete/Autocomplete.test.js index 181fdf378d2bc9..898d36a623c688 100644 --- a/packages/mui-material/src/Autocomplete/Autocomplete.test.js +++ b/packages/mui-material/src/Autocomplete/Autocomplete.test.js @@ -2440,22 +2440,6 @@ describe('', () => { expect(container.querySelector(`.${classes.endAdornment}`)).to.equal(null); }); - - it('should not render popper when there are no options', () => { - render( - } - slotProps={{ - popper: { 'data-testid': 'popperRoot' }, - }} - />, - ); - const popper = screen.queryByTestId('popperRoot'); - expect(popper).to.equal(null); - }); }); describe('prop: onChange', () => {