fix(module: datepicker): RangePicker.OnOpenChange called twice on close (#3307)

This commit is contained in:
Alex Kryvdyk 2023-06-17 20:13:26 +03:00 committed by GitHub
parent ff5dced7cb
commit 53527d5d13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 37 deletions

View File

@ -123,8 +123,8 @@ namespace AntDesign
{
var calendar = CultureInfo.Calendar;
var calendarWeekRule = CultureInfo.DateTimeFormat.CalendarWeekRule;
var date1Week = calendar.GetWeekOfYear(date1,calendarWeekRule, Locale.FirstDayOfWeek);
var date1Week = calendar.GetWeekOfYear(date1, calendarWeekRule, Locale.FirstDayOfWeek);
var date2Week = calendar.GetWeekOfYear(date2, calendarWeekRule, Locale.FirstDayOfWeek);
return index == 0 ? date1Week < date2Week && date1.Year <= date2.Year
: date1.Year >= date2.Year && date1Week > date2Week;
@ -471,28 +471,13 @@ namespace AntDesign
array.SetValue(value, index);
}
var otherIndex = Math.Abs(index - 1);
//if Value was just now instantiated then set the other index to existing DefaultValue
if (isValueInstantiated && DefaultValue != null)
{
var arrayDefault = DefaultValue as Array;
int oppositeIndex = index == 1 ? 0 : 1;
array.SetValue(arrayDefault.GetValue(oppositeIndex), oppositeIndex);
}
_pickerStatus[index].IsValueSelected = true;
if (closeDropdown && !HasTimeInput)
{
if (_pickerStatus[0].SelectedValue is not null
&& _pickerStatus[1].SelectedValue is not null)
{
Close();
}
// if the other DatePickerInput is disabled, then close picker panel
else if (IsDisabled(Math.Abs(index - 1)))
{
Close();
}
array.SetValue(arrayDefault.GetValue(otherIndex), otherIndex);
}
var startDate = array.GetValue(0) as DateTime?;
@ -508,6 +493,15 @@ namespace AntDesign
{
EditContext?.NotifyFieldChanged(FieldIdentifier);
}
_pickerStatus[index].IsValueSelected = true;
if (closeDropdown && !HasTimeInput
&& _pickerStatus[index].SelectedValue is not null
&& (_pickerStatus[otherIndex].SelectedValue is not null || IsDisabled(otherIndex)))
{
Close();
}
}
public override void ClearValue(int index = -1, bool closeDropdown = true)

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@ -462,7 +462,7 @@ namespace AntDesign
return Task.CompletedTask;
}
protected virtual async Task OnSelect(DateTime date, int index, bool switchFocus = true, bool closeDropdown = true)
protected virtual async Task OnSelect(DateTime date, int index)
{
_duringManualInput = false;
@ -478,33 +478,30 @@ namespace AntDesign
{
if (IsValidRange(date, index))
{
var otherIndex = Math.Abs(index - 1);
ChangeValue(date, index, false);
var otherIndex = Math.Abs(index - 1);
if (_pickerStatus[otherIndex].SelectedValue is not null)
{
ChangeValue(_pickerStatus[otherIndex].SelectedValue.Value, otherIndex, closeDropdown);
ChangeValue(_pickerStatus[otherIndex].SelectedValue.Value, otherIndex, true);
}
ChangeValue(date, index, closeDropdown);
}
}
}
else if (!HasTimeInput)
{
ChangeValue(date, index, closeDropdown);
ChangeValue(date, index, true);
}
// auto focus the other input
if (switchFocus)
if (IsRange && !HasTimeInput)
{
if (IsRange && !HasTimeInput)
{
await SwitchFocus(index);
}
else
{
await Focus(index);
}
await SwitchFocus(index);
}
else
{
await Focus(index);
}
}
else
@ -829,7 +826,7 @@ namespace AntDesign
if (string.IsNullOrEmpty(Format))
format = _pickerStatus[index].InitPicker switch
{
DatePickerType.Week => $"{Locale.Lang.YearFormat}-{CultureInfo.Calendar.GetWeekOfYear(value,CultureInfo.DateTimeFormat.CalendarWeekRule, Locale.FirstDayOfWeek)}'{Locale.Lang.Week}'",
DatePickerType.Week => $"{Locale.Lang.YearFormat}-{CultureInfo.Calendar.GetWeekOfYear(value, CultureInfo.DateTimeFormat.CalendarWeekRule, Locale.FirstDayOfWeek)}'{Locale.Lang.Week}'",
DatePickerType.Quarter => $"{Locale.Lang.YearFormat}-{DateHelper.GetDayOfQuarter(value)}",
_ => InternalFormat,
};