package com.vaadin.demo.component.splitlayout;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.splitlayout.SplitLayout;
import com.vaadin.flow.router.Route;
@Route("split-layout-orientation")
public class SplitLayoutOrientation extends Div {
public SplitLayoutOrientation() {
// tag::snippet[]
MasterContent master = new MasterContent();
DetailContent detail = new DetailContent();
SplitLayout splitLayout = new SplitLayout(master, detail);
splitLayout.setOrientation(SplitLayout.Orientation.VERTICAL);
// end::snippet[]
splitLayout.setMaxHeight("350px");
add(splitLayout);
}
}
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 be either an absolute or a percentage value.
When using a percentage value, ensure that ancestors have an explicit height as well.
package com.vaadin.demo.component.splitlayout;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.splitlayout.SplitLayout;
import com.vaadin.flow.router.Route;
@Route("split-layout-initial-splitter-position")
public class SplitLayoutInitialSplitterPosition extends Div {
public SplitLayoutInitialSplitterPosition() {
// tag::snippet[]
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);
// end::snippet[]
splitLayout.setMaxHeight("280px");
add(splitLayout);
}
}
The splitter respects the minimum and maximum size of the content area components.
package com.vaadin.demo.component.splitlayout;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.splitlayout.SplitLayout;
import com.vaadin.flow.component.splitlayout.SplitLayoutVariant;
import com.vaadin.flow.router.Route;
@Route("split-layout-theme-variants")
public class SplitLayoutThemeVariants extends Div {
public SplitLayoutThemeVariants() {
// tag::snippet[]
MasterContent master = new MasterContent();
DetailContent detail = new DetailContent();
SplitLayout splitLayout = new SplitLayout(master, detail);
splitLayout.addThemeVariants(SplitLayoutVariant.LUMO_SMALL);
// end::snippet[]
splitLayout.setMaxHeight("280px");
add(splitLayout);
}
}
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 aren’t ideal for touch devices.
package com.vaadin.demo.component.splitlayout;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.splitlayout.SplitLayout;
import com.vaadin.flow.component.splitlayout.SplitLayoutVariant;
import com.vaadin.flow.router.Route;
@Route("split-layout-minimal-theme-variants")
public class SplitLayoutMinimalThemeVariants extends Div {
public SplitLayoutMinimalThemeVariants() {
// tag::snippet[]
MasterContent master = new MasterContent();
DetailContent detail = new DetailContent();
SplitLayout splitLayout = new SplitLayout(master, detail);
splitLayout.addThemeVariants(SplitLayoutVariant.LUMO_MINIMAL);
// end::snippet[]
splitLayout.setMaxHeight("280px");
add(splitLayout);
}
}
When using the minimal theme variant, it’s 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 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, so that the content scales with the viewport.
Use Split Layout to give the user the ability to adjust the layout.
However, if only specific 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.