Cannot set the default helperText for Select components in theme
See original GitHub issueDescribe the bug
Of course, vanilla mui Select elements do not have helperText
; you have to add a FormHelperText
to your form control with the helper text as a child. But setting props.MuiFormHelperText.children='default helper text'
in my theme only changes the helper text for vanilla FormHelperText
s.
This is necessary because I want to set the helper text to a space ' '
to prevent form resizing, e.g. when a field has error helper text.
To Reproduce Steps to reproduce the behavior:
- Go to this forked sandbox
- Search for the comment:
// HERE: Try commenting the following line. The helper text
- … And comment the following line 😃
The additions I made are roughly…
import {
// ...
FormControl,
InputLabel,
Select as MuiSelect,
MenuItem,
} from '@material-ui/core'
// ...
const theme = createMuiTheme({
props: {
// ...
MuiFormHelperText: {
children: 'This should be the default helper text of all Select components',
},
})
// ...
// In the render function of MainForm
const formFields = [
// Default helper text doesn't work here
<Select
label="Pick some cities..."
name="cities"
required={required.cities}
data={selectData}
multiple={true}
// HERE: Try commenting the following line. The helper text
helperText="Woah helper text"
/>,
// Default helper text works here
<FormControl>
<InputLabel id="demo">Cities</InputLabel>
<MuiSelect labelId="demo" fullWidth>
{selectData.map(({ label, value }) => (
<MenuItem value={value}>{label}</MenuItem>
))}
</MuiSelect>
<FormHelperText>{/* Insert helper text here */}</FormHelperText>
</FormControl>,
];
I also removed most of the form components to simplify the example.
Expected behavior
Commenting out the line indicated should change the select helperText to 'This should be the default helper text of all Select components'
.
Additional context This ‘bug’ is not a super high priority, but it would help with theming.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
Closing, seems to be a non-issue now.
Example repo