[TextField] Display helperText on focus only
See original GitHub issueThere may already be a nice way to do this, but I couldn’t find it.
I’d like to be able to display an Input’s FormHelperText only if the input is focused. It should however always display the helperText if it is an error (and override the helperText).
I believe these are the main possible states:
- If input is
error: true
, display the error helperText - If input is
error: false
, and input is focused: display the helperText - If input is
error: false
, and input is not focused: don’t display the helperText - If input is
error: false
, and input is not focused, but something likealwaysDisplay: true
is set on theFormHelperText
component, then display the helperText
Excluded states:
- No helperText provided -> don’t display it obviously
- Space (
' '
) helperText provided, show placeholder space for a potential helperText later
Related to #2474
Maybe the component’s API could be revisited to handle these use cases more easily? Make it easier to pass in helperText, and errorHelperText together for example?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
[TextField] Display helperText on focus only #19861 - GitHub
I'd like to be able to display an Input's FormHelperText only if the input is focused. It should however always display the helperText...
Read more >Display the helper text when TextField focused in Material UI
Easiest solution would be to use a flag which holds the information about the clicked (touched) state for the TextField. Example:
Read more >Text field helper text - Material Design
Helper text gives context about a field's input, such as how the input will be used. It should be visible either persistently or...
Read more >Material.TextField.HelperText - elm-mdc-alpha 1.4.0
Helper text conveys additional guidance about the input field, such as how it will be used. ... being persistently visible or visible only...
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
For me
focused
doesn’t get updated when using aTextField
. I only get the initialfalse
value and no updates later on, even thoughonFocus
andonBlur
get triggered. ReplacingTextField
with other inputs does trigger value updates forfocused
. Here is a forked sandbox from the docs foruseFormControl
showing the different behavior forfocused
when used withTextField
andOutlinedInput
: https://codesandbox.io/s/useformcontrol-material-demo-forked-2wbxl9?file=/demo.jsI created a PR to add a section for
useFormControl
to theTextField
document.