Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Blazored.Modal/BlazoredModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<CascadingValue Value="_globalModalOptions">
@foreach (var modal in _modals)
{
@modal.ModalInstance
<DynamicComponent @key="modal.Id"
Type="typeof(KeyedComponent)"
Parameters="KeyedParams(modal)" />
}
</CascadingValue>
</CascadingValue>
Expand Down Expand Up @@ -134,7 +136,7 @@
await _styleFunctions.InvokeVoidAsync("setBodyStyle");
}
}

await InvokeAsync(StateHasChanged);
}

Expand All @@ -150,6 +152,11 @@
}
}

private Dictionary<string, object?> KeyedParams(ModalReference modal) => new()
{
[nameof(KeyedComponent.ChildContent)] = modal.ModalInstance
};

async ValueTask IAsyncDisposable.DisposeAsync()
{
if (_styleFunctions is not null)
Expand All @@ -163,6 +170,6 @@
// If the browser is gone, we don't need it to clean up any browser-side state
}
}
}
}

}
14 changes: 14 additions & 0 deletions src/Blazored.Modal/KeyedComponent.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

namespace Blazored.Modal;

internal class KeyedComponent : ComponentBase
{
[Parameter] public RenderFragment ChildContent { get; set; } = default!;

protected override void BuildRenderTree(RenderTreeBuilder builder)
{
ChildContent(builder);
}
}