Browse Source
Merge branch 'master' into date-picker-control
pull/1367/head
Steven Kirk
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
47 additions and
7 deletions
-
src/Avalonia.Input/Navigation/TabNavigation.cs
-
tests/Avalonia.Input.UnitTests/KeyboardNavigationTests_Tab.cs
|
|
|
@ -221,17 +221,16 @@ namespace Avalonia.Input.Navigation |
|
|
|
return parent; |
|
|
|
} |
|
|
|
|
|
|
|
var siblings = parent.GetVisualChildren() |
|
|
|
var allSiblings = parent.GetVisualChildren() |
|
|
|
.OfType<IInputElement>() |
|
|
|
.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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -80,6 +80,43 @@ namespace Avalonia.Input.UnitTests |
|
|
|
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] |
|
|
|
public void Next_Continue_Doesnt_Enter_Panel_With_TabNavigation_None() |
|
|
|
{ |
|
|
|
|