Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add multiple elements to Material-UI's AppBar component?

Tags:

I want to have multiple FlatButton components in the Material-UI AppBar and preserve the style, so it looks like this (with multiple buttons).

However, when I try to add multiple FlatButton components, I get an error saying I need to wrap them in an enclosing tag. I've used both a span and a div with the same bad results.

enter image description here

Is there a way to either preserve the AppBar's style in the enclosing tag or a different way to add multiple elements to the AppBar itself to get the desired effect?

like image 1000
Joe Martella Avatar asked Aug 13 '15 04:08

Joe Martella


People also ask

What is AppBar in react JS?

Often referred to as a NavBar, the AppBar will help you include page title, logo and navigation items to offer sleek, customizable app navigation. Part of the KendoReact library along with 100+ professional UI components built with React for React, from the ground up.


1 Answers

The iconRightElement must be a single element, so you just need to wrap your buttons in a div like this:

render() {
  const buttonStyle = {
    backgroundColor: 'transparent',
    color: 'white'
  };

  const rightButtons = (
    <div>
      <FlatButton label="About" style={buttonStyle} />
      <FlatButton label="Home" style={buttonStyle} />
    </div>
  );

  return (
    <AppBar title="React seed" iconRightElement={rightButtons} />
  );
}
like image 89
Branon Barrett Avatar answered Oct 21 '22 10:10

Branon Barrett