1

How to insert an icon centering material ui button?

Piece of Code:

 <Button variant="outlined" startIcon={<Add color='primary'/>} style={{ maxWidth: "36px" }} />

Expected behavior:

enter image description here

Current behavior:

enter image description here

KillMe
  • 184
  • 5
  • 20

1 Answers1

3

this margin is coming from startIcon class from material-ui itself. To remove this pass a class in to the startIcon in classes prop.

<Button
    style={{ maxWidth: "36px", minWidth: "36px" }}
    classes={{ startIcon: classes.startICon }}
    variant="outlined"
    startIcon={<Add />}
></Button>

And add the class in the useStyles to remove the margin.

const useStyles = makeStyles((theme) => ({
  startICon: {
    margin: 0
  }
}));

Here is the working demo:
Edit eloquent-shirley-pyt07

Rajiv
  • 3,346
  • 2
  • 12
  • 27