diff --git a/src/Core/Components/Base/InputHelpers.cs b/src/Core/Components/Base/InputHelpers.cs index 2a5cc4158b..f4e7a186f9 100644 --- a/src/Core/Components/Base/InputHelpers.cs +++ b/src/Core/Components/Base/InputHelpers.cs @@ -4,7 +4,6 @@ namespace Microsoft.FluentUI.AspNetCore.Components; internal static class InputHelpers { - public static string GetMaxValue() { Type? targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue); @@ -51,9 +50,19 @@ public static string GetMinValue() return value; } - internal static void ValidateIntegerInputs(string? max, string? min) + internal static void ValidateSByteInputs(string? max, string? min) { + var maxValue = Convert.ToSByte(max); + var minValue = Convert.ToSByte(min); + + if (maxValue < minValue) + { + throw new ArgumentException("Signed Integer Max value is smaller than Min value."); + } + } + internal static void ValidateIntegerInputs(string? max, string? min) + { var maxValue = Convert.ToInt32(max); var minValue = Convert.ToInt32(min); @@ -61,7 +70,6 @@ internal static void ValidateIntegerInputs(string? max, string? min) { throw new ArgumentException("Integer Max value is smaller then Min value."); } - } internal static void ValidateLongInputs(string? max, string? min) @@ -137,6 +145,11 @@ internal static void ValidateInputParameters(string? max, string? min) return; //nothing to validate } + if (typeof(TValue) == typeof(sbyte)) + { + ValidateSByteInputs(max, min); + } + if (typeof(TValue) == typeof(int)) { ValidateIntegerInputs(max, min); @@ -149,7 +162,6 @@ internal static void ValidateInputParameters(string? max, string? min) if (typeof(TValue) == typeof(short)) { - ValidateShortInputs(max, min); } @@ -165,7 +177,6 @@ internal static void ValidateInputParameters(string? max, string? min) if (typeof(TValue) == typeof(decimal)) { - ValidateDecimalInputs(max, min); } } diff --git a/src/Core/Components/NumberField/FluentNumberField.razor.cs b/src/Core/Components/NumberField/FluentNumberField.razor.cs index 021e92886b..0eb8a75287 100644 --- a/src/Core/Components/NumberField/FluentNumberField.razor.cs +++ b/src/Core/Components/NumberField/FluentNumberField.razor.cs @@ -79,7 +79,8 @@ private static string GetStepAttributeValue() // Unwrap Nullable, because InputBase already deals with the Nullable aspect // of it for us. We will only get asked to parse the T for nonempty inputs. var targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue); - if (targetType == typeof(int) || + if (targetType == typeof(sbyte) || + targetType == typeof(int) || targetType == typeof(long) || targetType == typeof(short) || targetType == typeof(float) || @@ -119,6 +120,7 @@ protected override bool TryParseValueFromString(string? value, [MaybeNullWhen(fa return value switch { null => null, + sbyte @sbyte => BindConverter.FormatValue(Convert.ToInt16(@sbyte), CultureInfo.InvariantCulture), int @int => BindConverter.FormatValue(@int, CultureInfo.InvariantCulture), long @long => BindConverter.FormatValue(@long, CultureInfo.InvariantCulture), short @short => BindConverter.FormatValue(@short, CultureInfo.InvariantCulture),