Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set helperText in react-select

I am using react-select and TextField Material-UI. Is there possibility to set helperText (small text below component) in react-select like it is made in TextField?

Thank You for help in advance.

P.S. I do not think my question is duplication of this question. The other post is about how to custom component which is a part of react-select, I want to add an option that react-select doesnt have.

like image 507
user0810 Avatar asked Dec 03 '22 18:12

user0810


1 Answers

TextField is mainly a convenience wrapper around several lower-level components including FormHelperText.

Here is the Autocomplete demo in the Material-UI documentation using react-select: https://material-ui.com/demos/autocomplete/#react-select

Here is a modified version of that demo using FormHelperText: https://codesandbox.io/s/rynvn8po5p

Here's the relevant snippet from that code:

          <Select
            classes={classes}
            styles={selectStyles}
            options={suggestions}
            components={components}
            value={this.state.single}
            onChange={this.handleChange("single")}
            placeholder="Search a country (start with a)"
            isClearable
          />
          <FormHelperText>Here's my helper text</FormHelperText>

The Material-UI demos for Select also show many examples of using FormHelperText without using TextField: https://material-ui.com/demos/selects/#simple-select

Here is the API documentation for FormHelperText: https://material-ui.com/api/form-helper-text/

like image 65
Ryan Cogswell Avatar answered Dec 11 '22 15:12

Ryan Cogswell