Skip to content

Commit

Permalink
fix(module: input-number): default value binding (#1871)
Browse files Browse the repository at this point in the history
* fix(module: input-number): default value binding

* fix default value
  • Loading branch information
ElderJames authored Aug 26, 2021
1 parent bdcb4ee commit dc35907
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions components/input-number/InputNumber.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ public TValue Step
private int? _decimalPlaces;

[Parameter]
public TValue DefaultValue { get; set; }
public TValue DefaultValue
{
get => _defaultValue;
set
{
_defaultValue = value;
_hasDefaultValue = true;
}
}

[Parameter]
public TValue Max { get; set; }
Expand All @@ -67,7 +75,7 @@ public TValue Step
public EventCallback<TValue> OnChange { get; set; }

private readonly bool _isNullable;

private bool _hasDefaultValue;

private readonly Func<TValue, TValue, TValue> _increaseFunc;
private readonly Func<TValue, TValue, TValue> _decreaseFunc;
Expand Down Expand Up @@ -150,6 +158,7 @@ public TValue Step
private readonly int _interval = 200;
private CancellationTokenSource _increaseTokenSource;
private CancellationTokenSource _decreaseTokenSource;
private TValue _defaultValue;

public InputNumber()
{
Expand Down Expand Up @@ -227,7 +236,11 @@ protected override void OnInitialized()


SetClass();
CurrentValue = Value ?? DefaultValue;

if (_hasDefaultValue && EqualityComparer<TValue>.Default.Equals(Value, default))
{
CurrentValue = _defaultValue;
}
}

/// <summary>
Expand Down

0 comments on commit dc35907

Please sign in to comment.