0

My MainView extends of an AppLayout. I want to fill the Navbar with a logo on the left side of it and the user id on the right side of the Navbar. Unfortunately everything I tried ends with both Components bound to the left side.

Navbar goal:

| Image -------------------------------------------------------------------------------------------------------- UserID |

Example code (same outcome with Vaadin 14 Image and a String):

public class MainView extends AppLayout
...

private void setupNavigationBar() {
    Div a = new Div();
    a.setText("Foo");
    a.getStyle().set("flex-flow", "flex-start");

    Div b = new Div();
    b.setText("Bar");
    b.getStyle().set("flex-flow", "flex-end");
    addToNavbar(a, b);
}

Navbar outcome:

| FooBar ------------------------------------------------------------------------------------------------------------------ |

What is the issue here? Why does the flex-flow not work? I already tried to wrap it in a HorizontalLayout which also does not work.

Michael Kemmerzell
  • 4,802
  • 4
  • 27
  • 43

1 Answers1

4

I have found a similar case here How to align flexbox columns left and right?and solution seems to work for me like you describe:


@Route("custom-appLayout")
public class CustomAppLayout extends AppLayout {
    public CustomAppLayout(){
            Image img = new Image("https://i.imgur.com/GPpnszs.png", "Vaadin Logo");
            img.setHeight("44px");
            addToNavbar(new DrawerToggle(), img);
            Tabs tabs = new Tabs(new Tab("Home"), new Tab("About"));
            tabs.setOrientation(Tabs.Orientation.VERTICAL);
            addToDrawer(tabs);
            addToNavbar(img);

            Div b = new Div();
            b.setText("Bar");
            b.getStyle().set("margin-left", "auto");
            b.getStyle().set("padding", "15px");
            addToNavbar(b);
    }
}

I've added a padding, since otherwise Bar is too close to the end, but you could set any value you want there. And this is how it looks like: enter image description here

Links I've used:

anasmi
  • 2,562
  • 1
  • 13
  • 25