Skip to content
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

[TextField] Display helperText on focus only #19861

Closed
Floriferous opened this issue Feb 26, 2020 · 7 comments · Fixed by #25927
Closed

[TextField] Display helperText on focus only #19861

Floriferous opened this issue Feb 26, 2020 · 7 comments · Fixed by #25927
Labels
component: text field This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation ready to take Help wanted. Guidance available. There is a high chance the change will be accepted

Comments

@Floriferous
Copy link
Contributor

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?

@AlexAndriyanenko
Copy link
Contributor

I can take this one, if nobody is working on it.

@oliviertassinari oliviertassinari added component: text field This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation labels May 6, 2020
@oliviertassinari
Copy link
Member

@AlexAndriyanenko Thanks for the interest in the issue. While I think that @Floriferous can already solve his problem with the current API and a form library, we have recently make a new module public: useFormControl, it would be interesting to better document it.

@oliviertassinari oliviertassinari added the ready to take Help wanted. Guidance available. There is a high chance the change will be accepted label Oct 10, 2020
@oliviertassinari oliviertassinari changed the title [FormHelperText] Display helperText on focus only [TextField] Display helperText on focus only Feb 10, 2021
@gap777
Copy link

gap777 commented Mar 15, 2021

What's the status of this?

@oliviertassinari
Copy link
Member

@gap777 Missing documentation for the public useFormControl hook.

@t49tran
Copy link
Contributor

t49tran commented Apr 22, 2021

I have added a doc page for useFormControl #25899, hope this will help.

@t49tran
Copy link
Contributor

t49tran commented Apr 24, 2021

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

@andraMacadamian
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation ready to take Help wanted. Guidance available. There is a high chance the change will be accepted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants