Skip to content

Commit

Permalink
Revert "Merge pull request AvaloniaUI#7963 from AvaloniaUI/disabled-i…
Browse files Browse the repository at this point in the history
…tems-should-not-be-selectable-with-keyboard"

This reverts commit fa7294a.
  • Loading branch information
danwalmsley committed May 10, 2022
1 parent 86d469a commit 9d41fe9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 84 deletions.
20 changes: 12 additions & 8 deletions src/Avalonia.Controls/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,18 +429,22 @@ private void SelectFocusedItem()

private void SelectNext()
{
if (ItemCount >= 1)
{
MoveSelection(NavigationDirection.Next, WrapSelection);
}
int next = SelectedIndex + 1;

if (next >= ItemCount)
next = 0;

SelectedIndex = next;
}

private void SelectPrev()
{
if (ItemCount >= 1)
{
MoveSelection(NavigationDirection.Previous, WrapSelection);
}
int prev = SelectedIndex - 1;

if (prev < 0)
prev = ItemCount - 1;

SelectedIndex = prev;
}
}
}
1 change: 1 addition & 0 deletions src/Avalonia.Controls/ItemsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ protected static IInputElement GetNextControl(
do
{
result = container.GetControl(direction, c, wrap);
from = from ?? result;

if (result != null &&
result.Focusable &&
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/StackPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected virtual IInputElement GetControlInDirection(NavigationDirection direct
index = Children.Count - 1;
break;
case NavigationDirection.Next:
++index;
if (index != -1) ++index;
break;
case NavigationDirection.Previous:
if (index != -1) --index;
Expand Down
75 changes: 0 additions & 75 deletions tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,81 +36,6 @@ public void Clicking_On_Control_Toggles_IsDropDownOpen()
Assert.False(target.IsDropDownOpen);
}

[Fact]
public void WrapSelection_Should_Work()
{
using (UnitTestApplication.Start(TestServices.RealFocus))
{
var items = new[]
{
new ComboBoxItem() { Content = "bla" },
new ComboBoxItem() { Content = "dd" },
new ComboBoxItem() { Content = "sdf", IsEnabled = false }
};
var target = new ComboBox
{
Items = items,
Template = GetTemplate(),
WrapSelection = true
};
var root = new TestRoot(target);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
target.Focus();
Assert.Equal(target.SelectedIndex, -1);
Assert.True(target.IsFocused);
target.RaiseEvent(new KeyEventArgs
{
RoutedEvent = InputElement.KeyDownEvent,
Key = Key.Up,
});
Assert.Equal(target.SelectedIndex, 1);
target.RaiseEvent(new KeyEventArgs
{
RoutedEvent = InputElement.KeyDownEvent,
Key = Key.Down,
});
Assert.Equal(target.SelectedIndex, 0);
}
}

[Fact]
public void Focuses_Next_Item_On_Key_Down()
{
using (UnitTestApplication.Start(TestServices.RealFocus))
{
var items = new[]
{
new ComboBoxItem() { Content = "bla" },
new ComboBoxItem() { Content = "dd", IsEnabled = false },
new ComboBoxItem() { Content = "sdf" }
};
var target = new ComboBox
{
Items = items,
Template = GetTemplate()
};
var root = new TestRoot(target);
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
target.Focus();
Assert.Equal(target.SelectedIndex, -1);
Assert.True(target.IsFocused);
target.RaiseEvent(new KeyEventArgs
{
RoutedEvent = InputElement.KeyDownEvent,
Key = Key.Down,
});
Assert.Equal(target.SelectedIndex, 0);
target.RaiseEvent(new KeyEventArgs
{
RoutedEvent = InputElement.KeyDownEvent,
Key = Key.Down,
});
Assert.Equal(target.SelectedIndex, 2);
}
}

[Fact]
public void SelectionBoxItem_Is_Rectangle_With_VisualBrush_When_Selection_Is_Control()
{
Expand Down

0 comments on commit 9d41fe9

Please sign in to comment.