Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Autocomplete] regression in behavior for freeSolo Autocomplete with custom Popper/Paper and no options #44048

Open
snapwich opened this issue Oct 8, 2024 · 3 comments
Assignees
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material regression A bug, but worse

Comments

@snapwich
Copy link
Contributor

snapwich commented Oct 8, 2024

Steps to reproduce

Old behavior: https://stackblitz.com/edit/react-ouzbqw-wbhjow?file=Demo.tsx,package.json
New behavior: https://stackblitz.com/edit/react-ouzbqw-vpfhhc?file=Demo.tsx,package.json'

Steps:

  1. Open autocomplete and wait 3 seconds for options to be set to []
  2. click SET DEFAULT OPTIONS to reset and try again

Current behavior

When options prop is set to [] the Autocomplete Popper is no longer rendered. The Autocomplete's state still considers itself open and the onClose handler is not called. Any custom Popper/Paper used in the Autocomplete will not be rendered.

Expected behavior

The Autocomplete stays open if you have a custom Popper/Paper so that you can display other information or maybe even a custom "No Items" option.

Context

In our case we have a custom Autocomplete used as a global site search that renders a custom Popper/Paper that includes chips that link to certain "Advanced search" options as well as contains a recently searched section (the Autocomplete's options) that will show recent results. In our current version of MUI v5.10.17 when there are no recent search options the Autocomplete can still be expanded and the Chips used to navigate to advanced search pages.

capture

capture2

However, updating to the latest 5.x version of MUI v5.16.7 (bug also present in latest 6.x version) when there are no recent search options and the Autocomplete's options prop is [] it will not open, or it will close the Autocomplete if the user has expanded it and options is asynchronously loaded and results in an empty data result. Also when the Autocomplete closes asynchronously because of options=[] it will not call onClose or update its internal open state unless the user does an action that makes it realize it is no longer open (such as clicking somewhere and causing a blur event).

This regression was introduced in #41300

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: autocomplete freesolo no options custom popper paper

@snapwich snapwich added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 8, 2024
@zannager zannager added the component: autocomplete This is the name of the generic UI component, not the React module! label Oct 9, 2024
@siriwatknp siriwatknp added the regression A bug, but worse label Oct 21, 2024
@siriwatknp siriwatknp moved this to Selected in Material UI Oct 21, 2024
@aarongarciah aarongarciah moved this from Selected to In progress in Material UI Oct 29, 2024
@ZeeshanTamboli ZeeshanTamboli added bug 🐛 Something doesn't work package: material-ui Specific to @mui/material labels Oct 29, 2024
@ZeeshanTamboli
Copy link
Member

It's a regression, as you mentioned, but we shouldn't revert #41300 since it fixes #40843. I haven't found a solution yet—any ideas?

@ZeeshanTamboli ZeeshanTamboli removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 29, 2024
@snapwich
Copy link
Contributor Author

i'm not sure what the best solution is, currently we are applying a patch to our internal application to go back to the old behavior

@mui__material@5.16.7.patch

i'm not sure whether this re-introduces #40843 or not since we never experienced that bug to begin with

@ZeeshanTamboli
Copy link
Member

@snapwich I have created a pull request to fix it: #44266. Feel free to check it out.

@DiegoAndai DiegoAndai self-assigned this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material regression A bug, but worse
Projects
Status: In progress
7 participants