From f50223cb0dcf988601c60fb0a9088c761b35f7bf Mon Sep 17 00:00:00 2001 From: sdoroff Date: Mon, 12 Feb 2018 18:10:00 -0500 Subject: [PATCH 1/3] Fixed a bug in tab navigation TabNavigation.GetFirstInNextContainer would only check one sibling and would move up to the parent if the first sibling was not focuable --- src/Avalonia.Input/Navigation/TabNavigation.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Input/Navigation/TabNavigation.cs b/src/Avalonia.Input/Navigation/TabNavigation.cs index 6e077e887f..a9d5b83073 100644 --- a/src/Avalonia.Input/Navigation/TabNavigation.cs +++ b/src/Avalonia.Input/Navigation/TabNavigation.cs @@ -221,17 +221,16 @@ namespace Avalonia.Input.Navigation return parent; } - var siblings = parent.GetVisualChildren() + var allSiblings = parent.GetVisualChildren() .OfType() .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); - if (customNext.handled) { return customNext.next; @@ -239,13 +238,17 @@ namespace Avalonia.Input.Navigation if (sibling.CanFocus()) { - next = sibling; + return sibling; } else { next = direction == NavigationDirection.Next ? GetFocusableDescendants(sibling, direction).FirstOrDefault() : GetFocusableDescendants(sibling, direction).LastOrDefault(); + if(next != null) + { + return next; + } } } From 7969749cd1ca55d3e9e81c685c9e16408657e61b Mon Sep 17 00:00:00 2001 From: sdoroff Date: Mon, 12 Feb 2018 20:06:55 -0500 Subject: [PATCH 2/3] Added a unit test --- .../KeyboardNavigationTests_Tab.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs b/tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs index ad70dcd470..60d31145cf 100644 --- a/tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs +++ b/tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs @@ -80,6 +80,43 @@ namespace Avalonia.Input.UnitTests Assert.Equal(next, result); } + [Fact] + public void Next_Skips_Unfocasable_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] public void Next_Continue_Doesnt_Enter_Panel_With_TabNavigation_None() { From 3891cbf06da28f1df68ec160e86c82db2973f606 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 24 Feb 2018 00:55:39 +0100 Subject: [PATCH 3/3] Fixed spelling. --- tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs b/tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs index 60d31145cf..e779652322 100644 --- a/tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs +++ b/tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs @@ -81,7 +81,7 @@ namespace Avalonia.Input.UnitTests } [Fact] - public void Next_Skips_Unfocasable_Siblings() + public void Next_Skips_Unfocusable_Siblings() { Button current; Button next;