Skip to content

Commit

Permalink
fix(blazorui): resolve event issues in BitNumberField #7015 (#7105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrus-Sushiant authored Mar 10, 2024
1 parent 166358e commit ce791e0
Showing 1 changed file with 14 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -556,13 +542,6 @@ private void SetValue(double value)
{
CurrentValue = GetGenericValue(value);
}

SetDisplayValue();
}

private void SetDisplayValue()
{
_intermediateValue = CurrentValueAsString;
}

private static string? GetCleanValue(string? value)
Expand All @@ -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()
Expand Down

0 comments on commit ce791e0

Please sign in to comment.