Composition
This component is a composition of 2 key components:
- LumexAccordion: The container that holds collapsible sections.
- LumexAccordionItem: The individual collapsible section within the accordion.
Usage
<LumexAccordion>
<LumexAccordionItem Id="1" Title="Accordion 1">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2">
<TitleContent>
<span>
Accordion <strong>#2</strong>
</span>
</TitleContent>
<ChildContent>
@_content
</ChildContent>
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Accordion 3">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
Disabled
Use the Disabled
parameter to disable the accordion.
<LumexAccordion Disabled="@true">
<LumexAccordionItem Id="1" Title="Accordion 1">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Accordion 2">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Accordion 3">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
Alternatively, use the DisabledItems
parameter to disable specific accordion items.
<LumexAccordion DisabledItems="@(["2"])">
<LumexAccordionItem Id="1" Title="Accordion 1">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Accordion 2">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Accordion 3">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
Expanded
Use the Expanded
parameter to make the accordion expanded.
<LumexAccordion Expanded="@true">
<LumexAccordionItem Id="1" Title="Accordion 1">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Accordion 2">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Accordion 3">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
Alternatively, use ExpandedItems
parameter to expand specific accordion items.
<LumexAccordion ExpandedItems="@(["2"])">
<LumexAccordionItem Id="1" Title="Accordion 1">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Accordion 2">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Accordion 3">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
Multiple
By default, only one accordion item can be expanded at a time.
Use the SelectionMode
parameter to control the selection behaviour of the accordion.
<LumexAccordion SelectionMode="@SelectionMode.Multiple">
<LumexAccordionItem Id="1" Title="Accordion 1">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Accordion 2">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Accordion 3">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
Variants
Use the Variant
parameter to set different visual styles of the accordion,
such as Light
, Shadow
, Bordered
or Splitted
.
<LumexAccordion Variant="@AccordionVariant.Light">
<LumexAccordionItem Id="1" Title="Accordion 1">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Accordion 2">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Accordion 3">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
<LumexAccordion Variant="@AccordionVariant.Shadow">
<LumexAccordionItem Id="1" Title="Accordion 1">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Accordion 2">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Accordion 3">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
<LumexAccordion Variant="@AccordionVariant.Bordered">
<LumexAccordionItem Id="1" Title="Accordion 1">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Accordion 2">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Accordion 3">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
<LumexAccordion Variant="@AccordionVariant.Splitted">
<LumexAccordionItem Id="1" Title="Accordion 1">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Accordion 2">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Accordion 3">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
Subtitle
Use the Subtitle
or SubtitleContent
parameters to
provide additional context for accordion items.
<LumexAccordion>
<LumexAccordionItem Id="1"
Title="Accordion 1"
Subtitle="Press to expand">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Accordion 2">
<SubtitleContent>
<span>
Press to expand <strong>item 2</strong>
</span>
</SubtitleContent>
<ChildContent>
@_content
</ChildContent>
</LumexAccordionItem>
<LumexAccordionItem Id="3"
Title="Accordion 3"
Subtitle="Press to expand">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
Start content
Use the StartContent
parameter to
insert additional content at the beginning of accordion items.
<LumexAccordion>
<LumexAccordionItem Id="1"
Title="Ross Geller"
Subtitle="4 unread messages">
<StartContent>
<LumexAvatar Bordered="@true"
Radius="@Radius.Large"
Color="@ThemeColor.Primary"
Src="https://i.pravatar.cc/150?img=6" />
</StartContent>
<ChildContent>@_content</ChildContent>
</LumexAccordionItem>
<LumexAccordionItem Id="2"
Title="Sheldon Cooper"
Subtitle="3 incompleted steps">
<StartContent>
<LumexAvatar Bordered="@true"
Radius="@Radius.Large"
Color="@ThemeColor.Success"
Src="https://i.pravatar.cc/150?img=11" />
</StartContent>
<ChildContent>@_content</ChildContent>
</LumexAccordionItem>
<LumexAccordionItem Id="3"
Title="Bruce Wayne">
<SubtitleContent>
<p class="flex">
2 issues to<span class="text-primary ml-1">fix now</span>
</p>
</SubtitleContent>
<StartContent>
<LumexAvatar Bordered="@true"
Radius="@Radius.Large"
Color="@ThemeColor.Secondary"
Src="https://i.pravatar.cc/150?img=12" />
</StartContent>
<ChildContent>@_content</ChildContent>
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content = @<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
Custom indicator
Use the IndicatorContent
parameter to
customize the default indicator icon of accordion items.
@using LumexUI.Shared.Icons
<LumexAccordion>
<LumexAccordionItem Id="1" Title="Anchor">
<ChildContent>@_content</ChildContent>
<IndicatorContent>
<LinkIcon />
</IndicatorContent>
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Moon">
<ChildContent>@_content</ChildContent>
<IndicatorContent>
<MoonIcon />
</IndicatorContent>
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Sun">
<ChildContent>@_content</ChildContent>
<IndicatorContent>
<SunIcon />
</IndicatorContent>
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content = @<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
The indicator icon can be controlled based on the expanded state of the accordion item:
@using LumexUI.Shared.Icons
<LumexAccordion>
<LumexAccordionItem Id="1" Title="Theme">
<ChildContent>@_content</ChildContent>
<IndicatorContent Context="expanded">
@(expanded ? @<SunIcon /> : @<MoonIcon />)
</IndicatorContent>
</LumexAccordionItem>
<LumexAccordionItem Id="2" Title="Anchor">
<ChildContent>@_content</ChildContent>
<IndicatorContent>
<LinkIcon />
</IndicatorContent>
</LumexAccordionItem>
<LumexAccordionItem Id="3" Title="Sun">
<ChildContent>@_content</ChildContent>
<IndicatorContent>
<SunIcon />
</IndicatorContent>
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content = @<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
}
Two-way data binding
Use the @bind-Expanded
directive,
or the Expanded
and ExpandedChanged
parameters,
to control the accordion’s expanded state.
<LumexAccordion>
<LumexAccordionItem Id="1"
Title="Accordion 1"
@bind-Expanded="@_itemOneExpanded">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="2"
Title="Accordion 2"
@bind-Expanded="@_itemTwoExpanded">
@_content
</LumexAccordionItem>
<LumexAccordionItem Id="3"
Title="@_itemThreeTitle"
Expanded="@_itemThreeExpanded"
ExpandedChanged="@OnExpandedChanged">
@_content
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content =>
@<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
private bool _itemOneExpanded;
private bool _itemTwoExpanded;
private bool _itemThreeExpanded;
private string _itemThreeTitle = "Accordion 3";
private void OnExpandedChanged( bool expanded )
{
_itemThreeExpanded = expanded;
_itemThreeTitle = expanded ? "I am expanded" : "I am collapsed";
}
}
Custom styles
This component supports named slots, which allow custom styles to be applied to specific parts of the component:
- Base: The overall container of the accordion item.
- Heading: The wrappper of the header section that includes the trigger.
- Trigger: The element that toggles the accordion open or closed.
- TitleWrapper: The wrappper of both the title and subtitle of the accordion item.
- Title: The main title of the accordion item.
- Subtitle: The secondary text beneath the title.
- StartContent: The content, such as icons, placed at the start of the accordion item.
- Indicator: The icon that indicates the accordion item’s expanded or collapsed state.
- Content: The wrappper of the body content of the accordion item.
You can customize the component(s) by passing any Tailwind CSS classes to the following component parameters:
Accordion
Class
: The basic CSS class name styles the wrapper of the accordion items.ItemClasses
: The CSS class names for the accordion items slots style all the accordion items at once.
Accordion Item
Class
: The basic CSS class name styles the wrapper of the accordion item.Classes
: The CSS class names for the accordion item slots style the entire accordion item at once.
@using LumexUI.Shared.Icons
<LumexAccordion Variant="@AccordionVariant.Shadow"
ShowDividers="@false"
Class="p-2 flex flex-col gap-1 max-w-sm"
ItemClasses="@_itemClasses">
<LumexAccordionItem Id="1"
Title="Connected Devices">
<StartContent>
<MonitorSmartphoneIcon class="text-primary" />
</StartContent>
<SubtitleContent>
2 issues to <span class="text-primary">fix now</span>
</SubtitleContent>
<ChildContent>@_content</ChildContent>
</LumexAccordionItem>
<LumexAccordionItem Id="2"
Title="Apps Permissions"
Subtitle="3 apps have read permissions">
<StartContent>
<ShieldAlertIcon />
</StartContent>
<ChildContent>@_content</ChildContent>
</LumexAccordionItem>
<LumexAccordionItem Id="3"
Title="Pending tasks"
Subtitle="Complete your profile"
Classes="@(new() { Subtitle = "text-warning" })">
<StartContent>
<InfoIcon class="text-warning" />
</StartContent>
<ChildContent>@_content</ChildContent>
</LumexAccordionItem>
</LumexAccordion>
@code {
private RenderFragment _content = @<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</text>;
private AccordionItemSlots _itemClasses = new()
{
Title = "font-medium text-medium",
Trigger = "px-2 py-0 hover:bg-default-100 rounded-lg h-14",
Content = "text-small p-2"
};
}
API
See the API references below for a complete guide to all the parameters available for the components mentioned here.