Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set up material-ui AppBar/ToolBar to have a horizontal tab menu layout?

Looking for the way to create a horizontal navigation menu for the web application using material-ui components. I'd like to start with something very similar to the menu at the react documentation website:

react documentation menu

Since it's a quite common menu look, I was searching for the example of such configuration but was unable to found it either at material-ui docs or here at SO (there is a similar solution, but it is not exactly what's needed).

How to do this?

like image 732
Poliakoff Avatar asked Nov 08 '16 20:11

Poliakoff


People also ask

How do you make a navigation bar using material UI?

Create a Drawer. js file in the component folder and in that file, create a DrawerComponent function. Import Drawer from Material UI, then create a function named DrawerComponent which will return a Drawer and a ListItem and this is where we will place the list of items we want in our responsive navigation bar.

Does material UI have a navbar?

Learning about the AppBar and Toolbar components in Material-UI. The navigation bar is one of the first things users see on a website. You can create a beautiful navigation bar easily in React using the component library from Material-UI.

What is the height of AppBar in material UI?

mui-appbar container that automatically adjusts its height based on the viewport dimensions: 48px (phone landscape) 56px (phone portrait) 64px (default)


1 Answers

My solution for this was to place a ToolbarGroup component within AppBar's iconElementRight property.

// Defining a stateless, functional component, MyNavLinks. 
// This component contains your navigation links.

const MyNavLinks = () => (
  <ToolbarGroup>
    <FlatButton label="Dashboard" containerElement={<Link to="dashboard"/>}/>
    <FlatButton label="Settings" containerElement={<Link to="settings" />}/>
    <FlatButton label="Profile" containerElement={<Link to="profile" />}/>
  </ToolbarGroup> 
);


// Another stateless, functional component, MyAppBar. 
// Here we are setting the iconElementRight property of Material UI's AppBar 
// to the component defined above.

const MyAppbar = () => (
    <AppBar
      title="Brand"
      iconElementRight={<MyNavLinks />}
    />
);

Result: Sample Result

like image 86
Farook K Avatar answered Sep 28 '22 10:09

Farook K