Render different components dynamically within the modal without iterating through possible types or using conditional logic.
If dynamically-rendered components have component parameters, pass them as an IDictionary. The string is the parameter's name, and the object is the parameter's value.
Event callbacks (EventCallback) can be passed in its parameter dictionary.
In the following parent component example, the ShowDTMessage method assigns a string with the current time to message, and the value of message is rendered.
The parent component passes the callback method, ShowDTMessage in the parameter dictionary:
The string key is the callback method's name, OnClickCallback.
The object value is created by EventCallbackFactory.Create for the parent callback method, ShowDTMessage.
When modals become too long for the user’s viewport or device, they scroll independent of the page itself. Try the demo below to see what we mean.
<Modal @ref="modal" title="Modal title">
<BodyTemplate>
<p style="margin-bottom: 100vh;">This is some placeholder content to show the scrolling behavior for modals. Instead of repeating the text the modal, we use an inline style set a minimum height, thereby extending the length of the overall modal and demonstrating the overflow scrolling. When content becomes longer than the height of the viewport, scrolling will move the modal as needed.</p>
<p>This content should appear at the bottom after you scroll.</p>
</BodyTemplate>
<FooterTemplate>
<Button Color="ButtonColor.Secondary" @onclick="OnHideModalClick">Close</Button>
<Button Color="ButtonColor.Primary">Save changes</Button>
</FooterTemplate>
</Modal>
<Button Color="ButtonColor.Primary" @onclick="OnShowModalClick">Launch demo modal</Button>
@code {
private Modal modal = default!;
private async Task OnShowModalClick()
{
await modal.ShowAsync();
}
private async Task OnHideModalClick()
{
await modal.HideAsync();
}
}
You can also create a scrollable modal that allows scroll the modal body by adding IsScrollable="true".
<Modal @ref="modal" title="Modal title" IsScrollable="true">
<BodyTemplate>
<p style="margin-bottom: 100vh;">This is some placeholder content to show the scrolling behavior for modals. Instead of repeating the text the modal, we use an inline style set a minimum height, thereby extending the length of the overall modal and demonstrating the overflow scrolling. When content becomes longer than the height of the viewport, scrolling will move the modal as needed.</p>
<p>This content should appear at the bottom after you scroll.</p>
</BodyTemplate>
<FooterTemplate>
<Button Color="ButtonColor.Secondary" @onclick="OnHideModalClick">Close</Button>
<Button Color="ButtonColor.Primary">Save changes</Button>
</FooterTemplate>
</Modal>
<Button Color="ButtonColor.Primary" @onclick="OnShowModalClick">Launch demo modal</Button>
@code {
private Modal modal = default!;
private async Task OnShowModalClick()
{
await modal.ShowAsync();
}
private async Task OnHideModalClick()
{
await modal.HideAsync();
}
}
<Modal @ref="modal" title="Modal title" IsVerticallyCentered="true" IsScrollable="true">
<BodyTemplate>
<p style="margin-bottom: 100vh;">This is some placeholder content to show the scrolling behavior for modals. Instead of repeating the text the modal, we use an inline style set a minimum height, thereby extending the length of the overall modal and demonstrating the overflow scrolling. When content becomes longer than the height of the viewport, scrolling will move the modal as needed.</p>
<p>This content should appear at the bottom after you scroll.</p>
</BodyTemplate>
<FooterTemplate>
<Button Color="ButtonColor.Secondary" @onclick="OnHideModalClick">Close</Button>
<Button Color="ButtonColor.Primary">Save changes</Button>
</FooterTemplate>
</Modal>
<Button Color="ButtonColor.Primary" @onclick="OnShowModalClick">Vertically centered scrollable modal</Button>
@code {
private Modal modal = default!;
private async Task OnShowModalClick()
{
await modal.ShowAsync();
}
private async Task OnHideModalClick()
{
await modal.HideAsync();
}
}