Skip to content

Commit 3e51a13

Browse files
committed
Fix show and hide for nested collapses
1 parent 5509514 commit 3e51a13

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

BlazorBootstrap.Demo.RCL/Components/Pages/Accordion/Accordion_Demo_01_Examples.razor

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
<AccordionItem Title="Accordion Item #1">
33
<Content>
44
<b>This is the first item's accordion body.</b> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.
5+
<Accordion>
6+
<AccordionItem Title="Accordion Item #1.1">
7+
<Content>
8+
<b>This is the first item in a nested accordion body.</b>.
9+
</Content>
10+
</AccordionItem>
11+
<AccordionItem Title="Accordion Item #1.2">
12+
<Content>
13+
<b>This is the second item in a nested accordion body.</b>.
14+
</Content>
15+
</AccordionItem>
16+
</Accordion>
517
</Content>
618
</AccordionItem>
719
<AccordionItem Title="Accordion Item #2">

blazorbootstrap/Components/Accordion/AccordionItem.razor.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,34 @@ protected override void OnParametersSet()
2727

2828
internal async Task ShowAsync() => await collapse.ShowAsync();
2929

30-
private async Task OnCollapseHiddenAsync()
30+
private async Task OnCollapseHiddenAsync(string collapseId)
3131
{
32+
if (collapseId != collapse.Id) return;
3233
if (Parent is not null && Parent.OnHidden.HasDelegate)
3334
await Parent.OnHidden.InvokeAsync(new AccordionEventArgs(Name, Title));
3435
}
3536

36-
private async Task OnCollapseHidingAsync()
37+
private async Task OnCollapseHidingAsync(string collapseId)
3738
{
39+
if (collapseId != collapse.Id) return;
3840
isCollapsed = true;
3941

4042
if (Parent is not null && Parent.OnHiding.HasDelegate)
4143
await Parent.OnHiding.InvokeAsync(new AccordionEventArgs(Name, Title));
4244
}
4345

44-
private async Task OnCollapseShowingAsync()
46+
private async Task OnCollapseShowingAsync(string collapseId)
4547
{
48+
if (collapseId != collapse.Id) return;
4649
isCollapsed = false;
4750

4851
if (Parent is not null && Parent.OnShowing.HasDelegate)
4952
await Parent.OnShowing.InvokeAsync(new AccordionEventArgs(Name, Title));
5053
}
5154

52-
private async Task OnCollapseShownAsync()
55+
private async Task OnCollapseShownAsync(string collapseId)
5356
{
57+
if (collapseId != collapse.Id) return;
5458
if (Parent is not null && Parent.OnShown.HasDelegate)
5559
await Parent.OnShown.InvokeAsync(new AccordionEventArgs(Name, Title));
5660
}

blazorbootstrap/Components/Collapse/Collapse.razor.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ protected override async Task OnInitializedAsync()
4747
}
4848

4949
[JSInvokable]
50-
public async Task bsHiddenCollapse() => await OnHidden.InvokeAsync();
50+
public async Task bsHiddenCollapse(string collapseId) => await OnHidden.InvokeAsync(collapseId);
5151

5252
[JSInvokable]
53-
public async Task bsHideCollapse() => await OnHiding.InvokeAsync();
53+
public async Task bsHideCollapse(string collapseId) => await OnHiding.InvokeAsync(collapseId);
5454

5555
[JSInvokable]
56-
public async Task bsShowCollapse() => await OnShowing.InvokeAsync();
56+
public async Task bsShowCollapse(string collapseId) => await OnShowing.InvokeAsync(collapseId);
5757

5858
[JSInvokable]
59-
public async Task bsShownCollapse() => await OnShown.InvokeAsync();
59+
public async Task bsShownCollapse(string collapseId) => await OnShown.InvokeAsync(collapseId);
6060

6161
/// <summary>
6262
/// Hides a collapsible element.
@@ -105,26 +105,26 @@ protected override async Task OnInitializedAsync()
105105
/// This event is fired when a collapse element has been hidden from the user (will wait for CSS transitions to complete).
106106
/// </summary>
107107
[Parameter]
108-
public EventCallback OnHidden { get; set; }
108+
public EventCallback<string> OnHidden { get; set; }
109109

110110
/// <summary>
111111
/// This event is fired immediately when the hide method has been called.
112112
/// </summary>
113113
[Parameter]
114-
public EventCallback OnHiding { get; set; }
114+
public EventCallback<string> OnHiding { get; set; }
115115

116116
/// <summary>
117117
/// This event fires immediately when the show instance method is called.
118118
/// </summary>
119119
[Parameter]
120-
public EventCallback OnShowing { get; set; }
120+
public EventCallback<string> OnShowing { get; set; }
121121

122122
/// <summary>
123123
/// This event is fired when a collapse element has been made visible to the user (will wait for CSS transitions to
124124
/// complete).
125125
/// </summary>
126126
[Parameter]
127-
public EventCallback OnShown { get; set; }
127+
public EventCallback<string> OnShown { get; set; }
128128

129129
/// <summary>
130130
/// Gets or sets the parent selector, DOM element.

blazorbootstrap/wwwroot/blazor.bootstrap.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,16 @@ window.blazorBootstrap = {
186186
return;
187187

188188
collapseEl.addEventListener('show.bs.collapse', (event) => {
189-
dotNetHelper.invokeMethodAsync('bsShowCollapse');
189+
dotNetHelper.invokeMethodAsync('bsShowCollapse', event.target?.id);
190190
});
191191
collapseEl.addEventListener('shown.bs.collapse', (event) => {
192-
dotNetHelper.invokeMethodAsync('bsShownCollapse');
192+
dotNetHelper.invokeMethodAsync('bsShownCollapse', event.target?.id);
193193
});
194194
collapseEl.addEventListener('hide.bs.collapse', (event) => {
195-
dotNetHelper.invokeMethodAsync('bsHideCollapse');
195+
dotNetHelper.invokeMethodAsync('bsHideCollapse', event.target?.id);
196196
});
197197
collapseEl.addEventListener('hidden.bs.collapse', (event) => {
198-
dotNetHelper.invokeMethodAsync('bsHiddenCollapse');
198+
dotNetHelper.invokeMethodAsync('bsHiddenCollapse', event.target?.id);
199199
});
200200

201201
let options = { parent: parent, toggle: toggle };

0 commit comments

Comments
 (0)