Is there a way to have a button in the header of the accordion that does not trigger expand/collapse? Right now the whole header is clickable to expand/collapse so when I add a button to the header and click it, the expand collapse action occurs. I want to have a button in the header so that I can click it and something else happens but the accordion item stays in the same state it was in. Only clicking the expand/collapse icon should open and close it.
<SfAccordion> <AccordionEvents Expanding="OnExpanding" Collapsing="OnCollapsing" Expanded="OnExpanded" Collapsed="OnCollapsed"></AccordionEvents> <AccordionItems> <AccordionItem Content="Margeret Peacock was born on Saturday , 01 December 1990."> <HeaderTemplate> <SfToolbar> <ToolbarItems> <ToolbarItem><SfButton Content="OnClick"></SfButton></ToolbarItem> <ToolbarItem Text="Copy"></ToolbarItem> <ToolbarItem Text="Paste"></ToolbarItem> </ToolbarItems> </SfToolbar> <div class="e-custom e-toggle-icon" @onclick="ToggleIconClicked"> <span class="e-tgl-collapse-icon e-icons"></span> </div> </HeaderTemplate> </AccordionItem> <AccordionItem Content="Laura Callahan was born on Tuesday , 06 November 1990."> <HeaderTemplate> <div>Laura Callahan</div> <div class="e-custom e-toggle-icon" @onclick="ToggleIconClicked"> <span class="e-tgl-collapse-icon e-icons"></span> </div> </HeaderTemplate> </AccordionItem> </AccordionItems> </SfAccordion> @code { private bool isToggleIconClicked = false; public void ToggleIconClicked() { isToggleIconClicked = true; } public void OnExpanding(ExpandEventArgs args) { if (!isToggleIconClicked) { args.Cancel = true; } } public void OnCollapsing(CollapseEventArgs args) { if (!isToggleIconClicked) { args.Cancel = true; } } public void OnExpanded(ExpandedEventArgs args) { isToggleIconClicked = !isToggleIconClicked; } public void OnCollapsed(CollapsedEventArgs args) { isToggleIconClicked = !isToggleIconClicked; } } <style> .e-accordion .e-acrdn-item .e-acrdn-header .e-toggle-icon:not(.e-custom) { display: none; } </style> |
It looks like you're using a Syncfusion css class for the toggle icon? What about when you want all the accordion items to default as expanded. When I switch my code to use this solution, the icon is pointing down with the accordion item expanded, which is correct. But when you click to close it, the arrow stays as the one pointing down. Then if you click it again to expand the accordion item, the arrow icon flips to facing up which is then wrong.
Joe,
You can resolve the issue with the toggle icon not updating properly by dynamically updating the class names, as shown below:
<SfAccordion> <AccordionEvents Expanding="OnExpanding" Collapsing="OnCollapsing" Expanded="OnExpanded" Collapsed="OnCollapsed"></AccordionEvents> <AccordionItems> <AccordionItem Expanded="@isFirstItemExpanded" Content="Margeret Peacock was born on Saturday , 01 December 1990. Now lives at Coventry House Miner Rd., London,UK. Margeret Peacock holds a position of Sales Coordinator in our WA department, (Seattle USA). Joined our company on Saturday , 01 May 2010"> <HeaderTemplate> <SfToolbar> <ToolbarItems> <ToolbarItem><SfButton Content="OnClick" @onclick="OnButtonClick"></SfButton></ToolbarItem> <ToolbarItem Text="Copy"></ToolbarItem> <ToolbarItem Text="Paste"></ToolbarItem> </ToolbarItems> </SfToolbar> <div class="e-custom e-toggle-icon" @onclick="ToggleIconClicked"> <span class='@(isFirstItemExpanded ? "e-tgl-collapse-icon e-icons e-expand-icon" : "e-tgl-collapse-icon e-icons")'></span> </div> </HeaderTemplate>
</AccordionItem> <AccordionItem Expanded="@isSecondItemExpanded" Content="Laura Callahan was born on Tuesday , 06 November 1990. Now lives at Edgeham Hollow Winchester Way, London,UK. Laura Callahan holds a position of Sales Coordinator in our WA department, (Seattle USA). Joined our company on Saturday , 01 May 2010"> <HeaderTemplate> <div>Laura Callahan</div> <div class="e-custom e-toggle-icon" @onclick="ToggleIconClicked"> <span class='@(isSecondItemExpanded ? "e-tgl-collapse-icon e-icons e-expand-icon" : "e-tgl-collapse-icon e-icons")'></span> </div> </HeaderTemplate> </AccordionItem> </AccordionItems> </SfAccordion>
@code { bool isFirstItemExpanded = true; bool isSecondItemExpanded = true; private bool isToggleIconClicked = false; } |
Sample: https://blazorplayground.syncfusion.com/VZheXACuUJCYcmUm
Please try this solution and let us know if you need further assistance!