ConfirmDialog locks body scroll via IJSRuntime + Bootstrap's modal-open class on show, restores on hide. Escape key now closes the dialog; default ConfirmButtonClass flipped from btn-danger to btn-primary so non-destructive confirms aren't red. Destructive callsites (Delete, Discard) get explicit ConfirmButtonClass="btn-danger". ToastNotification adds aria-live="polite" + aria-atomic="true" on the container and an optional autoDismissMs parameter on every Show* method. LoadingSpinner text-muted -> text-secondary for contrast. DataTable gains a clear (x) button on the search input and applies disabled / aria-disabled directly to the pagination buttons. NewFolderDialog splits backdrop and modal markup to match ConfirmDialog. NavMenu wraps the nav list in an overflow-y scroll container so the username/sign-out footer stays anchored, and section headers convert from <li> to <div role="presentation">. MainLayout adds a hamburger toggle for <lg viewports; sidebar collapses via Bootstrap collapse data attributes. App.razor extracts inline <style> block to a shared site.css; adds a left-border accent on the active nav link; switches the reconnect modal to modal-dialog-centered. Login uses d-flex / min-vh-100 centering. NotAuthorizedView gets the same centered layout plus the ScadaLink brand heading. Sites.razor: only the new ConfirmButtonClass="btn-danger" follow-up.
132 lines
3.7 KiB
Plaintext
132 lines
3.7 KiB
Plaintext
@* Reusable confirmation dialog using Bootstrap modal.
|
|
z-index ladder: Toast container 1090 > this modal 1055 > this backdrop 1040. *@
|
|
@inject IJSRuntime JS
|
|
@implements IAsyncDisposable
|
|
|
|
@if (_visible)
|
|
{
|
|
<div class="modal-backdrop fade show"></div>
|
|
<div @ref="_modalRef"
|
|
class="modal fade show d-block"
|
|
tabindex="-1"
|
|
role="dialog"
|
|
@onkeydown="OnKeyDownAsync">
|
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">@Title</h5>
|
|
<button type="button" class="btn-close" @onclick="Cancel"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>@Message</p>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="Cancel">Cancel</button>
|
|
<button type="button" class="btn @ConfirmButtonClass btn-sm" @onclick="Confirm">@ConfirmText</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
private bool _visible;
|
|
private bool _bodyLocked;
|
|
private TaskCompletionSource<bool>? _tcs;
|
|
private ElementReference _modalRef;
|
|
|
|
[Parameter] public string Title { get; set; } = "Confirm";
|
|
[Parameter] public string Message { get; set; } = "Are you sure?";
|
|
[Parameter] public string ConfirmText { get; set; } = "Confirm";
|
|
[Parameter] public string ConfirmButtonClass { get; set; } = "btn-primary";
|
|
|
|
public Task<bool> ShowAsync(string? message = null, string? title = null)
|
|
{
|
|
if (message != null) Message = message;
|
|
if (title != null) Title = title;
|
|
_visible = true;
|
|
_tcs = new TaskCompletionSource<bool>();
|
|
StateHasChanged();
|
|
return _tcs.Task;
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (_visible && !_bodyLocked)
|
|
{
|
|
_bodyLocked = true;
|
|
await TryLockBodyAsync();
|
|
// Focus the modal so the @onkeydown handler receives Escape.
|
|
try { await _modalRef.FocusAsync(); }
|
|
catch { /* prerender or detached: ignore */ }
|
|
}
|
|
}
|
|
|
|
private async Task OnKeyDownAsync(KeyboardEventArgs e)
|
|
{
|
|
if (e.Key == "Escape")
|
|
{
|
|
await CancelAsync();
|
|
}
|
|
}
|
|
|
|
private void Confirm()
|
|
{
|
|
Close(true);
|
|
}
|
|
|
|
private void Cancel()
|
|
{
|
|
Close(false);
|
|
}
|
|
|
|
private Task CancelAsync()
|
|
{
|
|
Close(false);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private void Close(bool result)
|
|
{
|
|
_visible = false;
|
|
_ = TryUnlockBodyAsync();
|
|
_tcs?.TrySetResult(result);
|
|
}
|
|
|
|
private async Task TryLockBodyAsync()
|
|
{
|
|
try
|
|
{
|
|
await JS.InvokeVoidAsync("document.body.classList.add", "modal-open");
|
|
}
|
|
catch
|
|
{
|
|
// Prerendering has no JS runtime; log only.
|
|
try { await JS.InvokeVoidAsync("console.debug", "ConfirmDialog: JS interop unavailable for body lock."); }
|
|
catch { /* swallow */ }
|
|
}
|
|
}
|
|
|
|
private async Task TryUnlockBodyAsync()
|
|
{
|
|
_bodyLocked = false;
|
|
try
|
|
{
|
|
await JS.InvokeVoidAsync("document.body.classList.remove", "modal-open");
|
|
}
|
|
catch
|
|
{
|
|
try { await JS.InvokeVoidAsync("console.debug", "ConfirmDialog: JS interop unavailable for body unlock."); }
|
|
catch { /* swallow */ }
|
|
}
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
if (_bodyLocked)
|
|
{
|
|
await TryUnlockBodyAsync();
|
|
}
|
|
}
|
|
}
|