[TextField] `OutlinedInput` border overlaps with the label
See original GitHub issueDuplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
<OutlinedInput /> Doesn’t work properly with labels.
The label overlaps, but works fine with <TextField />
I want to use OutlinedInput as there seems to be greater flexibility, but I may not have a choice until this is fixed
See code and screenshots below:
import React from 'react'
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import { useForm } from 'react-hook-form';
/**
* First I install all dependencies:
* These are the components that wrap a text input:
*/
import FormControl from '@mui/material/FormControl';
import InputLabel from '@mui/material/InputLabel';
import OutlinedInput from '@mui/material/OutlinedInput';
import FormHelperText from '@mui/material/FormHelperText';
import TextField from '@mui/material/TextField';
import FormControlLabel from '@mui/material/FormControlLabel';
import RadioGroup from '@mui/material/RadioGroup';
import Radio from '@mui/material/Radio';
import Checkbox from '@mui/material/Checkbox';
/** The Button we will use for Submitting the form */
import Button from '@mui/material/Button';
/**
*
* @returns <FormValidation />
*/
export default function FormValidation() {
/**
* Get the three most important porops from useForm, also getting watch in case I want to compare passwords for example
*/
const {register, handleSubmit, formState, watch} = useForm();
return (
<Box component='section' sx={{}}>
<Typography variant='h4'>Form Validation with MUI</Typography>
<Typography variant='body1'>
There is no built in Form Validation in MUI so I will now try to integrate with React Hook Form,
This same component will also be with Forms
We are going to use almost the same form from the react hook form example.
Here we use First, Last name for text, email, number,
</Typography>
<Box sx={{my: 5}}>
<form onSubmit={handleSubmit((data) => {
console.log('Using React Hook Form with MUI Controls!', data);
})}>
<FormControl fullWidth>
<InputLabel>First name:</InputLabel>
<OutlinedInput />
<FormHelperText></FormHelperText>
</FormControl>
{/* Text field is good but limited, for now we work with OutlinedInput, but it has the OutlinedInput bug */}
<TextField
error={false}
fullWidth
variant='outlined'
name='firstName'
label='First Name'
color='success'
InputLabelProps={{sx: {}}}
/>
</form>
</Box>
</Box>
)
}
See screenshots below:
With OutlinedInput:
With TextField:
Expected behavior 🤔
They should both look the same and the border should not overlap the label text on focus.
Steps to reproduce 🕹
Steps:
- Just test an <OutlinedInput /> basic element with a InputLabel and see the result2.
Im dont know why but with CodeSandbox Im not getting to see the file for the <Demo /> component and somehow I can’t save a sandbox properly but you should be able to test it very easily by simply creating the component
Context 🔦
Learning MUI
Your environment 🌎
`npx @mui/envinfo`
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Material-UI TextField Outline Label is overlapping with border ...
Click the "Confirmation Code" TextField . Notice the border has rendered incorrectly and is causing the label to overlap with the border. For ......
Read more >Textfield label overlapping issue - code helper
Note the textfield's label/title - The border will still visible behind the label text. This is an error, because usually the component figures...
Read more >inputlabelprops= shrink true | The AI Search Engine You Control
Keep material UI textfield label on top when text field has no value ... OutlinedInput will display a border notch If all the...
Read more >OutlinedInput API - Material UI - MUI
API reference docs for the React OutlinedInput component. Learn about the props, CSS, and other APIs of this exported module.
Read more >[Solved]-React Material UI Label Overlaps with Text-Reactjs
I fixed it by adding the condition on shrink based on a text field value. Just add this code in the text field:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@theMyth721 I tried the code that @danilo-leal propose and it worked correctly.
Yes sure, I have my dissertation due on the 29th, I will send it straight after 😃