-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Label of the TextField shrinks when there is an option selected while the label of a normal filled TextField doesn't #36548
Comments
@bartvanenter Thanks for reporting this, I agree that the transition on the Autocomplete is not ideal and it should behave like the TextField instead |
The solution I provided above was not working for all the use cases though. Here is a more extensive solution.
|
@mj12albert if you haven't started working on this, can you assign it to me. |
@sai6855 Done, thank you 🙌 |
this issue is fixed in #36741 codesandbox: https://codesandbox.io/s/gracious-kepler-8x67ex @bartvanenter fix will be released in next release |
Thank you very much!! |
We ran across this issue too, and it appears to still be happening in the latest release. See codesandbox: I think the codesandbox @sai6855 posted works because it was setting inputValue and value, which I believe is the workaround @bartvanenter mentioned. If inputValue is removed, the label still animates incorrectly. Can we re-open this issue? |
+1 seeing this with |
@rblackledge-shibumi @ewarrenG The issue is tracked in #44506, and I'm working on a fix in #44873. |
Duplicates
Latest version
Summary 💡
I have a form that includes both TextField components and Autocomplete components.
When entering the page the label of the Autocomplete shrinks with a transition, while the label of the TextField has already been shrunken and is in the right place.
This is not really consistent and makes the form look messy.
Expected behavior:
When an option has been selected in the Autocomplete the label should already start shrunken, just like the TextField component.
While the Autocomplete component has a value, the
inputProps.value
of the Autocomplete is empty at the first render which causes the label to be positioned inside the TextField.Then on the third render the
inputProps.value
is filled with the value that is provided to the Autocomplete, which causes the label to shrink to the top left of the TextField.See the screenshot below:
I found a workaround for this issue that fills the input with the
inputProps.value
when the TextField gets focus and using the option label of the provided value when the input doesn't have focus. See code below:I think this happens because in the
useAutocomplete
hook on line 159 theinputValue.default
is set to an empty string, and later it will be filled with the value in an useEffect.Examples 🌈
Kapture.2023-03-17.at.11.33.17.webm
See codesandbox for this example
Motivation 🔦
Would be nice if the behavior of the input labels would be consistent and less jumpy and messy.
The text was updated successfully, but these errors were encountered: