Skip to main content

LgAccordion

LgAccordion groups multiple LgAccordionPane panels and ensures that only one panel remains open at a time. Each pane is a specialized LgFrame, collapsible and closed by default.

<LgAccordion>
<LgAccordionPane Title="Section 1">
Content
</LgAccordionPane>
</LgAccordion>
  • Namespace: Lagoon.UI.Components
  • Inherits from: LgComponentBase
  • NuGet package: Lagoon.UI
Specialized pane

LgAccordionPane inherits from LgFrame, with Collapsable = true and DefaultCollapsed = true. The container also reassigns OnToggle to automatically close the other panels.

Usage​

Demonstration​

Try this component in the Lagoon showcase.

Simple accordion with three panels​

Each LgAccordionPane is an LgFrame that is collapsible and closed by default. The container ensures that only one panel is open at a time.

CustomerDetailsPage.razor
@inherits LgPage

<LgAccordion CssClass="customer-accordion">
<LgAccordionPane Title="#CustomerContactTitle"
IconName="@IconNames.All.People">
<HeaderContent>
<span>@("#CustomerContactHeader".Translate())</span>
</HeaderContent>
<ChildContent>
<p>@_customerContact</p>
</ChildContent>
</LgAccordionPane>

<LgAccordionPane Title="#DeliveryAddressTitle"
Kind="Kind.Secondary">
<ChildContent>
<p>@_deliveryAddress</p>
</ChildContent>
</LgAccordionPane>

<LgAccordionPane Title="#BillingAddressTitle"
Kind="Kind.Default">
<ChildContent>
<p>@_billingAddress</p>
</ChildContent>
</LgAccordionPane>
</LgAccordion>
CustomerDetailsPage.razor.cs
public partial class CustomerDetailsPage : LgPage
{
// Information displayed in the first accordion panel.
private string _customerContact = "Marie Martin — marie.martin@example.test";

// Business address displayed in the delivery panel.
private string _deliveryAddress = "12 rue des Peupliers, 44000 Nantes";

// Business address displayed in the billing panel.
private string _billingAddress = "18 avenue du Port, 44000 Nantes";
}

Enriched panel as a frame​

Since LgAccordionPane inherits from LgFrame, you can reuse Toolbar, SummaryContent, FooterContent, HeaderContent, Kind, IconName, and OnCommand. However, avoid driving OnToggle in a pane contained by LgAccordion: the container uses it to close the other panels.

ContractAccordionPage.razor
@inherits LgPage

<LgAccordion>
<LgAccordionPane Title="#ContractDocumentsTitle"
IconName="@IconNames.All.Folder"
Kind="Kind.Info"
OnCommand="OnDocumentsCommandAsync">
<Toolbar>
<LgToolbarButton Text="#ExportDocuments"
IconName="@IconNames.All.Pdf"
CommandName="export-documents" />
</Toolbar>
<ChildContent>
<p>@("#ContractDocumentsContent".Translate())</p>
</ChildContent>
<SummaryContent>
<p>@("#ContractDocumentsSummary".Translate()) @_documentCount</p>
</SummaryContent>
<FooterContent>
<p>@("#ContractDocumentsFooter".Translate())</p>
</FooterContent>
</LgAccordionPane>

<LgAccordionPane Title="#ContractHistoryTitle"
IconName="@IconNames.All.ClockHistory">
<ChildContent>
<p>@("#ContractHistoryContent".Translate())</p>
</ChildContent>
</LgAccordionPane>
</LgAccordion>
ContractAccordionPage.razor.cs
public partial class ContractAccordionPage : LgPage
{
// Counter displayed in the summary when the documents panel is collapsed.
private int _documentCount = 7;

// Centralizes the commands of the documents panel toolbar.
private Task OnDocumentsCommandAsync(CommandEventArgs args)
{
if (args.CommandName == "export-documents")
{
args.Handled = true;
}

return Task.CompletedTask;
}
}

Points of attention​

  • LgAccordion does not expose a public property to directly select the active panel.
  • Panes are initialized with Collapsable="true" and DefaultCollapsed="true".
  • Frame properties remain available on each pane, but exclusive opening is managed by the container.

Properties​

Properties of LgAccordion​

NameTypeDefaultDeclared inDescription
ChildContentRenderFragmentnullLgAccordionContainer content, usually a list of LgAccordionPane.
CssClassstringnullLgAccordionAdditional CSS classes applied to the accordion container.

Properties of LgAccordionPane​

NameTypeDefaultDeclared inDescription
ChildContentRenderFragmentnullLgFrameMain content of the panel.
FooterContentRenderFragmentnullLgFrameFooter content of the panel.
HeaderContentRenderFragmentnullLgFrameFree content displayed in the panel header.
SummaryContentRenderFragmentnullLgFrameSummary displayed when the panel is collapsed.
TitleContentRenderFragmentnullLgFrameCustom title in markup.
ToolbarRenderFragmentnullLgFrameToolbar rendered in the panel header.
AdditionalAttributesIReadOnlyDictionary<string, object>nullLgFrameAdditional HTML attributes applied to the panel root.
ButtonSizeButtonSize?nullLgFrameSize of toolbar buttons.
ChildCssClassstringnullLgFrameCSS classes applied to the main content.
CollapsablebooltrueLgFrameInherited parameter; the default value is provided by the pane constructor.
CollapsedboolfalseLgFrameCurrent collapsed state. On first render, the pane starts closed via DefaultCollapsed.
CollapsedChangedEventCallback<bool>—LgFrameTwo-way binding callback for Collapsed.
CssClassstringaccordion-itemLgFrameCSS class applied to the pane. LgAccordionPane.OnInitialized sets it to accordion-item.
DefaultCollapsedbool?trueLgFrameInherited parameter; the default value applied to Collapsed is provided by the pane constructor.
HeaderCssClassstringnullLgFrameCSS classes for the pane header.
IconNamestringnullLgFrameIcon displayed in front of the panel title.
KindKindKind.PrimaryLgFrameVisual theme of the pane.
OnCommandEventCallback<CommandEventArgs>—LgFrameReception of commands bubbled from the pane content.
OnToggleEventCallback<ToggleFrameEventArgs>—LgFrameReassigned by LgAccordion to automatically close the other panes.
ShowHeaderbooltrueLgFrameShows or hides the pane header.
TitlestringnullLgFrameText title of the panel.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute.
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute.

Events​

LgAccordion does not expose its own public event. LgAccordionPane adopts the callbacks from LgFrame.

EventTypeDescription
CollapsedChangedEventCallback<bool>Binding callback to track the collapsed state of a pane.
OnCommandEventCallback<CommandEventArgs>Receives commands bubbled by child components of the pane.
OnToggleEventCallback<ToggleFrameEventArgs>Used internally by LgAccordion to enforce exclusive opening of only one pane at a time.

Associated enumerations​

The enumerations below concern parameters inherited from LgFrame exposed by LgAccordionPane.

Kind​

Kind controls the visual theme of the inherited Kind property of the pane. See the complete table in LgFrame (default value: Kind.Primary).

ButtonSize​

ButtonSize controls the inherited ButtonSize property, used to size the toolbar buttons of the pane.

ValueDescription
MediumStandard size.
SmallReduced size (default value of standard Lagoon configuration when ButtonSize remains null).
LargeLarge size.
  • LgFrame — base component from which LgAccordionPane inherits.
  • LgFilterFrame — another specialized frame variant.
  • LgSplitContainer — layout useful for juxtaposing an accordion and a work area.