jsakamoto / Toolbelt.Blazor.HotKeys2

This is a class library that provides configuration-centric keyboard shortcuts for your Blazor apps.
https://jsakamoto.github.io/Toolbelt.Blazor.HotKeys2/
Mozilla Public License 2.0
87 stars 6 forks source link

Ability to enable/disable hot keys from C# during runtime #15

Closed uhfath closed 3 months ago

uhfath commented 4 months ago

This PR adds and ability to control each hot key's state during runtime from C# code. Currently I've added a "disabled" state but a user can use this to add it's own custom state. Something that might look like this:

public class HotKeyState : HotKeyEntryState
{
    public bool IsHiddenFromCheatSheet { get; set; }
    public string CheatSheetCategory { get; set; }
}

Then when rendering a cheat sheet it becomes possible to customize it in any way it is required. In this case - show/hide entries or group them by categories.

Also an IsDisabled state is introduced which can be changed during runtime from C# code. When a property is changed it's appropriate JS code is updated to accommodate for it's new value. Useful when one has to control specific keys state during modal dialogs. For instance, when a CRUD dialog is opened there is no need for hot keys of it's parent page to be active. This can be statically controlled using ExcludeSelector but sometimes it is desired to have more granular dynamic control from C# without mangling HTML selectors.

Appropriate tests are also inplace. And BTW, the SampleSite.Components project is also fixed to use an appropriate ProjectReference to Toolbelt.Blazor.HotKeys2 during normal builds or tests.

PR was built using v.3.2.1 tag.

jsakamoto commented 4 months ago

@uhfath Thank you for your contributions!

I'll merge this pull request, but I'm too busy to release this feature as a new package until the end of this month, March 2024. Thank you for your patience.

uhfath commented 3 months ago

Actually I came up with a better code design. I'll comment here when the new version will be ready. Please wait merging this PR until then.

jsakamoto commented 3 months ago

@uhfath Sure, I'll wait for that. Thank you for your contributions!

uhfath commented 3 months ago

Closed in favor of #19.