Categories
React Answers

How to create button with text under the icon with React Material UI?

Spread the love

Sometimes, we want to create button with text under the icon with React Material UI.

In this article, we’ll look at how to create button with text under the icon with React Material UI.

How to create button with text under the icon with React Material UI?

To create button with text under the icon with React Material UI, we can set the flexDirection of the button container.

For instance, we write:

import React from "react";
import Button from "@material-ui/core/Button";
import Settings from "@material-ui/icons/Settings";
import { makeStyles } from "@material-ui/core/styles";

const useStyles = makeStyles(() => ({
  button: {
    height: 95
  },
  label: {
    flexDirection: "column"
  }
}));

export default function App() {
  const classes = useStyles();

  return (
    <div>
      <Button
        classes={{ root: classes.button, label: classes.label }}
        variant="raised"
        color="primary"
        disableRipple={true}
      >
        <Settings className={classes.icon} />
        Message
      </Button>
    </div>
  );
}

We call makeStyles with a function that has the label class property that sets flexDirection to 'column'.

Then we set that as the returned classes as the value of the classes prop.

As a result, we should see that ‘Message’ is below the settings icon.

Conclusion

To create button with text under the icon with React Material UI, we can set the flexDirection of the button container.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

2 replies on “How to create button with text under the icon with React Material UI?”

hi thanks for the tip – cool thing but would be great if you would write the mui-version you’ve used

In latest mui this will do.
<Button sx = {{flexDirection: ‘column’, m:1, p:1, fontSize: 9}}

Leave a Reply

Your email address will not be published. Required fields are marked *