dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.26k stars 1.76k forks source link

Add Accelerators to all Visual Elements #16202

Open PureWeen opened 1 year ago

PureWeen commented 1 year ago

Description

We've added Accelerators to MenuItems https://github.com/dotnet/maui/issues/5211.

This spec proposes adding Accelerators to VisualElement. WinUI and Catalyst both support Accelerators at the base view level.

This spec is partially in response to https://github.com/dotnet/maui/issues/12004 where Accelerators will give users much more fine-grained control at the view level vs at a global level.

One of the primary reasons to use Accelerators over a Generic keyboard listener, is that this this lets the OS know what KeyCommands you've implemented short cut behavior against. With this information the OS can provide information to readers and better visual hints about available commands.

(Public) API Changes

VisualElement

Properties

API Description
Accelerators Bindable Property that let's you set as many Accelerators as you want.

Usage Scenarios

<StackLayout>
     <StackLayout.Accelerators>
                 <Accelerator Invoked="OnInvoked" Key="f" Modifiers="ctrl+space">
     </StackLayout.Accelertors>
</StackLayout>

Backward Compatibility

N/A

Difficulty

Medium

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

egvijayanand commented 11 months ago

Referring to this issue here: #18782

More details in the comments, AccessKey property.

taublast commented 8 months ago

Why not capture all keyboard keys globally at App level, then every VisualElement can subscribe to them/whatever?
I have a working implementation for such capture in MAUI for Windows and MacCatalist, it could serve as a base. https://github.com/taublast/DrawnUi.Maui/tree/main/src/Engine/Features/Keyboard

PureWeen commented 2 days ago

Why not capture all keyboard keys globally at App level, then every VisualElement can subscribe to them/whatever? I have a working implementation for such capture in MAUI for Windows and MacCatalist, it could serve as a base. https://github.com/taublast/DrawnUi.Maui/tree/main/src/Engine/Features/Keyboard

Accelerators are a very specific concept that doesn't really map to a global listener.

For example, WinUI has a specific KeyboardAcccelerator property on the UIElement itself https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.uielement.keyboardaccelerators?view=winrt-26100.

The reason for this is that this now tells the OS the combination of keys that are associated with this element.

If you were to do this via a global listener then this isn't discoverable by the OS. Doing accelerators via the correct APIs is necessary for accessibility and discoverability.

Similarly all UIResponders on iOS have https://developer.apple.com/documentation/uikit/uiresponder/1621141-keycommands

Handling key combinations at the app level isn't going to be implicitly discoverable