I would like to center text in a Material-UI button so that the text is centered irrespective of the icon next to it. At the moment the icon is included in the centering.
The top two buttons in the demo show how it currently looks, I am looking for the text to appear as it does in the bottom two buttons. With the icons before and after these buttons respectively, without influencing the text of the buttons.
https://codesandbox.io/s/material-demo-forked-tj8ko?file=/demo.js
import React from "react";
import Button from "@material-ui/core/Button";
import { makeStyles } from "@material-ui/core/styles";
import KeyboardArrowRightIcon from "@material-ui/icons/KeyboardArrowRight";
import KeyboardArrowLeftIcon from "@material-ui/icons/KeyboardArrowLeft";
const useStyles = makeStyles((theme) => ({
button: {
width: "100%",
marginBottom: theme.spacing(1),
marginTop: theme.spacing(1)
}
}));
export default function IconLabelButtons() {
const classes = useStyles();
return (
<div>
<Button
variant="contained"
color="secondary"
className={classes.button}
startIcon={<KeyboardArrowLeftIcon />}
>
Back
</Button>
{/* This Button uses a Font Icon, see the installation instructions in the Icon component docs. */}
<Button
variant="contained"
color="primary"
className={classes.button}
endIcon={<KeyboardArrowRightIcon />}
>
Forward
</Button>
<Button variant="contained" color="secondary" className={classes.button}>
Back
</Button>
{/* This Button uses a Font Icon, see the installation instructions in the Icon component docs. */}
<Button variant="contained" color="primary" className={classes.button}>
Forward
</Button>
</div>
);
}