-
-
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] Prevent shrink animation in uncontrolled Autocomplete when default value is set #44873
Open
ZeeshanTamboli
wants to merge
11
commits into
mui:master
Choose a base branch
from
ZeeshanTamboli:fix-44506-autocomplete-shrink-animation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Autocomplete] Prevent shrink animation in uncontrolled Autocomplete when default value is set #44873
ZeeshanTamboli
wants to merge
11
commits into
mui:master
from
ZeeshanTamboli:fix-44506-autocomplete-shrink-animation
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZeeshanTamboli
added
the
component: autocomplete
This is the name of the generic UI component, not the React module!
label
Dec 28, 2024
Netlify deploy previewhttps://deploy-preview-44873--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
ZeeshanTamboli
changed the title
[Autocomplete] Fix shrink animation in Autocomplete when value is set
[WIP][Autocomplete] Fix shrink animation in Autocomplete when value is set
Dec 28, 2024
2 tasks
ZeeshanTamboli
changed the title
[WIP][Autocomplete] Fix shrink animation in Autocomplete when value is set
[Autocomplete] Fix shrink animation in Autocomplete when value is set
Jan 2, 2025
ZeeshanTamboli
added
bug 🐛
Something doesn't work
package: material-ui
Specific to @mui/material
labels
Jan 2, 2025
ZeeshanTamboli
changed the title
[Autocomplete] Fix shrink animation in Autocomplete when value is set
[Autocomplete] Prevent shrink animation in Autocomplete when value is set
Jan 2, 2025
ZeeshanTamboli
changed the title
[Autocomplete] Prevent shrink animation in Autocomplete when value is set
[Autocomplete] Prevent shrink animation in Autocomplete when value is set for uncontrolled Autocomplete
Jan 4, 2025
ZeeshanTamboli
changed the title
[Autocomplete] Prevent shrink animation in Autocomplete when value is set for uncontrolled Autocomplete
[Autocomplete] Prevent shrink animation in Autocomplete when default value is set for uncontrolled Autocomplete
Jan 4, 2025
ZeeshanTamboli
changed the title
[Autocomplete] Prevent shrink animation in Autocomplete when default value is set for uncontrolled Autocomplete
[Autocomplete] Prevent shrink animation in uncontrolled Autocomplete when default value is set
Jan 4, 2025
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #44506
Also related to #36548 (see comment 1 and comment 2).
Problem
The shrink animation on input label is triggered when the HTML input value in the notched outlined input component changes from empty to filled.
In the
Autocomplete
component, the HTML input value is determined by theinputValue
prop. Initially,inputValue
is empty (source) whendefaultValue
prop is provided. The input value is later updated via state (source), causing a re-render and the shrink animation.Fix
Compute the initial
inputValue
on the first render whendefaultValue
is provided. This ensures the input is correctly initialized, preventing the shrink animation on InputLabel.Alternative that can be considered
Tell developer to use a controlled
Autocomplete
by managinginputValue
andonInputValueChange
. This avoids reliance on the default state mechanism. CodeSandbox: https://codesandbox.io/p/sandbox/stoic-fire-zz67mz-forked-8k9lmgBut since we already set the HTML input value using
defaultValue
, it makes sense to initializeinputValue
accordingly during the first render to avoid the animation. And it already works for other components likeTextField
andSelect
.Not sure how to add a test case for this.
Demos