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] Autocomplete automatically deletes the input #36234

Closed
2 tasks done
Paul6552 opened this issue Feb 17, 2023 · 4 comments
Closed
2 tasks done

[Autocomplete] Autocomplete automatically deletes the input #36234

Paul6552 opened this issue Feb 17, 2023 · 4 comments
Assignees
Labels
component: autocomplete This is the name of the generic UI component, not the React module!

Comments

@Paul6552
Copy link

Paul6552 commented Feb 17, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Take any example of autocomplete other than the FreeSolo.

Autocomplete example page

Write "Hello" in the input field where there is no option to do so.Click out of the input field.
The "Hello" input disappears. But I would like the text to remain.

vid-2023-02-17_10.29.21.mp4

Now you could say that you should just use freeSolo. The problem with FreeSolo is that the noOptionsText option no longer works. Is this a mistake? Should that be so?

At least this behavior of MUI is inappropriate. It should always be up to the programmer whether he wants to use this function or not. In my case I need this function.

Codesandbox example

In my example try to input anything and click away. The input disappeares. Try to set freeSolo -> noOptionsText is not working anymore

Current behavior 😯

Text in the input field disappears

Expected behavior 🤔

Text in the input field should stay

Context 🔦

No response

Your environment 🌎

No response

@Paul6552 Paul6552 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 17, 2023
@zannager zannager added the component: autocomplete This is the name of the generic UI component, not the React module! label Feb 17, 2023
@MenoIy
Copy link

MenoIy commented Feb 17, 2023

I don't know whether that will help, but you can have a look at #19663

@mikededo
Copy link

mikededo commented Feb 17, 2023

It could be a side effect of the onBlur or onFocus functions. Is it possible that you provide the code of the entire component?

@sai6855
Copy link
Contributor

sai6855 commented Feb 21, 2023

@Paul6552 you can set clearOnBlur={false} to restore inputValue when input looses focus

csb: https://codesandbox.io/s/wizardly-pascal-jv8ct2?file=/demo.js

<Autocomplete
  disablePortal
  clearOnBlur={false}
  id="combo-box-demo"
  options={top100Films}
  sx={{ width: 300 }}
  renderInput={(params) => <TextField {...params} label="Movie" />}
/>

@Paul6552
Copy link
Author

@sai6855 thank you so much. It works :)

@zannager zannager removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

6 participants