diff --git a/src/Connected.Components.Showcase.Runner/Pages/Index.razor b/src/Connected.Components.Showcase.Runner/Pages/Index.razor index a24aa01..4de7880 100644 --- a/src/Connected.Components.Showcase.Runner/Pages/Index.razor +++ b/src/Connected.Components.Showcase.Runner/Pages/Index.razor @@ -8,20 +8,20 @@ + diff --git a/src/Connected.Components/Components/InputNumber.razor.cs b/src/Connected.Components/Components/InputNumber.razor.cs index 7ec19f2..5cf64ef 100644 --- a/src/Connected.Components/Components/InputNumber.razor.cs +++ b/src/Connected.Components/Components/InputNumber.razor.cs @@ -3,8 +3,6 @@ using Connected.Utilities; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using System.Numerics; -using System.Runtime.CompilerServices; -using static Connected.Colors; namespace Connected.Components; public partial class InputNumber:InputBase where NumberType : INumber @@ -18,7 +16,7 @@ public partial class InputNumber:InputBase where NumberType : INumbe } set { - _step = CalculateStep(value); + _step=value; } } @@ -29,7 +27,7 @@ public partial class InputNumber:InputBase where NumberType : INumbe { double num = (double)Convert.ChangeType(Value, typeof(double)); num += _step; - Value = (NumberType)Convert.ChangeType(num, typeof(NumberType)); + Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(num, typeof(NumberType))); await ValueChanged.InvokeAsync(Value); } @@ -37,12 +35,12 @@ public partial class InputNumber:InputBase where NumberType : INumbe { double num = (double)Convert.ChangeType(Value, typeof(double)); num -= _step; - Value = (NumberType)Convert.ChangeType(num, typeof(NumberType)); + Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(num, typeof(NumberType))); await ValueChanged.InvokeAsync(Value); } protected async Task OnMouseWheel(WheelEventArgs obj) { - if (DisableMouseWheel==false) + if (!DisableMouseWheel) { if (!obj.ShiftKey || Disabled || Readonly) return; @@ -57,8 +55,20 @@ public partial class InputNumber:InputBase where NumberType : INumbe } } + private NumberType _value; + [Parameter] - public NumberType Value { get; set; } + public NumberType Value + { + get + { + return _value; + } + set + { + _value = AdjustDecimalPlaces(value); + } + } [Parameter] public int DecimalPlaces { get; set; } =0; @@ -67,43 +77,18 @@ public partial class InputNumber:InputBase where NumberType : INumbe [Parameter] public EventCallback ValueChanged { get; set; } - public async Task ChangeValueAsync(ChangeEventArgs args) + public async Task ChangeValueAsync(ChangeEventArgs args) { if (args.Value is not null) { NumberType value = (NumberType)Convert.ChangeType(args.Value, typeof(NumberType)); - if (value.ToString().Length > 0) + if (value.ToString().Length <= 0) { - value = AdjustDecimalPlaces(value); - //await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(value, typeof(NumberType))); - } - else - { value = (NumberType)Convert.ChangeType(0, typeof(NumberType)); - //await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(0, typeof(NumberType))); - } - Value = value; - await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(Value, typeof(NumberType))); - } - } - - private double CalculateStep(double step) - { - double CalculatedStep = 1; - if (DecimalPlaces > 0) - { - var CurrentStepDecmalPlaces = Helper.GetDecimalPlaces(step); - - if (CurrentStepDecmalPlaces > DecimalPlaces) - { - for (int i = 0; i < DecimalPlaces; i++) - { - CalculatedStep = CalculatedStep / 10; - } } + await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(AdjustDecimalPlaces(value), typeof(NumberType))); } - return CalculatedStep; } private NumberType AdjustDecimalPlaces(NumberType value) diff --git a/src/Connected.Components/Components/InputText.razor b/src/Connected.Components/Components/InputText.razor index 360bfe5..3a848fc 100644 --- a/src/Connected.Components/Components/InputText.razor +++ b/src/Connected.Components/Components/InputText.razor @@ -5,25 +5,14 @@
@if (NumOfRows==1) { - @if (!IsPassword) - { - - } else - { - - } + } else {