diff --git a/src/BlazorUI/Bit.BlazorUI/Components/Inputs/NumberField/BitNumberField.razor.cs b/src/BlazorUI/Bit.BlazorUI/Components/Inputs/NumberField/BitNumberField.razor.cs index 7ca65b4935..edcb966f56 100644 --- a/src/BlazorUI/Bit.BlazorUI/Components/Inputs/NumberField/BitNumberField.razor.cs +++ b/src/BlazorUI/Bit.BlazorUI/Components/Inputs/NumberField/BitNumberField.razor.cs @@ -329,6 +329,16 @@ protected override void RegisterCssStyles() StyleBuilder.Register(() => _hasFocus ? Styles?.Focused : string.Empty); } + protected override Task OnInitializedAsync() + { + if ((ValueHasBeenSet is false || CurrentValue is null) && DefaultValue is not null) + { + SetValue(GetDoubleValueOrDefault(DefaultValue).GetValueOrDefault()); + } + + return base.OnInitializedAsync(); + } + protected override async Task OnParametersSetAsync() { if (_internalMin.HasValue is false) @@ -349,15 +359,6 @@ protected override async Task OnParametersSetAsync() _precision = Precision is not null ? Precision.Value : CalculatePrecision(Step); - if (ValueHasBeenSet is false) - { - SetValue(GetDoubleValueOrDefault(DefaultValue).GetValueOrDefault()); - } - else - { - SetDisplayValue(); - } - await base.OnParametersSetAsync(); } @@ -460,21 +461,6 @@ private async Task HandleOnKeyDown(KeyboardEventArgs e) } break; - case "Enter": - if (_intermediateValue == CurrentValueAsString) break; - - var isNumber = double.TryParse(_intermediateValue, out var numericValue); - if (isNumber) - { - SetValue(numericValue); - await OnChange.InvokeAsync(CurrentValue); - } - else - { - SetDisplayValue(); - } - break; - default: break; } @@ -556,13 +542,6 @@ private void SetValue(double value) { CurrentValue = GetGenericValue(value); } - - SetDisplayValue(); - } - - private void SetDisplayValue() - { - _intermediateValue = CurrentValueAsString; } private static string? GetCleanValue(string? value) @@ -588,15 +567,10 @@ private async Task CheckIntermediateValueAndSetValue() if (_intermediateValue == CurrentValueAsString) return; var isNumber = double.TryParse(_intermediateValue, out var numericValue); - if (isNumber) - { - SetValue(numericValue); - await OnChange.InvokeAsync(CurrentValue); - } - else - { - SetDisplayValue(); - } + if (isNumber is false) return; + + SetValue(numericValue); + await OnChange.InvokeAsync(CurrentValue); } private double GetMaxValue()