@inject IJSRuntime JSRuntime
@implements IAsyncDisposable
@ChildContent
@code {
///
/// Callback when Enter key is pressed.
///
[Parameter]
public EventCallback OnEnter { get; set; }
///
/// The child content of the component.
///
[Parameter]
public required RenderFragment ChildContent { get; set; }
///
/// CSS class string to apply to the wrapper div.
///
[Parameter]
public string CssClass { get; set; } = "modal-dialog fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center";
///
/// Determines if the default behavior should be prevented for keyboard events.
///
[Parameter]
public bool preventDefault { get; set; } = false;
///
/// Handle keyboard events.
///
private async Task KeyWasPressed(KeyboardEventArgs e)
{
// Listen for Enter key and submit the modal
if (e.Key == "Enter")
{
preventDefault = true;
await OnEnter.InvokeAsync();
}
}
///
public ValueTask DisposeAsync()
{
return ValueTask.CompletedTask;
}
}