MudHotkey: Add new component for handling hotkeys#12079
MudHotkey: Add new component for handling hotkeys#12079danielchalmers merged 36 commits intoMudBlazor:devfrom
Conversation
|
In regard to the failed "Check JS is ES6 compliant" step: Private fields and methods are compatible with all modern browsers: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_elements#browser_compatibility |
No, since the build fails, it will affect other PRs, and we won't be able to make a release, etc. Why can't the |
@ScarletKuro Because the dot net obj ref would break when i navigate away or reload or am I mistaken? That was the intention why I used the static method approach at all because I couldn't find another way how I could make it work on a application wide level. |
Can you explain it in more detail, with examples? If you force a reload or navigate away, you obviously need to re-register the callback but I don’t see a problem with that. If you perform an SPA navigation to another page, you’d need to add a handler for that specific page. I don’t see an issue with that either.
I find it troublesome if it has to be static, because that introduces a lot of restrictions since you can’t access local members, methods, etc., which makes the design poor for the user as you have to access things statically. For example, Toolbelt.Blazor.HotKeys2 uses |
|
@ScarletKuro I changed it to the following (please note that the code is just a proof of concept atm, the provider is prob. not needed): This would allow the user to easily add for example a custom popup which opens on a certain hotkey easily, either by adding it into the MainLayout for a global hotkey or into a page for a lokal hotkey. The service will then get removed and the functions would be moved into the MudHotkeyProvider. Is that more in line with what you had in mind? |
I guess so. That idea with provider looks interesting, and it makes sense if you want to have global hotkeys across the whole app. Few things to consider:
|
|
@ScarletKuro Then what about this: A simple component instead of the service (code is again not finalized):
<MudHotkey Key="JsKey.KeyB" KeyModifiers="[JsKeyModifier.Control]" HideChildContentOnRepress="true">
<SomeDialog />
</MudHotkey><MudHotkey Key="_selectedKey" KeyModifiers="_selectedKeyModifiers" OnHotkeyPressed="OnHotkey" /> |
|
Sounds good to me |
|
If we're making breaking changes soon, can we merge this with the KeyInterceptorService and refactor the usage across the library? I'm also not sure about making it a component as it seems like more complexity. What if you need to handle multiple hotkeys for one child? |
This PR adds a new service:
GlobalHotkeyService.This service allows to registers global i.e. on all pages available hotkeys. This is useful to for example implement a global search popup, save your current work in a wiki application, show some info overlay, quickly navigate to a common target, etc.