Blazorise Collapse Component
Add expandable sections to your Blazor apps. Use Collapse to reveal or hide content-perfect for menus, filters, FAQs, and additional details.
Overview
The Collapse component provides an accessible way to show and hide content in Blazor applications. It's ideal for progressive disclosure patterns, such as "read more" areas, filter panels, or navigation sections. Pair it with a toggle (like a Button) in the header to control visibility through user interaction or programmatically.
Using collapsible sections helps organize information, keeping the interface clean and easy to navigate. This approach also complements accordions when you need a single collapsible block rather than multiple linked items.
Structure
The Collapse structure is simple and intuitive:
<Collapse>- the root container that manages the expanded or collapsed state.<CollapseHeader>- always visible header; place your toggle control here (commonly aButtonor clickable heading).<CollapseBody>- the collapsible region that holds the main content.
Examples
Basic Example
Click the button to toggle the collapsible content. This example shows the standard header and body structure for collapsible sections.
<Collapse @bind-Visible=""> <CollapseHeader> <Button Color="Color.Primary" Clicked="@(() => visible = !visible)"> Toggle collapse </Button> </CollapseHeader> <CollapseBody> <Card> <CardBody> This is some collapsible content. It can be shown or hidden by clicking the button. </CardBody> </Card> </CollapseBody> </Collapse>
@code { bool visible = true; }
Programmatic Example
This example demonstrates programmatic control of the collapse state using a button in the header to toggle visibility.
<Collapse @ref=""> <CollapseHeader> <Button Color="Color.Primary" Clicked="@collapseRef.Toggle"> Toggle collapse </Button> </CollapseHeader> <CollapseBody> <Card> <CardBody> This is some collapsible content. It can be shown or hidden by clicking the button. </CardBody> </Card> </CollapseBody> </Collapse>
@code {
Collapse collapseRef;
}
API
Parameters
Collapse
| Parameter | Description | Type | Default |
|---|---|---|---|
ChildContent |
Specifies the content to be rendered inside this Collapse. |
RenderFragment | null |
Visible |
Gets or sets the collapse visibility state. |
bool | false |
CollapseHeader
| Parameter | Description | Type | Default |
|---|---|---|---|
ChildContent |
Specifies the content to be rendered inside this CollapseHeader. |
RenderFragment | null |
CollapseBody
| Parameter | Description | Type | Default |
|---|---|---|---|
ChildContent |
Specifies the content to be rendered inside this CollapseBody. |
RenderFragment | null |
Events
Collapse
| Event | Description | Type |
|---|---|---|
VisibleChanged |
Occurs when the collapse visibility state changes. |
EventCallback<bool> |
CollapseHeader
| Event | Description | Type |
|---|---|---|
Clicked |
Occurs when the header is clicked. |
EventCallback<MouseEventArgs> |
Methods
Collapse
| Method | Description | Return | Parameters |
|---|---|---|---|
Toggle |
Toggles the collapse visibility state. | Task |