Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display an image on left of Material-UI AppBar, but retain the "hamburger" menu?

I'd like to display an image on the left of a Material-UI AppBar, but keep the "hamburger" menu and have the image just to the right of that.

Is it possible? I can add an image to the left using

<AppBar title="My App"
        iconElementLeft = {<img src='header-logo.png' alt="Logo" />} />;

However, that replaces the "hamburger" menu, which is of no use to me.

I also tried creating an img as a child of the AppBar, but that puts the image to the right of any iconElementRight elements.

like image 552
dommer Avatar asked Nov 06 '16 15:11

dommer


People also ask

How do I use an image as an icon in Materialui?

Right click on the new scaled path in the paths toolbox and select export path. Open the exported file, and copy the path tag inside of the svg tag. Also, remove any other attributes in the path tag except the d attribute.

How do I add a picture to my material toolbar?

Just add a closing tag to your Appbar element (remove the self closing tag) and put the image inside.

How do you customize UI AppBar?

Add a Material-UI dependency and Material-UI icons dependency because we will use an icon on the AppBar . Alright! so now that we have the dependencies, we will remove this boilerplate code and this App component will instead return a div containing AppBar component from Material-UI library.


2 Answers

In material ui 4.3.2, there is no 'title' props for AppBar. So to add a logo try the following method.

<AppBar color="inherit">
    <Toolbar>
        <img src="logo.png" alt="logo" className={classes.logo} />
      </Toolbar>
</AppBar>

Use the css to restrict the logo size. i.e.

const useStyles = makeStyles({
  logo: {
    maxWidth: 160,
  },
});
like image 143
Vikas Kumar Avatar answered Sep 28 '22 06:09

Vikas Kumar


Just pass your tag as the title. Material-ui will take a node as title

Something like

 <AppBar
    title={<img src="https://unsplash.it/40/40"/>}
  />

Working pen

Hope this helps!

like image 40
Pranesh Ravi Avatar answered Sep 28 '22 07:09

Pranesh Ravi