DwsAccordion
The DwsAccordion component allows you to create collapsible sections of content. Below are examples of different accordion items.
API Reference — DwsAccordion API Reference — DwsAccordionItemBasic Accordion
A single-open-or-none accordion (the default Mode). The headers are headings: HeadingLevel='3' puts them under this section's h2 in the page outline. Each header is a native button inside its heading: Tab reaches it, Enter and Space toggle it, ArrowDown / ArrowUp / Home / End move between the headers.
This is the content of section 1.
This is the content of section 2.
This is the content of section 3.
Show Code
Accordion.razor
<DwsAccordion HeadingLevel="3" Name="Accordion_Sections">
<DwsAccordionItem Name="AccordionItem_Section1" Title="Section 1">
<p>This is the content of section 1.</p>
</DwsAccordionItem>
<DwsAccordionItem Name="AccordionItem_Section2" Title="Section 2">
<p>This is the content of section 2.</p>
</DwsAccordionItem>
<DwsAccordionItem Name="AccordionItem_Section3" Title="Section 3">
<p>This is the content of section 3.</p>
</DwsAccordionItem>
</DwsAccordion>Accordion.razor.cs
// No additional code-behind is required for this example.Open Modes
The Mode parameter: SingleOpen, SingleOpenOrNone, MultipleOpen and MultipleOpenOrNone.
Mode.MultipleOpenOrNone
Every item can be expanded independently, and all may be collapsed.
Try expanding this one alongside the first.
Mode.SingleOpen
Opening this one collapses the first; neither can be collapsed directly.
Mode.SingleOpenOrNone
At most one item is open; opening another collapses this one.
The open item can also be collapsed, leaving none open.
Mode.MultipleOpen
Open this one too - the first stays open.
Show Code
Accordion.razor
<DwsTypography Name="AccordionDemo_Heading1" Typography="DwsTypographyType.Heading6">Mode.MultipleOpenOrNone</DwsTypography>
<DwsAccordion HeadingLevel="3" Name="Accordion_MultipleOpenOrNone" Mode="DwsAccordionMode.MultipleOpenOrNone">
<DwsAccordionItem Name="AccordionItem_Multi1" Title="First item">
<p>Every item can be expanded independently, and all may be collapsed.</p>
</DwsAccordionItem>
<DwsAccordionItem Name="AccordionItem_Multi2" Title="Second item">
<p>Try expanding this one alongside the first.</p>
</DwsAccordionItem>
</DwsAccordion>
<DwsTypography Name="AccordionDemo_Heading2" Typography="DwsTypographyType.Heading6" Class="mt-3">Mode.SingleOpen</DwsTypography>
<DwsAccordion HeadingLevel="3" Name="Accordion_SingleOpen" Mode="DwsAccordionMode.SingleOpen">
<DwsAccordionItem Name="AccordionItem_Single1" Title="First item">
<p>Exactly one item stays open at all times.</p>
</DwsAccordionItem>
<DwsAccordionItem Name="AccordionItem_Single2" Title="Second item">
<p>Opening this one collapses the first; neither can be collapsed directly.</p>
</DwsAccordionItem>
</DwsAccordion>
<DwsTypography Name="AccordionDemo_Heading3" Typography="DwsTypographyType.Heading6" Class="mt-3">Mode.SingleOpenOrNone</DwsTypography>
<DwsAccordion HeadingLevel="3" Name="Accordion_SingleOpenOrNone" Mode="DwsAccordionMode.SingleOpenOrNone">
<DwsAccordionItem Name="AccordionItem_SingleOrNone1" Title="First item">
<p>At most one item is open; opening another collapses this one.</p>
</DwsAccordionItem>
<DwsAccordionItem Name="AccordionItem_SingleOrNone2" Title="Second item">
<p>The open item can also be collapsed, leaving none open.</p>
</DwsAccordionItem>
</DwsAccordion>
<DwsTypography Name="AccordionDemo_Heading4" Typography="DwsTypographyType.Heading6" Class="mt-3">Mode.MultipleOpen</DwsTypography>
<DwsAccordion HeadingLevel="3" Name="Accordion_MultipleOpen" Mode="DwsAccordionMode.MultipleOpen">
<DwsAccordionItem Name="AccordionItem_MultipleOpen1" Title="First item">
<p>Starts expanded; any number of items may be open at once.</p>
</DwsAccordionItem>
<DwsAccordionItem Name="AccordionItem_MultipleOpen2" Title="Second item">
<p>Open this one too - the first stays open.</p>
</DwsAccordionItem>
</DwsAccordion>Accordion.razor.cs
// No additional code-behind is required for this example.Appearance, Shape & Spacing
Appearance, Shape, Color, HighlightColor and spacing/border parameters.
Uses Appearance, Shape, Color, spacing and border parameters.
The currently active item is tinted with HighlightColor.
Show Code
Accordion.razor
<DwsAccordion HeadingLevel="3" Name="Accordion_Filled"
Appearance="DwsAppearance.Filled"
Shape="DwsShape.Square"
Color="DwsColor.Secondary"
HighlightColor="DwsColor.Success"
Margin="8" Padding="4"
BorderWidth="1" BorderStyle="DwsBorderStyle.Solid" BorderColor="DwsColor.Secondary">
<DwsAccordionItem Name="AccordionItem_Filled1" Title="Filled, square, secondary">
<p>Uses Appearance, Shape, Color, spacing and border parameters.</p>
</DwsAccordionItem>
<DwsAccordionItem Name="AccordionItem_Filled2" Title="Highlighted when active">
<p>The currently active item is tinted with HighlightColor.</p>
</DwsAccordionItem>
</DwsAccordion>Accordion.razor.cs
// No additional code-behind is required for this example.Custom Icon & Title
A leading icon, a RenderFragment title and custom expand/collapse icons. Keep TitleContent to text, icons and other non-interactive content while the header is the button.
This item uses a leading icon, a RenderFragment title and custom expand/collapse icons.
Show Code
Accordion.razor
<DwsAccordion HeadingLevel="3" Name="Accordion_IconTitle">
<DwsAccordionItem Name="AccordionItem_IconTitle1"
Icon="@Icons.BS.InfoCircle" IconColor="DwsColor.Info"
ExpandIcon="@Icons.BS.PlusCircle" CollapseIcon="@Icons.BS.DashCircle">
<TitleContent>
<strong>Custom <em>title content</em></strong>
</TitleContent>
<ChildContent>
<p>This item uses a leading icon, a RenderFragment title and custom expand/collapse icons.</p>
</ChildContent>
</DwsAccordionItem>
</DwsAccordion>Accordion.razor.cs
// No additional code-behind is required for this example.Disabled Items
An item with Disabled set, and an item with no content, which is disabled automatically.
This content is never reachable while Disabled is true.
Show Code
Accordion.razor
<DwsAccordion HeadingLevel="3" Name="Accordion_Disabled">
<DwsAccordionItem Name="AccordionItem_Disabled" Title="Disabled item" Disabled="true">
<p>This content is never reachable while Disabled is true.</p>
</DwsAccordionItem>
<DwsAccordionItem Name="AccordionItem_NoContent" Title="No content embedded (auto-disabled)" />
</DwsAccordion>Accordion.razor.cs
// No additional code-behind is required for this example.Nested Accordions
A DwsAccordion nested inside a DwsAccordionItem's content.
Nested accordion:
Inner content 1.
Inner content 2.
Show Code
Accordion.razor
<DwsAccordion HeadingLevel="3" Name="Accordion_Outer">
<DwsAccordionItem Name="AccordionItem_Outer" Title="Outer section">
<p>Nested accordion:</p>
<DwsAccordion HeadingLevel="3" Name="Accordion_Inner">
<DwsAccordionItem Name="AccordionItem_Inner1" Title="Inner section 1">
<p>Inner content 1.</p>
</DwsAccordionItem>
<DwsAccordionItem Name="AccordionItem_Inner2" Title="Inner section 2">
<p>Inner content 2.</p>
</DwsAccordionItem>
</DwsAccordion>
</DwsAccordionItem>
</DwsAccordion>Accordion.razor.cs
// No additional code-behind is required for this example.Interface-Description
| Name | Typ | Default | Description |
|---|---|---|---|
| ChildContent | RenderFragment? | null | One or more DwsAccordionItem components to render inside the accordion. |
| Mode | DwsAccordionMode | SingleOpenOrNone | Controls how many items may be expanded at once: SingleOpen, SingleOpenOrNone, MultipleOpen or MultipleOpenOrNone. |
| Appearance | DwsAppearance | Outline | Visual appearance of the accordion (Outline, Filled, Text). |
| Shape | DwsShape | Round | Corner shape of the accordion. |
| Color | DwsColor | Primary | Base theme color of the accordion. |
| HighlightColor | DwsColor | Undefined | Accent color applied to whichever item matches ActiveItemName. |
| Margin | int? | null | Outer margin in pixels. |
| Padding | int? | null | Inner padding in pixels. |
| BorderWidth | int? | null | Border width in pixels. |
| BorderStyle | DwsBorderStyle | None | Border line style. |
| BorderColor | DwsColor | Undefined | Border color. |
| DefaultTriggerMode | DwsAccordionTriggerMode | HeaderClick | Default expand/collapse trigger for items that don't set their own TriggerMode. |
| ActiveItemName | string? | null | Name of the most recently expanded item. Supports two-way binding via @bind-ActiveItemName. |
| AnimationMode | DwsAccordionAnimationMode | Collapse | CSS transition family applied when items expand/collapse. |
| AnimationSpeed | DwsAnimationSpeed | Normal | Duration of the expand/collapse animation. |
| AriaLabel | string? | null | Overrides the accordion's accessible label. |
| HeadingLevel | int | 2 | The heading level (1-6) of every item's header, for the page's outline. Headers are h2 elements; any other level is announced through aria-level. |
| Name | Typ | Description |
|---|---|---|
| ActiveItemNameChanged | EventCallback<string?> | Fired when ActiveItemName changes. Used by @bind-ActiveItemName. |
| OnActiveItemChanged | EventCallback<string?> | Fired when the active item changes. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Element | ElementReference | The associated web component. May be null if accessed before the component is rendered. | |
| ComponentGuid | Guid | Unique identifier for the component. | |
| TypeString | string | The name of the component type, obtained from reflection. | |
| Authorized_RegisterEnabled | bool | false | Indicates whether this component is enabled through a permission registry. |
| Authorized_RegisterSelected | bool | false | Indicates whether this component is selected in permission selection mode. |
| GetInitializedState | bool | false | Returns whether the component is initialized. |
| GetRenderModeState | DwsRenderMode | Returns the current render mode. | |
| GetComponentState | DwsComponentStateType | Returns the current component state. | |
| GetIsInteractiveState | bool | false | Returns whether the component is interactive. |
| GetIsPrerenderingState | bool | false | Returns whether the component is prerendering. |
| GetComponentLoadingState | bool | false | Returns whether the component is loading. |
| IsFormBusy | bool | false | Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState). |
| Name | Typ | Parameters | Description |
|---|---|---|---|
| DebugInfo | void | Logs debug information about the component. | |
| UpdateState | void | Updates the component's state and triggers StateHasChanged. | |
| UpdateStateAsync | Task | Asynchronously updates the component's state and triggers StateHasChanged. | |
| Dispose | void | Disposes the component and releases resources. | |
| FocusAsync | ValueTask | bool containedInScrollableList | Sets focus to the component's element. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Name | string | Required unique identifier for the component within its container. | |
| Visible | bool | true | Determines if the component is visible in the UI. |
| Disabled | bool | false | Disables the form control, ensuring it doesn't participate in form submission. |
| ComponentNameSpace | string | The namespace for permission-based access control. | |
| PermissionKey | string? | null | A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins. |
| Class | string | Optional CSS class names. | |
| Style | string | Optional in-line styles. | |
| Tag | object | An optional user-defined object to store any additional data with the component. | |
| BackReference | DwsReference | A reference to the enclosing component. | |
| ID | string | The HTML ID attribute for the component. | |
| AdditionalAttributes | Dictionary<string, object> | Additional HTML attributes for the component's root element. | |
| IgnorePermissionChecks | bool | false | Bypasses all permission checks for this component. |
| IgnorePermissionSelection | bool | false | Ignore permission selection mode for this component. |
| IgnoreFormBusy | bool | false | Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it. |
| Name | Typ | Description |
|---|---|---|
| OnInitializedCallbackStarted | EventCallback | Callback when OnInitialized starts. |
| OnInitializedCallback | EventCallback | Callback during OnInitialized. |
| OnInitializedCallbackCompleted | EventCallback | Callback when OnInitialized completes. |
| OnInitializedAsyncCallbackStarted | EventCallback | Callback when OnInitializedAsync starts. |
| OnInitializedAsyncCallback | EventCallback | Callback during OnInitializedAsync. |
| OnInitializedAsyncCallbackCompleted | EventCallback | Callback when OnInitializedAsync completes. |
| OnIsComponentLoadingChanged | EventCallback<bool> | Callback when IsComponentLoading changes. |
| OnCurrentRenderModeChanged | EventCallback<DwsRenderMode> | Callback when CurrentRenderMode changes. |
| OnComponentStateChanged | EventCallback<DwsComponentStateType> | Callback when ComponentState changes. |
Interface-Description
| Name | Typ | Default | Description |
|---|---|---|---|
| Title | string | string.Empty | Header text displayed on the accordion item toggle. |
| TitleContent | RenderFragment? | null | Rich header content; overrides Title when set. In the HeaderClick and HeaderDblClick trigger modes it is rendered inside the header's native button, so it must not contain controls of its own (use TriggerMode ButtonClick for a header with buttons or links). |
| ChildContent | RenderFragment? | null | Body content rendered when the accordion item is expanded. |
| OnLoadContentAsync | Func<Task>? | null | Invoked once on first expand to lazily populate ChildContent's data; shows a loading state meanwhile. |
| Icon | string | string.Empty | Optional leading icon shown before the title. |
| ShowIcon | bool | true | Whether the leading Icon is rendered. |
| IconColor | DwsColor | Undefined | Color of the leading icon. |
| ExpandIcon | string | bi-chevron-down | Icon shown when the item is collapsed. |
| CollapseIcon | string | bi-chevron-up | Icon shown when the item is expanded. |
| ShowToggleIcon | bool | true | Whether the expand/collapse icon is rendered. |
| Haptic | DwsHapticFeedback | Selection | The tick played when the header opens or closes the item (haptics switched on, phones only). None turns it off. |
| Color | DwsColor? | null | Overrides the parent accordion's Color for this item. |
| Margin | int? | null | Outer margin in pixels. |
| Padding | int? | null | Inner padding in pixels. |
| BorderWidth | int? | null | Border width in pixels. |
| BorderStyle | DwsBorderStyle | None | Border line style. |
| BorderColor | DwsColor | Undefined | Border color. |
| IsExpanded | bool | false | Controls whether the item is expanded. Supports two-way binding via @bind-IsExpanded. |
| DisableCollapse | bool | false | Once expanded, prevents collapsing this item through the UI. |
| TriggerMode | DwsAccordionTriggerMode? | null | Overrides the parent accordion's DefaultTriggerMode for this item only. HeaderClick / HeaderDblClick: the header is a native button (Enter and Space toggle it). ButtonClick: the header is plain text and the toggle icon is the button. |
| AriaLabel | string? | null | Overrides the item's accessible label. |
| Name | Typ | Description |
|---|---|---|
| IsExpandedChanged | EventCallback<bool> | Fired when the expanded state changes. Used by @bind-IsExpanded. |
| OnExpand | EventCallback | Fired when the item expands. |
| OnCollapse | EventCallback | Fired when the item collapses. |
| VisibleChanged | EventCallback<bool> | Fired when the inherited Visible parameter changes. Used by @bind-Visible. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Element | ElementReference | The associated web component. May be null if accessed before the component is rendered. | |
| ComponentGuid | Guid | Unique identifier for the component. | |
| TypeString | string | The name of the component type, obtained from reflection. | |
| Authorized_RegisterEnabled | bool | false | Indicates whether this component is enabled through a permission registry. |
| Authorized_RegisterSelected | bool | false | Indicates whether this component is selected in permission selection mode. |
| GetInitializedState | bool | false | Returns whether the component is initialized. |
| GetRenderModeState | DwsRenderMode | Returns the current render mode. | |
| GetComponentState | DwsComponentStateType | Returns the current component state. | |
| GetIsInteractiveState | bool | false | Returns whether the component is interactive. |
| GetIsPrerenderingState | bool | false | Returns whether the component is prerendering. |
| GetComponentLoadingState | bool | false | Returns whether the component is loading. |
| IsFormBusy | bool | false | Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState). |
| Name | Typ | Parameters | Description |
|---|---|---|---|
| DebugInfo | void | Logs debug information about the component. | |
| UpdateState | void | Updates the component's state and triggers StateHasChanged. | |
| UpdateStateAsync | Task | Asynchronously updates the component's state and triggers StateHasChanged. | |
| Dispose | void | Disposes the component and releases resources. | |
| FocusAsync | ValueTask | bool containedInScrollableList | Sets focus to the component's element. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Name | string | Required unique identifier for the component within its container. | |
| Visible | bool | true | Determines if the component is visible in the UI. |
| Disabled | bool | false | Disables the form control, ensuring it doesn't participate in form submission. |
| ComponentNameSpace | string | The namespace for permission-based access control. | |
| PermissionKey | string? | null | A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins. |
| Class | string | Optional CSS class names. | |
| Style | string | Optional in-line styles. | |
| Tag | object | An optional user-defined object to store any additional data with the component. | |
| BackReference | DwsReference | A reference to the enclosing component. | |
| ID | string | The HTML ID attribute for the component. | |
| AdditionalAttributes | Dictionary<string, object> | Additional HTML attributes for the component's root element. | |
| IgnorePermissionChecks | bool | false | Bypasses all permission checks for this component. |
| IgnorePermissionSelection | bool | false | Ignore permission selection mode for this component. |
| IgnoreFormBusy | bool | false | Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it. |
| Name | Typ | Description |
|---|---|---|
| OnInitializedCallbackStarted | EventCallback | Callback when OnInitialized starts. |
| OnInitializedCallback | EventCallback | Callback during OnInitialized. |
| OnInitializedCallbackCompleted | EventCallback | Callback when OnInitialized completes. |
| OnInitializedAsyncCallbackStarted | EventCallback | Callback when OnInitializedAsync starts. |
| OnInitializedAsyncCallback | EventCallback | Callback during OnInitializedAsync. |
| OnInitializedAsyncCallbackCompleted | EventCallback | Callback when OnInitializedAsync completes. |
| OnIsComponentLoadingChanged | EventCallback<bool> | Callback when IsComponentLoading changes. |
| OnCurrentRenderModeChanged | EventCallback<DwsRenderMode> | Callback when CurrentRenderMode changes. |
| OnComponentStateChanged | EventCallback<DwsComponentStateType> | Callback when ComponentState changes. |
