Skip to content
GitHub11 stars

A collapsible panel controlled by a button.

<CollapsibleRoot class="collapsible">
    <CollapsibleTrigger class="collapsible-trigger">
        Recovery keys

Anatomy

Import the primitives and assemble the parts:

@using Blazix.Primitives

<CollapsibleRoot>
    <CollapsibleTrigger />
    <CollapsiblePanel />
</CollapsibleRoot>

Examples

Hidden until found

The HiddenUntilFound parameter hides the closed panel with hidden="until-found", so the browser can search its contents with find-in-page (Ctrl+F, or Cmd+F on macOS) and open the panel when it finds a match. The closed panel always stays in the DOM, which also makes its contents indexable by search engines.

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

<CollapsibleRoot>
    <CollapsibleTrigger>Shipping details</CollapsibleTrigger>
    <CollapsiblePanel HiddenUntilFound="true">Standard shipping takes 3–5 business days.</CollapsiblePanel>
</CollapsibleRoot>

See the Accordion example for an interactive demo.

API Reference

CollapsibleRoot

Renders a <div> element.

ParameterTypeDefault
Open bool false
OpenChanged

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

EventCallback<bool> -
OnOpenChange EventCallback<OpenChangeEventArgs> -
Disabled

Whether the component should ignore user interaction.

bool false
Render RenderFragment<CollapsibleRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the collapsible is open.

-
data-closed

Present when the collapsible is closed.

-
data-starting-style

Present when the collapsible begins animating in.

-
data-ending-style

Present when the collapsible is animating out.

-

CollapsibleTrigger

Renders a <button> element.

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

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-panel-open

Present when the collapsible panel is open.

-

CollapsiblePanel

Renders a <div> element.

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

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the collapsible panel is open.

-
data-closed

Present when the collapsible panel is closed.

-
data-starting-style

Present when the panel begins animating in.

-
data-ending-style

Present when the panel is animating out.

-
CSS variableType
--collapsible-panel-height

The collapsible panel's height.

number