[AutoComplete] does not update displayed value if options are received after the value
See original GitHub issueDuplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
An autocomplete who has its options given to it after the value, does not update its displayed value, even though getOptionLabel returns the right value
Expected behavior 🤔
The displayed value should reflect the getOptionLabel function
Steps to reproduce 🕹
Steps:
- Open page, information about object is fetched and set
- Options are fetched and tend to arrive after the information about the object
- Options are set and given to AutoComplete
- AutoComplete displays initial value instead updating to the result of getOptionLabel
If we swap the delays and make the information about the object arrive after the options, the correct value is displayed. getOptionLabel returns the correct value at all times. The value is updated when interacting with the field
Context 🔦
It is technically a duplicate of #25096 (which I opened last year) but we just got around to upgrading to MUI 5 last week (in part hoping to have this fixed as noted in #27313) but after tests, the issue persists. After digging, I saw that this pull request did a regression discussed in #28098 and an additional fix was done.
Long story short, the reported behavior is still incorrect for us. getOptionLabel returns the right value but the initial value is displayed incorrectly on load of the page
Is there a way to force a value update? Any workaround?
Your environment 🌎
npx @mui/envinfo
System:
OS: Windows 10 10.0.19044
Binaries:
Node: 16.15.1 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 8.13.2 - ~\Desktop\isovision-web-ui-mui5\node_modules\.bin\npm.CMD
Browsers:
Chrome: 103.0.5060.114
Edge: Spartan (44.19041.1266.0), Chromium (103.0.1264.37)
npmPackages:
@emotion/react: ^11.9.3 => 11.9.3
@emotion/styled: ^11.9.3 => 11.9.3
@mui/base: 5.0.0-alpha.87
@mui/icons-material: ^5.8.4 => 5.8.4
@mui/lab: ^5.0.0-alpha.88 => 5.0.0-alpha.88
@mui/material: ^5.8.6 => 5.8.6
@mui/private-theming: 5.8.6
@mui/styled-engine: 5.8.0
@mui/styles: ^5.8.6 => 5.8.6
@mui/system: 5.8.6
@mui/types: 7.1.4
@mui/utils: 5.8.6
@mui/x-date-pickers: ^5.0.0-alpha.7 => 5.0.0-alpha.7
@types/react: 17.0.47
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
typescript: 4.7.4
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Related StackOverflow Question
We are not invoking
onChangeif the options change, and in my opinion this is correct behavior (as there wasn’t any interaction with the component). I would assume you can wait for all promises to resolve before setting the value, this way it should work as expected.Confirmed as working in my use case, thanks