Skip to content

Commit

Permalink
feat: auto focus on barcode text field after scan
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw committed Jan 29, 2024
1 parent 6a26169 commit 2a20f79
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions GrocyScanner.Service/Pages/Scanner.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@inject IGtinValidator GtinValidator
@using Microsoft.AspNetCore.SignalR.Client
@inject NavigationManager NavigationManager
@inject IJSRuntime JS
@inject IJSRuntime Js
@inject IDialogService DialogService

<PageTitle>Scanner • Grocy Scanner</PageTitle>
Expand All @@ -27,6 +27,7 @@
</MudStack>
<div>
<MudTextField
@ref="barcodeInputTextRef"
@bind-Value="Barcode"
T="string"
Margin="Margin.Dense"
Expand Down Expand Up @@ -80,6 +81,8 @@
private CameraNotification? CurrentSelectedCamera { get; set; }
private string Barcode { get; set; } = string.Empty;

private MudTextField<string> barcodeInputTextRef;

protected override async Task OnInitializedAsync()
{
HubConnection hubConnection = new HubConnectionBuilder()
Expand All @@ -103,12 +106,12 @@

private async Task OnRefreshAvailableCameras()
{
await JS.InvokeVoidAsync("updateAvailableCameras");
await Js.InvokeVoidAsync("updateAvailableCameras");
}

private async Task OnSelectedCameraChanged(CameraNotification cameraNotification)
{
await JS.InvokeVoidAsync("startScanningWithCamera", cameraNotification.Id);
await Js.InvokeVoidAsync("startScanningWithCamera", cameraNotification.Id);
CurrentSelectedCamera = cameraNotification;
}

Expand All @@ -125,14 +128,14 @@
private async Task OpenDialog(string barcode)
{
var parameters = new DialogParameters<AddProductDialog> { { nameof(AddProductDialog.Barcode), barcode } };
Barcode = string.Empty;
await DialogService.ShowAsync<AddProductDialog>("Purchase Product", parameters, new DialogOptions
{
CloseOnEscapeKey = false,
DisableBackdropClick = true,
CloseButton = false
});

Barcode = string.Empty;
await barcodeInputTextRef.FocusAsync();
}

}

0 comments on commit 2a20f79

Please sign in to comment.