@inherits DComponentBase @* daisyUI Accordion: https://daisyui.com/components/accordion/ . Instead of daisyUI's radio group, the open item is an index in C# (@bind-Active, -1 = none). Each DAccordionItem registers itself through the cascading value and renders a DCollapse that is open only while its index is Active. The cascading value isn't fixed, so every item re-renders whenever the accordion does. *@
@ChildContent
@code { [Parameter] public RenderFragment ChildContent { get; set; } /// Index of the open item, in registration order; -1 when all are closed. [Parameter] public int Active { get; set; } = -1; [Parameter] public EventCallback ActiveChanged { get; set; } [Parameter] public DCollapseIcon Icon { get; set; } /// Join the items into one block (join join-vertical, join-item). [Parameter] public bool Joined { get; set; } readonly List items = new(); string CssClass => Cx(Joined ? "join join-vertical rounded-box neo-raised" : "flex flex-col gap-2", Class); internal int IndexOf(DAccordionItem item) => items.IndexOf(item); internal void Add(DAccordionItem item) { items.Add(item); StateHasChanged(); } internal void Remove(DAccordionItem item) { items.Remove(item); StateHasChanged(); } internal async Task Select(int index) { Active = index; await ActiveChanged.InvokeAsync(index); StateHasChanged(); } }