Docs

Documentation versions (currently viewingVaadin 24)

App Layout

App Layout is a component for building common application layouts.

App Layout is a component for the root layout of a Vaadin application. It provides predefined areas for the navigation drawer, the header, and the view’s content.

Important
Scaled down examples
The examples on this page are scaled down so that their viewport-size-dependent behavior can be demonstrated. Some examples also change their behavior based on your browser viewport size.
Open in a
new tab
Source code
AppLayoutBasic.java
app-layout-basic.tsx
app-layout-basic.ts

The layout consists of three sections:

An application’s main navigation blocks should be positioned in the navbar or the drawer or both, whereas views are rendered in the content area. App Layout is responsive and adjusts automatically to fit desktop, tablet, and mobile screen sizes.

Usage as Root Layout

App Layout is designed to be the application’s root layout, within which most or all views are rendered. It’s not intended to be nested inside other elements.

Flow

With Flow, the root layout can be defined using the @Layout annotation, which tells the router to render all routes or views inside of it.

Source code
Java
@Layout
public class MainLayout extends AppLayout {

}

Hilla

Files named @layout.tsx define the root layout for the other views defined in the same directory or its subdirectories. A @layout.tsx in the root of the views directory acts as the default root layout for all views in the application. An <Outlet/> element is used to tell the router where to render the contents of routes or views.

Source code
@layout.tsx
export default function MainLayout() {
  return (
    <AppLayout>
      <Outlet />
    </AppLayout>
  );
}

See Hilla routing documentation for details.

Content Area

The content area is where individual views are rendered. The route layout mechanisms in Flow and Hilla can automatically render the contents of routes and views there, but it can be invoked manually:

Source code
Java
public class MainLayout extends AppLayout {
  public MainLayout() {
    MyView view = new MyView();
    setContent(view);
  }
}
Java
tsx
tsx
HTML
HTML

The navbar is a header above the content area. It can contain primary or secondary navigation elements, the application’s title, or view-specific content such as the title of the current view.

Source code
Java
@Layout
public class MainLayout extends AppLayout {
  public MainLayout() {
    H1 title = new H1("My App");
    addToNavbar(title);
  }
}
Java
tsx
tsx
HTML
HTML

The navbar can be located on top, or to the side of the drawer. When put it on top, the navbar is typically used as an application header. Application headers contain, for example, the application’s name and branding, as well as actions that apply to the entire application (e.g., notifications, settings, etc.).

Open in a
new tab
Source code
AppLayoutNavbarPlacement.java
app-layout-navbar-placement.tsx
app-layout-navbar-placement.ts

When placed to the side, the navbar is often seen as a view header, containing the view’s title, as well as actions and secondary navigation that relate only to the current view.

Open in a
new tab
Source code
AppLayoutNavbarPlacementSide.java
app-layout-navbar-placement-side.tsx
app-layout-navbar-placement-side.ts

Drawer

The drawer can switch between a fixed area next to the view’s content and an expandable panel, toggled via the drawer toggle. It typically contains the application’s primary navigation, such as a Side Navigation component.

Source code
Java
@Layout
public class MainLayout extends AppLayout {
  public MainLayout() {
    SideNav nav = new SideNav();
    addToDrawer(nav);
  }
}
Java
tsx
tsx
HTML
HTML

Drawer Toggle

Show and hide the drawer using a Drawer Toggle or a Button. The Drawer Toggle, which is represented by the hamburger icon (i.e., ☰), should always be accessible — unless the drawer is empty. It’s usually situated in the navbar.

Scrolling Behavior

Depending on whether App Layout has a defined height, the way the content inside the layout scrolls can differ.

Auto Height

When the App Layout has an undefined or auto height set, which is the default, the <body> element is the scrolling container for the content inside the layout.

Open in a
new tab
Source code
AppLayoutHeightAuto.java
app-layout-height-auto.tsx
app-layout-height-auto.ts

The vertical scrollbar crosses the App Layout navbar and the content flows under it, allowing for translucent visual styles. Mobile browsers collapse and expand their toolbars when the user scrolls down and up, respectively. On iOS, you can tap the status bar (i.e., where signal strength, battery, and clock are indicated) to scroll back to the top of the page or view.

This behavior isn’t compatible with vertically scrollable Grids, or other scrolling containers within the content area that’s height is 100%. To support those, define 100% height for the App Layout.

Full Height (100%)

To allow a nested component to take all of the available vertical space inside the App Layout, you need to set an explicit height for the layout, typically 100%. A common use case is to let a data grid fill the entire content area.

Note
Make sure all parent components and elements have 100% height. The full hierarchy of components from the App Layout to the <body> element need to have 100% height.
Open in a
new tab
Source code
AppLayoutHeightFull.java
app-layout-height-full.tsx
app-layout-height-full.ts

The vertical scrollbar stays within the layout content area, and mobile browsers don’t collapse their toolbars when the content area is scrolled down.

Bottom Navbar on Small Touchscreens

When the navbar is used for navigation, the touch-optimized navbar slot can be used to provide a separate version of the navigation at the bottom of the UI, optimized for mobile phones.

Open in a
new tab
Source code
AppLayoutBottomNavbar.java
app-layout-bottom-navbar.tsx
app-layout-bottom-navbar.ts

Best Practices

Choose between navbar and drawer based primarily on the number of items placed in it. The navbar is a good choice for a small number of items (i.e., three to five), as they can fit into the viewport without scrolling.

Open in a
new tab
Source code
AppLayoutNavbar.java
app-layout-navbar.tsx
app-layout-navbar.ts

When more items need to be displayed, or if small-screen support is a priority, the drawer is a better choice. It can accommodate a longer list of links without scrolling, and collapses into a hamburger menu on small screens. Furthermore, a vertical list of items is easier for the user to scan.

Open in a
new tab
Source code
AppLayoutDrawer.java
app-layout-drawer.tsx
app-layout-drawer.ts

For applications that require multilevel or hierarchical navigation, use the drawer to contain at least the first level. The secondary and tertiary navigation items can be placed in either the drawer or the navbar.

Open in a
new tab
Source code
AppLayoutSecondaryNavigation.java
app-layout-secondary-navigation.tsx
app-layout-secondary-navigation.ts

3005EA19-8E28-4BF2-8A0A-FC3F46C04F1B

OSZAR »