Reputation: 2709
I'm using MUI 5 and React and I have this issue that the outlined text field shows line through the label as per the screenshot
I have no idea how to fix it.
My fields looks like this
<FormControl fullWidth variant="outlined">
<InputLabel shrink id={labelId}>
{label}
</InputLabel>
<Controller
as={
<Select
displayEmpty
name={name}
labelId={labelId}
id={name}
label={label}
>
<MenuItem key={`no${name}`} value="">
{intl.formatMessage({
defaultMessage: 'No proxy number',
})}
</MenuItem>
{items.map(pn => (
<MenuItem key={pn.id} value={pn.id}>
<ListItemIcon>
<img
src={pn?.country?.flagIconUrl}
alt={pn.countryCode}
width="20px"
height="15px"
/>
</ListItemIcon>
{pn.value}
</MenuItem>
))}
</Select>
}
name={name}
control={control}
/>
<FormHelperText>{helperText}</FormHelperText>
</FormControl>
Then the above is used as a function called SelectFormInput
to make the specific fields
<Grid item xs={6}>
<SelectFormInput
control={control}
labelId="proxyNumber"
name="proxyNumber"
items={proxyNumbers}
label={intl.formatMessage({
defaultMessage: 'Proxy phone Number',
})}
helperText={intl.formatMessage({
defaultMessage: 'Optional. Phone number used by site users',
})}
/>
</Grid>
<Grid item xs={6}>
<SelectFormInput
control={control}
labelId="inboundProxyNumber"
name="inboundProxyNumber"
items={inboundProxyNumbers}
label={intl.formatMessage({
defaultMessage: 'Inbound Proxy Number',
})}
helperText={intl.formatMessage({
defaultMessage: 'Optional. Phone number seen by candidate',
})}
/>
</Grid>
I was unable to find any solution on the net for my specific situation.
Upvotes: 9
Views: 9327
Reputation: 1
I added a white background color to the inputLabel and it works.
<InputLabel sx={{backgroundColor: "white"}}>Region</InputLabel>
Upvotes: 0
Reputation: 1934
to resolve above issue you need to make the input font size and label fontsize same
<TextField
fullWidth
label="First Name"
InputLabelProps={{ shrink: true, style: { fontWeight: 700, fontSize: 20 } }}
InputProps={{ style: { fontSize: 20, height: 35 } }}
/>
Upvotes: 0
Reputation: 21
you can also try add a background color to InputLabel, on createTheme, this works for me:
import { createTheme } from '@material-ui/core';
const theme = createTheme({
overrides: {
MuiInputLabel: {
root: {
backgroundColor: '#ffffff',
paddingLeft: '4px',
paddingRight: '4px'
}
}
}
});
export default theme;
Upvotes: 2
Reputation: 2709
I found a solution that helped my specific situation. I had to add this
input={<OutlinedInput notched label={label} />}
Inside my
<Select
displayEmpty
name={name}
labelId={labelId}
id={name}
input={<OutlinedInput notched label={label} />} />
And so the label UI has been fixed
Upvotes: 7
Reputation: 2207
There is a <fieldset/>
tag within the FormControl
, and the <legend/>
inside of it is making the white block possible.
I am not sure in your case (<Select/>
), but if you are trying to use raw input with the outlined style, you have to give label prop to the <OutlinedInput/>
.
<FormControl fullWidth>
<InputLabel>Phone</InputLabel>
<OutlinedInput label="Phone" /> // without label="...", you get the line-through
</FormControl>
Upvotes: 2