Browse Source

focus first item in DropDown on key up/down

Andrey Kunchev 7 years ago
parent
commit
fa8380d92d
1 changed files with 11 additions and 0 deletions
  1. 11 0
      src/Avalonia.Controls/DropDown.cs

+ 11 - 0
src/Avalonia.Controls/DropDown.cs

@@ -2,6 +2,7 @@
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
 using System;
+using System.Linq;
 using Avalonia.Controls.Generators;
 using Avalonia.Controls.Primitives;
 using Avalonia.Controls.Shapes;
@@ -138,6 +139,16 @@ namespace Avalonia.Controls
                     e.Handled = true;
                 }
             }
+            else if (IsDropDownOpen && SelectedIndex < 0 && ItemCount > 0 &&
+                      (e.Key == Key.Up || e.Key == Key.Down))
+            {
+                var firstChild = Presenter?.Panel?.Children.FirstOrDefault(c => c.Focusable);
+                if (firstChild != null)
+                {
+                    firstChild.Focus();
+                    e.Handled = true;
+                }
+            }
         }
 
         /// <inheritdoc/>