question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextField] Display helperText on focus only

See original GitHub issue

There 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 like alwaysDisplay: true is set on the FormHelperText 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:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
andraMacadamiancommented, Feb 22, 2022

For me focused doesn’t get updated when using a TextField. I only get the initial false value and no updates later on, even though onFocus and onBlur get triggered. Replacing TextField with other inputs does trigger value updates for focused. Here is a forked sandbox from the docs for useFormControl showing the different behavior for focused when used with TextField and OutlinedInput: https://codesandbox.io/s/useformcontrol-material-demo-forked-2wbxl9?file=/demo.js

2reactions
t49trancommented, Apr 24, 2021

I created a PR to add a section for useFormControl to the TextField document.

Read more comments on GitHub >

github_iconTop 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 >
React Text Field component - Material UI - MUI
Text Fields let users enter and edit text.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found