question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextField] `OutlinedInput` border overlaps with the label

See original GitHub issue

Duplicates

  • 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:

Screenshot 2022-03-03 at 09 18 55

With TextField:

Screenshot 2022-03-03 at 09 19 26

Expected behavior 🤔

They should both look the same and the border should not overlap the label text on focus.

Steps to reproduce 🕹

Steps:

  1. 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:open
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
MahmoudManscommented, Apr 9, 2022

@theMyth721 I tried the code that @danilo-leal propose and it worked correctly.

1reaction
theMyth721commented, Apr 19, 2022

Yes sure, I have my dissertation due on the 29th, I will send it straight after 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found