Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Material UI: How to vertically centre align an icon button?

I have this tsx piece of code to show a text box and an icon button to add something:

<TextField id="outlined-basic" label="22Keyword" defaultValue={"test123"} variant="outlined" />
            <IconButton aria-label="delete">
                <AddCircleOutlineOutlinedIcon />
            </IconButton>

The output is like this:
enter image description here

As you can see, the "+" icon is not vertically aligned with middle of the textbox. I tried adding padding to the button but it ruins the circle that is shown when mouse is hovering and makes it like an oval:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<TextField id="outlined-basic" label="22Keyword" defaultValue={"test123"} variant="outlined" />
            <IconButton aria-label="delete" style={{paddingTop: 19}}>
                <AddCircleOutlineOutlinedIcon />
            </IconButton>

enter image description here

How can I say "all of these elements should be aligned"?

>Solution :

You can easily use Box component and flexbox.

<Box
  display="flex"
  alignItems="center"
>
  <TextField id="outlined-basic" label="22Keyword" defaultValue={"test123"} variant="outlined" />
            <IconButton aria-label="delete">
                <AddCircleOutlineOutlinedIcon />
            </IconButton>
</Box>

It supports all system properties.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading