Skip to content

Commit 2f78a5d

Browse files
authored
Refactor OTPInput and GoogleMap components (#69)
Updated `NotifyChangesAsync` in `OTPInput` to fix formatting in the `if` condition for better readability. Removed unnecessary `Console.WriteLine` from `OnInput` and `OnScriptLoad` methods to clean up debugging output. Refactored `OnKeyUp` in `OTPInput` to make it asynchronous, ensuring all `JSRuntime.InvokeVoidAsync` calls are properly awaited. Added a call to `NotifyChangesAsync` after handling the "Backspace" key. Improved handling of "ArrowLeft" and "ArrowRight" keys with awaited asynchronous operations.
1 parent 109c6cf commit 2f78a5d

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

BlazorExpress.Bulma/Components/Form/OTPInput/OTPInput.razor.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,12 @@ private async Task NotifyChangesAsync()
4646
var otpValue = string.Join(string.Empty, otpValues);
4747
await OnOTPChanged.InvokeAsync(otpValue);
4848

49-
if (otpValue.Length == Length
50-
&& !otpValues.Any(string.IsNullOrWhiteSpace))
49+
if (otpValue.Length == Length && !otpValues.Any(string.IsNullOrWhiteSpace))
5150
await OnOTPCompleted.InvokeAsync(otpValue);
5251
}
5352

5453
private async Task OnInput(ChangeEventArgs e, int index)
5554
{
56-
Console.WriteLine($"OnInput: {e.Value}");
57-
5855
var currentValue = otpValues[index] ?? "";
5956
var newValue = new string(e.Value?.ToString()?.Where(char.IsDigit)?.ToArray());
6057

@@ -84,20 +81,25 @@ private async Task OnInput(ChangeEventArgs e, int index)
8481
await NotifyChangesAsync();
8582
}
8683

87-
private void OnKeyUp(KeyboardEventArgs e, int index)
84+
private async Task OnKeyUp(KeyboardEventArgs e, int index)
8885
{
8986
// Handle backspace key to clear the current input and focus on the previous one
9087
if (e.Key == "Backspace" && index > 0)
9188
{
9289
otpValues[index] = string.Empty;
93-
JSRuntime.InvokeVoidAsync(JsInteropUtils.FocusElement, GetInputId(index - 1));
90+
await JSRuntime.InvokeVoidAsync(JsInteropUtils.FocusElement, GetInputId(index - 1));
91+
92+
// Notify changes
93+
await NotifyChangesAsync();
9494
}
9595

9696
// Handle left arrow key to focus on the previous input
97-
if (e.Key == "ArrowLeft" && index > 0) JSRuntime.InvokeVoidAsync(JsInteropUtils.FocusElement, GetInputId(index - 1));
97+
if (e.Key == "ArrowLeft" && index > 0)
98+
await JSRuntime.InvokeVoidAsync(JsInteropUtils.FocusElement, GetInputId(index - 1));
9899

99100
// Handle right arrow key to focus on the next input
100-
if (e.Key == "ArrowRight" && index < Length - 1) JSRuntime.InvokeVoidAsync(JsInteropUtils.FocusElement, GetInputId(index + 1));
101+
if (e.Key == "ArrowRight" && index < Length - 1)
102+
await JSRuntime.InvokeVoidAsync(JsInteropUtils.FocusElement, GetInputId(index + 1));
101103
}
102104

103105
#endregion

BlazorExpress.Bulma/Components/Maps/GoogleMap.razor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public ValueTask UpdateMarkersAsync(IEnumerable<GoogleMapMarker> markers)
7272

7373
private void OnScriptLoad()
7474
{
75-
Console.WriteLine("OnScriptLoad called...");
7675
Task.Run(async () => await JSRuntime.InvokeVoidAsync(GoogleMapJsInterop.Initialize, Id, Zoom, Center, Markers, Clickable, objRef));
7776
}
7877

0 commit comments

Comments
 (0)