Details
Details is an expandable panel for showing and hiding content from the user, to make the UI less cluttered.
Anatomy
Details consist of a summary area and a content area.
Summary
The Summary is the part that’s always visible, and typically describes the content, for example with a title. Clicking on the summary toggles the content area’s visibility.
The summary supports rich content and can contain any component. This can be used, for example, to display the status of the corresponding content.
Source code
DetailsSummary.java
details-summary.tsx
details-summary.ts
Country.ts
Country.ts
Content
This is the collapsible part of Details. It can contain any component. When the content area is collapsed, the content is invisible and inaccessible by keyboard or screen reader.
Lazy Content Flow
Content added to a collapsed Details is created and sent to the browser even if the user never expands it. When the content is expensive to build — for example, when it loads data from a backend — create it the first time the Details is opened, using an opened change listener:
Source code
Java
Details details = new Details("Order History");
details.addOpenedChangeListener(event -> {
if (event.isOpened() && details.getContent().findAny().isEmpty()) {
details.add(createOrderHistory());
}
});The content check ensures that the content is created only once. After that, it stays in place when the Details is collapsed and expanded again.
Best Practices
Use Details to group related content and to reduce the chance of overwhelming the user with information. However, avoid putting important information in a Details component unless it’s expanded by default. Otherwise, the user might not notice it.
Details can be used instead of Accordion if there’s a need to see content from multiple collapsible content areas, simultaneously.
The expandable and collapsible nature of Details can sometimes be difficult for users to discover. Use the filled variant and apply a tooltips to make this more discoverable.