-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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]TextField] label doesn't take its place after clearing value via inputRef (uncontrolled state) #42901
Comments
@evgeniyworkbel The CodeSandbox link you provided is private. Can you make it public? |
@ZeeshanTamboli I had made |
@evgeniyworkbel It is because the TextField component isn't re-rendering when the value is cleared through |
The CodeSandbox link you provided is private. Can you make it public? |
Made it public now. |
The behaviour in example is weird |
What is weird? |
Label is not shrinked when is typing |
I updated the CodeSandbox: https://codesandbox.io/p/sandbox/cranky-moon-forked-8wkr3q. As asked before, why don't you convert your component to controlled component to handle such cases seamlessly. |
Because I need to debounce value inside to update search params |
And you can't do that with a controlled component? Can you show an example? Does the updated CodeSandbox work for you? |
https://codesandbox.io/p/sandbox/cranky-moon-forked-s55hpw?file=%2Fsrc%2FApp.tsx%3A17%2C36 |
You are debouncing the function wrong. |
it makes sense but the problem remains: controlled input is debounced badly - user wants to type fast and controlled input don't allow this |
You can sync the value with local state: https://codesandbox.io/p/sandbox/cranky-moon-forked-fn2x9x?file=%2Fsrc%2FControlledInput.tsx%3A15%2C31. I suggest asking such questions on StackOverflow. |
Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information. |
Search keywords
mui textfield clear ref uncontrolled
Latest version
Steps to reproduce
Link to live example: https://codesandbox.io/p/sandbox/cranky-moon-lcxtdf?file=%2Fsrc%2FControlledInput.tsx%3A5%2C52
Steps:
Current behavior
After clearing value of input, label didn't back to its place, it is at top of input, placeholder is shown
Expected behavior
After clearing value of input, label back to its place(inside of input), placeholder hides
Context
I use uncontrolled state control of text field: i pass defaultValue prop and inputRef.
I use Google Chrome lates version
Your environment
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: