Master-Detail Layout
- Setting Sizes
- Overlay Size
- Forced Overlay Mode
- Overlay Containment Modes
- Orientation
- Detail Placeholder
- Hiding the Detail Area
- Router Integration
- Nesting Layouts
- Related Components
Master-Detail Layout is component for building UIs with a horizontally or vertically split pair consisting of a master area and a detail area that can responsively switch to an overlay.
|
Note
|
Preview Feature
This is a preview version of Master-Detail Layout. You need to enable it with the feature flag |
|
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.
|
In the example below, clicking a row in the table reveals the detail area which is rendered next to the master area by default. Drag the splitter to change the width of the layout: the detail area switches to an overlay when the combined master and detail sizes exceed the available space.
Source code
MasterDetailLayoutBasic.java
PersonList.java
PersonList.java
PersonDetail.java
PersonDetail.java
master-detail-layout-basic.tsx
PersonList.tsx
PersonList.tsx
PersonDetail.tsx
PersonDetail.tsx
Setting Sizes
The masterSize and detailSize properties define sizes for each area. When the combined master and detail sizes exceed the available space, the detail area switches to an overlay.
Source code
Java
layout.setMasterSize("600px");
layout.setDetailSize("300px");Java
tsx
tsx
The default masterSize is 30rem. If detailSize is not set, it is automatically determined based on the detail content’s minimum width and cached until new detail content is set.
|
Note
|
In earlier versions, setMasterMinSize and setDetailMinSize were used to set minimum sizes for each area. These have been replaced by the expanding area API described below.
|
Expanding Area
By default, the master area expands to fill any available space beyond the specified sizes. This can be changed so that the detail area expands instead, or both areas expand proportionally.
Source code
Java
// Detail area expands to fill remaining space
layout.setMasterSize("300px");
layout.setDetailSize("400px");
layout.setExpandingArea(MasterDetailLayout.ExpandingArea.DETAIL);
// Both areas expand proportionally
layout.setExpandingArea(MasterDetailLayout.ExpandingArea.BOTH);Java
tsx
tsx
Overlay Size
By default, the detail overlay uses the detail size. The overlay size can be customized separately using overlaySize. For example, setting it to 100% makes the detail overlay cover the full layout.
|
Note
|
In earlier versions, the same effect was achieved using setOverlayMode(OverlayMode) (Flow) / stackOverlay (React), which has been replaced by overlaySize.
|
Source code
Java
layout.setOverlaySize("100%");Java
tsx
tsx
Forced Overlay Mode
The layout can be configured to always render the detail area as an overlay by setting masterSize to 100%. This causes the combined sizes to always exceed the available space, triggering overlay mode regardless of the layout width.
Source code
Java
layout.setMasterSize("100%");Java
tsx
tsx
|
Note
|
In earlier versions, setForceOverlay(boolean) (Flow) and forceOverlay (React) were used to always render the detail area as an overlay. This API has been removed.
|
Overlay Containment Modes
The overlay can be configured to render in two different ways, called containment modes:
-
Layout: The overlay only covers the master area (default);
-
Viewport: The overlay covers the entire viewport (i.e. page).
Source code
Java
layout.setOverlayContainment(MasterDetailLayout.OverlayContainment.VIEWPORT);Java
tsx
tsx
|
Note
|
Limited Modality with Viewport-Containment
Due to browser support constraints, the modality of the detail overlay in viewport containment mode is currently limited to pointer interactions. Elements behind the overlay can be focused by keyboard.
|
Orientation
By default, the Master-Detail Layout is split horizontally. This can be changed to a vertical split.
Source code
MasterDetailLayoutVertical.java
PersonList.java
PersonList.java
PersonDetail.java
PersonDetail.java
master-detail-layout-vertical.tsx
PersonList.tsx
PersonList.tsx
PersonDetail.tsx
PersonDetail.tsx
Detail Placeholder
A placeholder component can be shown in the detail area when no detail content is set. Unlike detail content, the placeholder simply hides when it doesn’t fit rather than being rendered as an overlay.
Source code
Java
layout.setDetailPlaceholder(new Span("Select an item to see details"));Java
tsx
tsx
Hiding the Detail Area
The detail area is automatically shown or hidden when content is added or removed from it. There is no explicit property to control the visibility of the detail area.
Master-Detail Layout exposes the following events that can be used to hide the detail area by removing the content from it:
-
backdrop-click: Fired when the user clicks on the backdrop of the detail overlay when it is in drawer mode. -
detail-escape-press: Fired when the user presses Escape within the detail area.
Source code
Java
layout.addBackdropClickListener(event -> {
// Hide the detail area by removing the content
layout.setDetail(null);
});
layout.addDetailEscapePressListener(event -> {
// Hide the detail area by removing the content
layout.setDetail(null);
});Java
tsx
tsx
Router Integration
Master-Detail Layout can be used as a router layout (see Flow/Hilla), so that nested views are automatically rendered in the details area of the component. This allows showing nested views without having to manage the contents of the details area manually when the route changes, while providing the same benefits such as responsive behavior that the component normally provides.
The Flow MasterDetailLayout component implements the RouterLayout interface. When using a view class that extends from MasterDetailLayout as a layout for a nested view, that view is then automatically shown in the details area of the component.
The example below shows how to set up a master and a detail view. The master view is ProductListView, which would show a list of products, and the detail view is ProductDetailView, which shows information about a specific product. The ProductListView extends from MasterDetailLayout, so that it can be used as a route layout by the detail view. It also configures a @Route so that it can be navigated to by itself. Assuming there is a main layout for the application, for example one using AppLayout, it configures that as a parent layout. The ProductDetailView configures a @Route, using the ProductListView as the route layout.
With this setup, when navigating to /products, the layout would only show the product list. When navigating to a product detail, for example /products/1, it would then also show the product details next to, or on top of, the product list.
Source code
Java
@ParentLayout(MainLayout.class)
@Route(value = "products", layout = MainLayout.class)
public class ProductListView extends MasterDetailLayout { ... }
@Route(value = "products/:productId", layout = ProductListView.class)
public class ProductDetailView extends VerticalLayout { ... }Java
tsx
tsx
Nesting Layouts
Master-Detail Layouts can be nested inside each other to enable multi-level navigation.
When nesting, it may help to omit the detailSize property to let layouts automatically calculate detail sizes based on their content’s minimum size. In this case, each nested detail pushes its minimum size up to its ancestors, so when space gets tight, the outermost levels collapse into overlays first, keeping the levels closest to the user fully visible as long as possible.
In contrast, with explicitly set sizes, the order is reversed: collapsing starts from the innermost levels, keeping the outermost ones open instead, which might cause the user to lose some context.