Browse Source
Do not match access keys on input elements that are not effectively enabled. (#13185)
pull/13255/head
Boyd Patterson
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
26 additions and
1 deletions
-
src/Avalonia.Base/Input/AccessKeyHandler.cs
-
tests/Avalonia.Base.UnitTests/Input/AccessKeyHandlerTests.cs
|
|
|
@ -183,7 +183,8 @@ namespace Avalonia.Input |
|
|
|
var text = e.Key.ToString(); |
|
|
|
var matches = _registered |
|
|
|
.Where(x => string.Equals(x.AccessKey, text, StringComparison.OrdinalIgnoreCase) |
|
|
|
&& x.Element.IsEffectivelyVisible) |
|
|
|
&& x.Element.IsEffectivelyVisible |
|
|
|
&& x.Element.IsEffectivelyEnabled) |
|
|
|
.Select(x => x.Element); |
|
|
|
|
|
|
|
// If the menu is open, only match controls in the menu's visual tree.
|
|
|
|
|
|
|
|
@ -165,6 +165,30 @@ namespace Avalonia.Base.UnitTests.Input |
|
|
|
Assert.Equal(1, raised); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Not_Raise_AccessKeyPressed_For_Registered_Access_Key_When_Not_Effectively_Enabled() |
|
|
|
{ |
|
|
|
var button = new Button(); |
|
|
|
var root = new TestRoot(button) { IsEnabled = false }; |
|
|
|
var target = new AccessKeyHandler(); |
|
|
|
var raised = 0; |
|
|
|
|
|
|
|
target.SetOwner(root); |
|
|
|
target.Register('A', button); |
|
|
|
button.AddHandler(AccessKeyHandler.AccessKeyPressedEvent, (s, e) => ++raised); |
|
|
|
|
|
|
|
KeyDown(root, Key.LeftAlt); |
|
|
|
Assert.Equal(0, raised); |
|
|
|
|
|
|
|
KeyDown(root, Key.A, KeyModifiers.Alt); |
|
|
|
Assert.Equal(0, raised); |
|
|
|
|
|
|
|
KeyUp(root, Key.A, KeyModifiers.Alt); |
|
|
|
KeyUp(root, Key.LeftAlt); |
|
|
|
|
|
|
|
Assert.Equal(0, raised); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Open_MainMenu_On_Alt_KeyUp() |
|
|
|
{ |
|
|
|
|