Skip to content
Navigation Accordion

Accordion

Stacked headings that reveal their section.

On this page

Examples

Accordion

Interactive Server, WebAssembly and Auto, plus static server rendering.

Razor
<div class="w-full max-w-lg">
    <KlyAccordion Items="Items" Value="@(["render-modes"])" />
</div>

@code {
    private static readonly KlyAccordionItem[] Items =
    [
        new("Which render modes are supported?") { Value = "render-modes", Content = @<p>Interactive Server, WebAssembly and Auto, plus static server rendering.</p> },
        new("Do I need Tailwind?") { Value = "tailwind", Content = @<p>No. Without it, load klyroo.css and theme with CSS variables.</p> },
        new("Is it accessible?") { Value = "a11y", Content = @<p>Components follow the WAI-ARIA authoring practices and are tested with axe.</p> },
    ];
}

With controls inside

Light
Dark
System

Razor
@* Components inside a panel keep their own behavior: opening the menu does not collapse the item. *@
<div class="w-full max-w-lg">
    <KlyAccordion Items="Items" Value="@(["settings"])" />
</div>

@code {
    private static readonly KlySelectItem[] Themes = [new("light", "Light"), new("dark", "Dark"), new("system", "System")];

    private static readonly KlyAccordionItem[] Items =
    [
        new("Settings") { Value = "settings", Content = @<KlyFormField Label="Theme"><KlySelect Items="Themes" Placeholder="Pick a theme" /></KlyFormField> },
        new("Danger zone") { Value = "danger", Content = @<p>Delete your account.</p> },
    ];
}

Text and DefaultOpen

An item takes a Text instead of content, and DefaultOpen opens it first (the first such item only, without Multiple).

Klyroo.Display.Core ships with IsAotCompatible=true and zero UI dependencies.

Razor
<div class="w-full max-w-xl">
    <KlyAccordion Items="@(new[]
    {
        new KlyAccordionItem("NativeAOT support") { Text = "Klyroo.Display.Core ships with IsAotCompatible=true and zero UI dependencies.", DefaultOpen = true },
        new KlyAccordionItem("Secret masking") { Text = "KlySecretBlock masks all but the last characters until the user reveals them." },
    })" />
</div>

API

KlyAccordion

Accordion of collapsible items. One or several items can be open at once, and the state lives in the browser, so it works in every render mode.

Parameters

Name Type Default Description
Class string Classes added to the root element, merged last so they win over the theme.
Collapsible bool true With a single open item, it can be closed too.
HeadingLevel int 3 Heading level of the item headers, to fit the page outline.
Items (required) IReadOnlyList<KlyAccordionItem> The items of the accordion ( KlyAccordionItem ): a label and a content each, with an optional icon and value.
Multiple bool false Several items can be open at once.
Ui AccordionUi Per-instance class overrides of the slots of the accordion, see AccordionUi . They are merged after the theme and the Class parameter wins on the root slot.
Value (@bind-Value) IReadOnlyList<string> Values of the open items.

Ui slots

Ui takes a AccordionUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyAccordion , after the theme and the app configuration.
Item Classes merged into the item slot of KlyAccordion , after the theme and the app configuration.
Header Classes merged into the header slot of KlyAccordion , after the theme and the app configuration.
Trigger Classes merged into the trigger slot of KlyAccordion , after the theme and the app configuration.
LeadingIcon Classes merged into the leadingIcon slot of KlyAccordion , after the theme and the app configuration.
Label Classes merged into the label slot of KlyAccordion , after the theme and the app configuration.
TrailingIcon Classes merged into the trailingIcon slot of KlyAccordion , after the theme and the app configuration.
Content Classes merged into the content slot of KlyAccordion , after the theme and the app configuration.
Body Classes merged into the body slot of KlyAccordion , after the theme and the app configuration.