feat: fix various issue upon click or tab.
This commit is contained in:
@@ -7,6 +7,8 @@ using Avalonia.Controls.Primitives;
|
|||||||
using Avalonia.Data;
|
using Avalonia.Data;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.VisualTree;
|
||||||
|
using Irihi.Avalonia.Shared.Common;
|
||||||
using Irihi.Avalonia.Shared.Contracts;
|
using Irihi.Avalonia.Shared.Contracts;
|
||||||
using Irihi.Avalonia.Shared.Helpers;
|
using Irihi.Avalonia.Shared.Helpers;
|
||||||
|
|
||||||
@@ -25,6 +27,7 @@ public class DatePicker: DatePickerBase, IClearControl
|
|||||||
private Button? _button;
|
private Button? _button;
|
||||||
private TextBox? _textBox;
|
private TextBox? _textBox;
|
||||||
private CalendarView? _calendar;
|
private CalendarView? _calendar;
|
||||||
|
private Popup? _popup;
|
||||||
|
|
||||||
public static readonly StyledProperty<DateTime?> SelectedDateProperty = AvaloniaProperty.Register<DatePicker, DateTime?>(
|
public static readonly StyledProperty<DateTime?> SelectedDateProperty = AvaloniaProperty.Register<DatePicker, DateTime?>(
|
||||||
nameof(SelectedDate), defaultBindingMode: BindingMode.TwoWay);
|
nameof(SelectedDate), defaultBindingMode: BindingMode.TwoWay);
|
||||||
@@ -66,7 +69,7 @@ public class DatePicker: DatePickerBase, IClearControl
|
|||||||
CalendarView.DateSelectedEvent.RemoveHandler(OnDateSelected, _calendar);
|
CalendarView.DateSelectedEvent.RemoveHandler(OnDateSelected, _calendar);
|
||||||
|
|
||||||
_button = e.NameScope.Find<Button>(PART_Button);
|
_button = e.NameScope.Find<Button>(PART_Button);
|
||||||
e.NameScope.Find<Popup>(PART_Popup);
|
_popup = e.NameScope.Find<Popup>(PART_Popup);
|
||||||
_textBox = e.NameScope.Find<TextBox>(PART_TextBox);
|
_textBox = e.NameScope.Find<TextBox>(PART_TextBox);
|
||||||
_calendar = e.NameScope.Find<CalendarView>(PART_Calendar);
|
_calendar = e.NameScope.Find<CalendarView>(PART_Calendar);
|
||||||
|
|
||||||
@@ -172,11 +175,17 @@ public class DatePicker: DatePickerBase, IClearControl
|
|||||||
SetCurrentValue(IsDropdownOpenProperty, true);
|
SetCurrentValue(IsDropdownOpenProperty, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnLostFocus(RoutedEventArgs e)
|
/// <inheritdoc/>
|
||||||
|
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnLostFocus(e);
|
base.OnPointerPressed(e);
|
||||||
SetCurrentValue(IsDropdownOpenProperty, false);
|
if(!e.Handled && e.Source is Visual source)
|
||||||
SetSelectedDate();
|
{
|
||||||
|
if (_popup?.IsInsidePopup(source) == true)
|
||||||
|
{
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnKeyDown(KeyEventArgs e)
|
protected override void OnKeyDown(KeyEventArgs e)
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public class DateRangePicker : DatePickerBase, IClearControl
|
|||||||
private bool? _start;
|
private bool? _start;
|
||||||
private CalendarView? _startCalendar;
|
private CalendarView? _startCalendar;
|
||||||
private TextBox? _startTextBox;
|
private TextBox? _startTextBox;
|
||||||
|
private Popup? _popup;
|
||||||
|
|
||||||
static DateRangePicker()
|
static DateRangePicker()
|
||||||
{
|
{
|
||||||
@@ -139,7 +140,7 @@ public class DateRangePicker : DatePickerBase, IClearControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
_button = e.NameScope.Find<Button>(PART_Button);
|
_button = e.NameScope.Find<Button>(PART_Button);
|
||||||
e.NameScope.Find<Popup>(PART_Popup);
|
_popup = e.NameScope.Find<Popup>(PART_Popup);
|
||||||
_startCalendar = e.NameScope.Find<CalendarView>(PART_StartCalendar);
|
_startCalendar = e.NameScope.Find<CalendarView>(PART_StartCalendar);
|
||||||
_endCalendar = e.NameScope.Find<CalendarView>(PART_EndCalendar);
|
_endCalendar = e.NameScope.Find<CalendarView>(PART_EndCalendar);
|
||||||
_startTextBox = e.NameScope.Find<TextBox>(PART_StartTextBox);
|
_startTextBox = e.NameScope.Find<TextBox>(PART_StartTextBox);
|
||||||
@@ -399,6 +400,19 @@ public class DateRangePicker : DatePickerBase, IClearControl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnPointerPressed(e);
|
||||||
|
if(!e.Handled && e.Source is Visual source)
|
||||||
|
{
|
||||||
|
if (_popup?.IsInsidePopup(source) == true)
|
||||||
|
{
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnTextBoxGetFocus(object? sender, GotFocusEventArgs e)
|
private void OnTextBoxGetFocus(object? sender, GotFocusEventArgs e)
|
||||||
{
|
{
|
||||||
if (_startCalendar is not null && _startCalendar?.Mode == CalendarViewMode.Month)
|
if (_startCalendar is not null && _startCalendar?.Mode == CalendarViewMode.Month)
|
||||||
@@ -418,5 +432,32 @@ public class DateRangePicker : DatePickerBase, IClearControl
|
|||||||
SetCurrentValue(IsDropdownOpenProperty, true);
|
SetCurrentValue(IsDropdownOpenProperty, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnKeyDown(KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Key == Key.Escape)
|
||||||
|
{
|
||||||
|
SetCurrentValue(IsDropdownOpenProperty, false);
|
||||||
|
e.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.Key == Key.Down)
|
||||||
|
{
|
||||||
|
SetCurrentValue(IsDropdownOpenProperty, true);
|
||||||
|
e.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.Key == Key.Tab)
|
||||||
|
{
|
||||||
|
if(_endTextBox?.IsFocused == true)
|
||||||
|
{
|
||||||
|
SetCurrentValue(IsDropdownOpenProperty, false);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnKeyDown(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user