Docs

Documentation versions (currently viewingVaadin 14)

You are viewing documentation for an older Vaadin version. View latest documentation

Split Layout

Split Layout is a component with two content areas and a draggable split handle between them.

Open in a
new tab
MasterContent master = new MasterContent();
DetailContent detail = new DetailContent();

SplitLayout splitLayout = new SplitLayout(master, detail);

Orientation

The default orientation is horizontal, placing the content areas side by side. The orientation can also be vertical.

Orientation should be set based on the content and the screen size. The user can also be allowed to choose which orientation they wish to use.

Open in a
new tab
MasterContent master = new MasterContent();
DetailContent detail = new DetailContent();

SplitLayout splitLayout = new SplitLayout(master, detail);
splitLayout.setOrientation(SplitLayout.Orientation.VERTICAL);

Splitter Position

The initial splitter position is determined by the default size of the two content area components. Their height and width affect the position when using a vertical and horizontal orientation, respectively.

The initial split position can also be explicitly set using a percentage value. When using vertical orientation, the split layout must have an explicit height for this to work. This can either be an absolute or percentage value. When using a percentage value, ensure that ancestors have an explicit height as well.

Open in a
new tab
MasterContent master = new MasterContent();
DetailContent detail = new DetailContent();

SplitLayout splitLayout = new SplitLayout(master, detail);
// Sets the width for the first child to 70%, giving
// the second child the remaining width of 30%
splitLayout.setSplitterPosition(70);

The splitter respects the minimum and maximum size of the content area components.

Open in a
new tab
MasterContent master = new MasterContent();
master.setMinWidth("200px");
master.setMaxWidth("400px");

DetailContent detail = new DetailContent();

SplitLayout splitLayout = new SplitLayout(master, detail);

The split can be adjusted programmatically, for example, by using a Button. This is useful when the user wants to toggle between certain positions.

Open in a
new tab
button = new Button();
leftArrowIcon = VaadinIcon.ARROW_LEFT.create();
rightArrowIcon = VaadinIcon.ARROW_RIGHT.create();
Div masterContainer = new Div();
DetailContent detailContent = new DetailContent();
MasterContent masterContent = new MasterContent();

sidebarCollapsed = false;

button.addClickListener(event -> {
    sidebarCollapsed = !sidebarCollapsed;
    updateSidebar();
});
button.getElement().setAttribute("aria-label", "Expand/collapse sidebar");
button.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
button.getStyle().set("float", "right");

masterContainer.add(button, masterContent);
masterContainer.getStyle().set("overflow", "hidden");

splitLayout = new SplitLayout(masterContainer, detailContent);

updateSidebar();

...

private void updateSidebar() {
    button.setIcon(sidebarCollapsed ? rightArrowIcon : leftArrowIcon);
    splitLayout.setSplitterPosition(sidebarCollapsed ? 13 : 40);
}

Theme Variants

Split Layout has two theme variants: small and minimal.

Open in a
new tab
MasterContent master = new MasterContent();
DetailContent detail = new DetailContent();

SplitLayout splitLayout = new SplitLayout(master, detail);
splitLayout.addThemeVariants(SplitLayoutVariant.LUMO_SMALL);

The small theme variant makes the divider smaller. The minimal theme variant hides the visual divider. Both variants only show the split handle on hover and are not ideal for touch devices.

Open in a
new tab
MasterContent master = new MasterContent();
DetailContent detail = new DetailContent();

SplitLayout splitLayout = new SplitLayout(master, detail);
splitLayout.addThemeVariants(SplitLayoutVariant.LUMO_MINIMAL);

When using the minimal theme variant, it is recommended to somehow suggest the split between the two sides, for example by styling one side as a layer on top of the other.

While these variants reduce the visual clutter, they make it less obvious to the user that the content is resizable.

Best Practices

  • Don’t use Split Layout when either content area has, or should have, a fixed size.

  • Split Layouts can be difficult to use in responsive applications due to the splitter position being percentage based and thus the content scales with the viewport.

  • Use Split Layout to give the user the ability to adjust the layout. However, if the only distinct positions such as collapsed and expanded are useful to the user, use a toggle button instead. Non-adjustable layouts should use Ordered Layouts or Flex Layout.

A83EE03A-424D-4FB1-83E1-D185DB682DB8