<Fields>
<Field ColumnSize="ColumnSize.Is1.OnDesktop">
<TextEdit IsReadonly="true" Text="@Name" />
</Field>
<Field>
<SimpleButton Color="Color.Danger" Clicked="Remove">Remove</SimpleButton>
</Field>
<Field>
<SimpleButton Color="Color.Warning" Clicked="Show Modal">Edit</SimpleButton>
</Field>
</Fields>
<Modal ref="modalRef">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalHeader>
<ModalTitle>Edit</ModalTitle>
<CloseButton Clicked="@HideModal" />
</ModalHeader>
<ModalBody>
<Field>
<FieldLabel>@Name</FieldLabel>
<TextEdit Placeholder="Enter name..." />
</Field>
</ModalBody>
<ModalFooter>
<SimpleButton Color="Color.Secondary" Clicked="@HideModal">X</SimpleButton>
<SimpleButton Color="Color.Primary" Clicked="@HideModal">Save</SimpleButton>
</ModalFooter>
</ModalContent>
</Modal>
@functions
{
private Modal modalRef;
[Parameter]
private string Name { get; set; }
}
Lets say i have to loop these to show them in table.
But using this in for loop in some other component will create hidden modal for each item. Now correct me if i'm wrong but, there's no way to create single modal as generic component and then just pass modal ref and other parameters on click event , right?
@functions {
RenderFragment ModalProperty { get; set; }
private Modal modal;
RenderFragment CreateDynamicComponent() => builder =>
{
builder.OpenComponent(0, typeof(CustomGenericModal));
builder.AddAttribute(1, "modalRef", modal);
builder.AddAttribute(2, "Name", @Name);
builder.CloseComponent();
};
void SetModalPropertyOnClick()
{
ModalProperty = CreateDynamicComponent();
}
}
This way each item would have empty RenderFragment ModalProperty { get; set; }. But modal would only render on click by invoking component dynamically and setting ModalProperty .