Skip to content
GitHub11 stars

A set of collapsible panels with headings.

<AccordionRoot class="accordion">
    <AccordionItem class="accordion-item">
        <AccordionHeader class="accordion-header">

Anatomy

Import the primitives and assemble the parts:

@using Blazix.Primitives

<AccordionRoot>
    <AccordionItem>
        <AccordionHeader>
            <AccordionTrigger />
        </AccordionHeader>
        <AccordionPanel />
    </AccordionItem>
</AccordionRoot>

Examples

Open multiple panels

You can set up the accordion to allow multiple panels to be open at the same time using the Multiple parameter.

<AccordionRoot Multiple="true" class="accordion">
    <AccordionItem class="accordion-item">
        <AccordionHeader class="accordion-header">

Hidden until found

The HiddenUntilFound parameter hides closed panels with hidden="until-found" so the browser can search their contents and reveal the matching panel automatically. It can be set on each AccordionPanel, or once on AccordionRoot to apply to all panels.

To try it, press Ctrl+F (Cmd+F on macOS) and search for "restocking": the browser opens the closed panel containing the match. When HiddenUntilFound is enabled, closed panels always remain mounted in the DOM, which also makes their contents indexable by search engines.

Older browsers that don't support hidden="until-found" keep panels hidden until their trigger opens them, and find-in-page skips over the contents.

<AccordionRoot HiddenUntilFound="true" class="accordion">
    <AccordionItem class="accordion-item">
        <AccordionHeader class="accordion-header">

API Reference

AccordionRoot

Renders a <div> element.

ParameterTypeDefault
Value IReadOnlyList<string>? -
ValueChanged

Called with the new value when Value changes, for @bind-Value.

EventCallback<IReadOnlyList<string>?> -
OnValueChange

Runs before the value changes, with the reason; call Cancel() to keep it.

EventCallback<ValueChangeEventArgs<IReadOnlyList<string>>> -
Disabled

Whether the component should ignore user interaction.

bool false
Multiple bool false
Orientation

Which way the parts are laid out, and which arrow keys move between them.

Orientation Orientation.Vertical
LoopFocus bool true
KeepMounted bool false
HiddenUntilFound bool false
Render RenderFragment<AccordionRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-orientation

Indicates the orientation of the accordion.

'horizontal' | 'vertical'
data-disabled

Present when the accordion is disabled.

-

AccordionItem

Renders a <div> element.

ParameterTypeDefault
Value string? -
Disabled

Whether the component should ignore user interaction.

bool false
OnOpenChange EventCallback<OpenChangeEventArgs> -
Render RenderFragment<AccordionItemRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the accordion item is open.

-
data-disabled

Present when the accordion item is disabled.

-
data-index

Indicates the index of the accordion item.

number

AccordionHeader

Renders a <h3> element.

ParameterTypeDefault
Render RenderFragment<AccordionItemRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the accordion item is open.

-
data-disabled

Present when the accordion item is disabled.

-
data-index

Indicates the index of the accordion item.

number

AccordionTrigger

Renders a <button> element.

ParameterTypeDefault
NativeButton bool? -
Render RenderFragment<AccordionItemRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-panel-open

Present when the accordion panel is open.

-
data-disabled

Present when the accordion item is disabled.

-
data-index

Indicates the index of the accordion item.

number

AccordionPanel

Renders a <div> element.

ParameterTypeDefault
KeepMounted bool false
HiddenUntilFound bool? -
Render RenderFragment<AccordionPanelRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the accordion panel is open.

-
data-orientation

Indicates the orientation of the accordion.

'horizontal' | 'vertical'
data-disabled

Present when the accordion item is disabled.

-
data-index

Indicates the index of the accordion item.

number
data-starting-style

Present when the panel begins animating in.

-
data-ending-style

Present when the panel is animating out.

-
CSS variableType
--accordion-panel-height

The accordion panel's height.

number