Focus on TextField is lost if variant is changed on the fly
See original GitHub issue- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
If the variant
property of a TextField is changed on the fly the focus on the field is lost
Expected Behavior 🤔
Would be nice if focus is kept.
Steps to Reproduce 🕹
Go to https://odtfp.csb.app/
- type something in the field
- …then type an
_
char (which enable the error state) - …see focus being lost
- re-focus the field manually
- remove the
_
(so exit the “error state” - focus is lost again
Context 🔦
What I was trying to achieve is to have a better highlight of the field error so I’m switching from “standard” to “filled” variant on the fly in case of error.
I perfectly know that I can have the same visual behavior just using styles, and I’m going in this direction, but I was not sure if this should be threat as a minor bug or not, so I’m reporting this.
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v4.9.9 |
React | 16.12.0 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Focus on TextField is lost if variant is changed on the fly #20821
The issue is present in the latest release. I have searched the issues of this repository and believe that this is not a...
Read more >Flutter TextField is losing data when focus changes
I think issue is not in loosing focus, but rather in the fact that widget is rebuilt, it's class recreated and as consequence...
Read more >Focus and text fields - Flutter documentation
When a text field is selected and accepting input, it is said to have “focus.” Generally, users shift focus to a text field...
Read more >Migrating to v5 - Bootstrap
Track and review changes to the Bootstrap source files, documentation, and components to help you migrate from v4 to v5. On this page....
Read more >First steps with Flutter - Part 3: Responding to user input
Today we're going to explore how to actually do something when the user interacts with the widgets that we've added to our layout....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think for uncontrolled components the state would be lost as well. It would definitely be nice to be able to switch variants but the amount of work required isn’t justified compared to the gain. Generally you don’t switch variants since you only have a single variant per form anyway.
@eps1lon @oliviertassinari I updated the codesandox with an uncontrolled example and there’s the same issue. However I really don’t find useful adding any complexity for supporting this edge case. My report was only just in case it was hiding other issues. Changing the variant on the fly is not useful.
Thanks all for your time!