fix(module: slider): not working under wasm (#415)

Co-authored-by: James Yeung <shunjiey@hotmail.com>
This commit is contained in:
Brian Ding 2020-07-23 15:49:23 +08:00 committed by GitHub
parent 0ca5698620
commit fa60c9c8bf
2 changed files with 21 additions and 5 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Linq.Expressions;
using System.Globalization;
namespace AntDesign.Helpers
{
@ -35,4 +36,17 @@ namespace AntDesign.Helpers
return Expression.Lambda<Func<T, string, string>>(body, p1, p2).Compile();
}
}
internal static class Formatter
{
/// <summary>
/// under WASM mode, when format a double number to percentage, there will be a blank between number and %, '35.00 %'
/// use this method instead to avoid the blank space
/// </summary>
/// <returns></returns>
public static string ToPercentWithoutBlank(double num)
{
return num.ToString("p", CultureInfo.CurrentCulture).Replace(" ", "", StringComparison.Ordinal);
}
}
}

View File

@ -1,4 +1,5 @@
using AntDesign.core.Extensions;
using AntDesign.Helpers;
using AntDesign.JsInterop;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
@ -506,17 +507,18 @@ namespace AntDesign
}
}
private void SetStyle()
{
_rightHandleStyle = string.Format(CultureInfo.CurrentCulture, RightHandleStyleFormat, (RightValue / Max).ToString("p", CultureInfo.CurrentCulture));
_rightHandleStyle = string.Format(CultureInfo.CurrentCulture, RightHandleStyleFormat, Formatter.ToPercentWithoutBlank(RightValue / Max));
if (Range)
{
_trackStyle = string.Format(CultureInfo.CurrentCulture, TrackStyleFormat, (LeftValue / Max).ToString("p", CultureInfo.CurrentCulture), ((RightValue - LeftValue) / Max).ToString("p", CultureInfo.CurrentCulture));
_leftHandleStyle = string.Format(CultureInfo.CurrentCulture, LeftHandleStyleFormat, (LeftValue / Max).ToString("p", CultureInfo.CurrentCulture));
_trackStyle = string.Format(CultureInfo.CurrentCulture, TrackStyleFormat, Formatter.ToPercentWithoutBlank(LeftValue / Max), Formatter.ToPercentWithoutBlank((RightValue - LeftValue) / Max));
_leftHandleStyle = string.Format(CultureInfo.CurrentCulture, LeftHandleStyleFormat, Formatter.ToPercentWithoutBlank(LeftValue / Max));
}
else
{
_trackStyle = string.Format(CultureInfo.CurrentCulture, TrackStyleFormat, "0%", (RightValue / Max).ToString("p", CultureInfo.CurrentCulture));
_trackStyle = string.Format(CultureInfo.CurrentCulture, TrackStyleFormat, "0%", Formatter.ToPercentWithoutBlank(RightValue / Max));
}
StateHasChanged();
@ -524,7 +526,7 @@ namespace AntDesign
private string SetMarkPosition(double key)
{
return (key / Max).ToString("p", CultureInfo.CurrentCulture);
return Formatter.ToPercentWithoutBlank(key / Max);
}
private string IsActiveMark(double key)