feat(module: confirm): add AutoFocusButton options for the open method in confirm service (#2398)

* fix decimal conversion

* Fix Culture Decimal Separator

* feat(ConfirmService) Allow choose AutoFocusButton

* Update components/modal/confirmDialog/ConfirmService.cs

Co-authored-by: James Yeung <shunjiey@hotmail.com>

* Fix after add Nullable to ConfirmAutoFocusButton

* Fix format in code

Co-authored-by: James Yeung <shunjiey@hotmail.com>
This commit is contained in:
jp-rl 2022-04-15 03:45:08 +02:00 committed by James Yeung
parent 5e85c7c649
commit a97828e673
3 changed files with 12 additions and 5 deletions

View File

@ -87,7 +87,7 @@ namespace AntDesign
throw new FormatException();
}
_value = int.Parse(value.Substring(0, index), CultureInfo.InvariantCulture);
_value = decimal.Parse(value.Substring(0, index), CultureInfo.InvariantCulture);
if (index == value.Length)
{

View File

@ -34,15 +34,16 @@ namespace AntDesign
set
{
_step = value;
NumberFormatInfo nfi = CultureInfo.NumberFormat;
var stepStr = _step.ToString();
if (string.IsNullOrEmpty(_format))
{
_format = string.Join('.', stepStr.Split('.').Select(n => new string('0', n.Length)));
_format = string.Join('.', stepStr.Split(nfi.NumberDecimalSeparator).Select(n => new string('0', n.Length)));
}
else
{
if (stepStr.IndexOf('.') > 0)
_decimalPlaces = stepStr.Length - stepStr.IndexOf('.') - 1;
if (stepStr.IndexOf(nfi.NumberDecimalSeparator) > 0)
_decimalPlaces = stepStr.Length - stepStr.IndexOf(nfi.NumberDecimalSeparator) - 1;
else
_decimalPlaces = 0;
}

View File

@ -22,13 +22,15 @@ namespace AntDesign
/// <param name="confirmButtons">the buttons of dialog</param>
/// <param name="confirmIcon">the icon of dialog</param>
/// <param name="options">the configuration options for dialog</param>
/// <param name="autoFocusButton">the autofocus button</param>
/// <returns></returns>
public async Task<ConfirmResult> Show(
OneOf<string, RenderFragment> content,
OneOf<string, RenderFragment> title,
ConfirmButtons confirmButtons,
ConfirmIcon confirmIcon,
ConfirmButtonOptions options)
ConfirmButtonOptions options,
ConfirmAutoFocusButton? autoFocusButton = ConfirmAutoFocusButton.Ok)
{
if (options == null) throw new ArgumentNullException(nameof(options));
ConfirmOptions confirmOptions = new ConfirmOptions()
@ -37,6 +39,10 @@ namespace AntDesign
ConfirmButtons = confirmButtons,
ConfirmIcon = confirmIcon,
};
if (autoFocusButton != null)
confirmOptions.AutoFocusButton = (ConfirmAutoFocusButton)autoFocusButton;
if (title.IsT0)
{
confirmOptions.Title = title.AsT0;