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
[material-ui][Autocomplete] Value not shown after object reaching the condition it should #41039
Comments
Hello, I found some issues in your code that could be causing the problem. In fact, There was inconsistent management of inputValue and value props for the Autocomplete components: there was an inconsistency in how you managed the inputValue prop for the second Autocomplete component. You passed an inputValue prop but did not handle it properly with an onInputChange handler. The inputValue prop in Autocomplete is used to control the text input part of the component directly, and without proper handling, it can lead to unexpected behavior. |
@Hari0812 const options = ['Option 1', 'Option 2']; export function App() { const changeInput = (key, val) => { return ( { spec: ${spec.first} }{ dec: ${spec.second} }<Autocomplete value={spec.first || ''} onChange={(event, value) => { changeInput('first', value); }} id="autocomplete-first" options={options} sx={{ width: 300 }} renderInput={(params) => <TextField {...params} label="First Option" />} /> <Autocomplete value={spec.second || ''} onChange={(event, value) => { changeInput('second', value); }} id="autocomplete-second" options={options} sx={{ width: 300 }} renderInput={(params) => <TextField {...params} label="Second Option" />} /> ); } ` |
Hi @EyaOuenniche Screen.Recording.2024-02-12.at.7.47.45.AM.movFIX: Thanks |
Hello @Hari0812 ,
|
Hi @EyaOuenniche |
Actually there I did not, I just reproduced your code and added this part
If you would like to remove the redundant value for inputValue and value prop, you need to separate them into 2 different states. here is my suggestion:
|
Thanks :) |
Steps to reproduce
Link to live example: (required)
(https://stackblitz.com/edit/stackblitz-starters-pumcfo?description=React%20%20%20TypeScript%20starter%20project&file=package.json,src%2FApp.tsx&title=React%20Starter)
Current behavior
In the link i provide a code that cause unexpected behaviour the behaviour was initially i set the state to empty object and i use the values in Autocomplete tag initially it was undefined so the value is not shown after setting the value when object reaches the condition it should empty the both value of the dropdown but the selected value is shown inside the box
Expected behavior
when i set the state to empty object the text shown inside the box should become empty
Context
No response
Your environment
npx @mui/envinfo
Search keywords: Cache
The text was updated successfully, but these errors were encountered: