AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
24.57k stars 2.12k forks source link

Numeric access keys not working #15957

Open JouriM2 opened 4 weeks ago

JouriM2 commented 4 weeks ago

Here is sample repo: https://github.com/JouriM2/AvDropDownBug It contains simple window with 3 edits and labels to access them.

изображение

implemented as:

    <StackPanel Orientation="Vertical" Margin="20">
        <Label Content="_1 One" Target="edt1"/>
        <TextBox x:Name="edt1"/>

        <Label Content="_2 Two" Target="edt2"/>
        <TextBox x:Name="edt2"/>

        <Label Content="_A Three" Target="edt3"/>
        <TextBox x:Name="edt3"/>

    </StackPanel>

Problems I have:

  1. Number hotkeys not working. Pressing Alt+1 or Alt+2 do nothing. Alt+A works as expected and move focus to edit. If to press mouse on Label itself all three are works. How to use number hotkeys?

  2. After I press Alt on keyboard all hotkeys stay underlined until I press any mouse button inside window (any button, at any point inside window). At same time any keyboard actions do not remove highlighting. It seems like a bug and hotkeys need to be hidden after Alt key released.

Originally posted by @JouriM2 in https://github.com/AvaloniaUI/Avalonia/discussions/15939

stevemonaco commented 4 weeks ago

Moving some details from the originating discussion...

For point 1: https://github.com/AvaloniaUI/Avalonia/blob/f140033e420ee39b16dcc0621d5580f94d5bcb2c/src/Avalonia.Base/Input/AccessKeyHandler.cs#L175-L183

e.Key.ToString() returns "D1" for the key (because of the enum) whereas "_1 One" registers "1" in the hotkey map.

For point 2:

This works as expected if you have a Menu, which is the primary use of AccessText. I'm not sure what the intended design is for out-of-menu access keys. You should be able to press the alt key, release it, and continue pressing access keys (with or without alt held down) to navigate. The non-menu access keys return to normal when the menu is closed.

It can be fixed in this area https://github.com/AvaloniaUI/Avalonia/blob/f140033e420ee39b16dcc0621d5580f94d5bcb2c/src/Avalonia.Base/Input/AccessKeyHandler.cs#L211-L230 by placing the following before the break;. Not sure if there are any side-effects.

if (MainMenu is null)
{
    _owner!.ShowAccessKeys = _showingAccessKeys = false;
}