[frontend/components] Add Escape and Enter to SelectDialog

This commit is contained in:
pancakes 2025-02-21 19:16:11 +10:00
parent 12f4267d01
commit 37ec177e69
No known key found for this signature in database
GPG key ID: ED53D426432B861B

View file

@ -5,7 +5,7 @@
@inject IJSRuntime Js; @inject IJSRuntime Js;
@inject IStringLocalizer<Localization> Loc; @inject IStringLocalizer<Localization> Loc;
<dialog class="dialog" @ref="Dialog"> <dialog @onkeydown="HandleKeyDown" class="dialog" @ref="Dialog">
<div class="select @(Waiting ? "waiting" : "")"> <div class="select @(Waiting ? "waiting" : "")">
@if (Waiting) @if (Waiting)
{ {
@ -71,6 +71,19 @@
await CloseDialog(); await CloseDialog();
} }
private async Task HandleKeyDown(KeyboardEventArgs e)
{
if (e is { Code: "Enter" })
{
if (!Waiting) await ConfirmAction();
}
if (e is { Code: "Escape" })
{
if (!Waiting) await CancelAction();
}
}
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
_module = await Js.InvokeAsync<IJSObjectReference>("import", _module = await Js.InvokeAsync<IJSObjectReference>("import",