I was using an older version of the library and had things working as expected. When I updated to the latest, I started to see issues with loosing focus when typing values into a TextField
. However, I can't generate a way to replicate the issue because I have a validation script and layers of scope that I'm dealing with.
Key observations:
The issues arise when I change the component from
Input
toTextField
=> instant malfunction with focus.This is only relevant for a "controlled" component with an
onChange
callback;onBlur
is not a problem.
There are similar questions/answers on both stackOverflow and in the issues archive using TextField
in various contexts.
From what I can gather, there are several troubleshooting options. Would it be possible to let me know if there are others?
- must set the name prop (not so with
Input
) - turn off
autoFocus
? - use value instead of
defaultValue
(required foronChange
) - set
inputRef={input => input && input.focus()}
? - use an
id
that does not change value between renders - use indirection by wrapping the
TextField
- avoid defining functions inside the definition of the component
Other: to help debug, track the value of the active element using document.activeElement
in the devTools debugger.
I recognize that a lot of this should be well understood from a basic understanding of html forms. However, what makes it tricky is that we are dealing with an API (a wonderful API at that :), that abstracts much of what is going on under the hood, and thus the need for an API-specific "howto".
Thank you for letting me know ideas for how to troubleshoot this thoroughly annoying and debilitating misunderstanding in how I'm doing things.
Thank you in advance!
- E