浏览代码

Merge branch 'master' into date-picker-control

Steven Kirk 7 年之前
父节点
当前提交
c4b994a9bf

+ 10 - 7
src/Avalonia.Input/Navigation/TabNavigation.cs

@@ -221,17 +221,16 @@ namespace Avalonia.Input.Navigation
                     return parent;
                     return parent;
                 }
                 }
 
 
-                var siblings = parent.GetVisualChildren()
+                var allSiblings = parent.GetVisualChildren()
                     .OfType<IInputElement>()
                     .OfType<IInputElement>()
                     .Where(FocusExtensions.CanFocusDescendants);
                     .Where(FocusExtensions.CanFocusDescendants);
-                var sibling = direction == NavigationDirection.Next ? 
-                    siblings.SkipWhile(x => x != container).Skip(1).FirstOrDefault() : 
-                    siblings.TakeWhile(x => x != container).LastOrDefault();
+                var siblings = direction == NavigationDirection.Next ?
+                    allSiblings.SkipWhile(x => x != container).Skip(1) :
+                    allSiblings.TakeWhile(x => x != container).Reverse();
 
 
-                if (sibling != null)
+                foreach (var sibling in siblings)
                 {
                 {
                     var customNext = GetCustomNext(sibling, direction);
                     var customNext = GetCustomNext(sibling, direction);
-
                     if (customNext.handled)
                     if (customNext.handled)
                     {
                     {
                         return customNext.next;
                         return customNext.next;
@@ -239,13 +238,17 @@ namespace Avalonia.Input.Navigation
 
 
                     if (sibling.CanFocus())
                     if (sibling.CanFocus())
                     {
                     {
-                        next = sibling;
+                        return sibling;
                     }
                     }
                     else
                     else
                     {
                     {
                         next = direction == NavigationDirection.Next ?
                         next = direction == NavigationDirection.Next ?
                             GetFocusableDescendants(sibling, direction).FirstOrDefault() :
                             GetFocusableDescendants(sibling, direction).FirstOrDefault() :
                             GetFocusableDescendants(sibling, direction).LastOrDefault();
                             GetFocusableDescendants(sibling, direction).LastOrDefault();
+                        if(next != null)
+                        {
+                            return next;
+                        }
                     }
                     }
                 }
                 }
 
 

+ 37 - 0
tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs

@@ -80,6 +80,43 @@ namespace Avalonia.Input.UnitTests
             Assert.Equal(next, result);
             Assert.Equal(next, result);
         }
         }
 
 
+        [Fact]
+        public void Next_Skips_Unfocusable_Siblings()
+        {
+            Button current;
+            Button next;
+
+            var top = new StackPanel
+            {
+                Children =
+                {
+                    new StackPanel
+                    {
+                        Children =
+                        {
+                            new Button { Name = "Button1" },
+                            new Button { Name = "Button2" },
+                            new StackPanel
+                            {
+                                Children =
+                                {
+                                    (current = new Button { Name = "Button3" }),
+                                }
+                            },
+                            new TextBlock { Name = "TextBlock" },
+                            (next = new Button { Name = "Button4" }),
+                        }
+                    },
+                    new Button { Name = "Button5" },
+                    new Button { Name = "Button6" },
+                }
+            };
+
+            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
+
+            Assert.Equal(next, result);
+        }
+
         [Fact]
         [Fact]
         public void Next_Continue_Doesnt_Enter_Panel_With_TabNavigation_None()
         public void Next_Continue_Doesnt_Enter_Panel_With_TabNavigation_None()
         {
         {