Merge pull request #697 from irihitech/autocomplete
Fix AutoCompleteBox focus behavior in Avalonia 11.3
This commit is contained in:
@@ -1,14 +1,11 @@
|
|||||||
using System.Diagnostics;
|
using Avalonia.Controls.Templates;
|
||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Controls.Primitives;
|
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Irihi.Avalonia.Shared.Contracts;
|
using Irihi.Avalonia.Shared.Contracts;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
public class AutoCompleteBox: Avalonia.Controls.AutoCompleteBox, IClearControl
|
public class AutoCompleteBox : Avalonia.Controls.AutoCompleteBox, IClearControl
|
||||||
{
|
{
|
||||||
static AutoCompleteBox()
|
static AutoCompleteBox()
|
||||||
{
|
{
|
||||||
@@ -20,23 +17,24 @@ public class AutoCompleteBox: Avalonia.Controls.AutoCompleteBox, IClearControl
|
|||||||
AddHandler(PointerPressedEvent, OnBoxPointerPressed, RoutingStrategies.Tunnel);
|
AddHandler(PointerPressedEvent, OnBoxPointerPressed, RoutingStrategies.Tunnel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
SetCurrentValue(SelectedItemProperty, null);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnBoxPointerPressed(object? sender, PointerPressedEventArgs e)
|
private void OnBoxPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||||
{
|
{
|
||||||
if (Equals(sender, this) && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
|
if (Equals(sender, this) && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed && IsDropDownOpen == false)
|
||||||
{
|
|
||||||
SetCurrentValue(IsDropDownOpenProperty, true);
|
SetCurrentValue(IsDropDownOpenProperty, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnGotFocus(GotFocusEventArgs e)
|
protected override void OnGotFocus(GotFocusEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnGotFocus(e);
|
base.OnGotFocus(e);
|
||||||
if (IsDropDownOpen) return;
|
// If the focus is set by pointer navigation, it is handled by PointerPressed, do not open the dropdown.
|
||||||
SetCurrentValue(IsDropDownOpenProperty, true);
|
if (e.NavigationMethod == NavigationMethod.Pointer) return;
|
||||||
}
|
if (!this.GetTemplateChildren().Contains(e.Source)) return;
|
||||||
|
// If the focus is set by keyboard navigation, open the dropdown.
|
||||||
public void Clear()
|
if (IsDropDownOpen == false) SetCurrentValue(IsDropDownOpenProperty, true);
|
||||||
{
|
|
||||||
SetCurrentValue(SelectedItemProperty, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user