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

Disable not working #25

Open Int32Overflow opened 1 week ago

Int32Overflow commented 1 week ago

I would like to activate the HotKeys only for a specific TabPage. To do this, I have used a HotKeyEntryState for several HotKeys. When switching tabs, the "Disabled" property is set correctly, but the HotKeys still trigger (on the hidden tab)

private readonly HotKeyEntryState overviewTabHotKeyState = new HotKeyEntryState();
protected override async Task OnAfterRenderAsync(bool firstRender)
{
    await base.OnAfterRenderAsync(firstRender);

    if (firstRender)
    {
        hotKeysContext = this.HotKeys.CreateContext()
            .Add(ModCode.Ctrl, Code.F, ShowSearch, new() { Description = "Show search bar", Exclude = Exclude.InputNonText | Exclude.TextArea, State = overviewTabHotKeyState })
            .Add(ModCode.None, Code.F5, ReloadTable, new() { Description = "Reload table", Exclude = Exclude.InputNonText | Exclude.TextArea, State = overviewTabHotKeyState });
    }
}

private async Task DoActivePanelIndexChanged(int newIndex)
{
    if (this.selectedTabIndex != newIndex)
    {
        this.selectedTabIndex = newIndex;
        if (this.selectedTabIndex == 0)
        {
            overviewTabHotKeyState.Disabled = false;
        }
        else
        {
            overviewTabHotKeyState.Disabled = true;
        }
    }
}
jsakamoto commented 6 days ago

Hi @Int32Overflow,

Unfortunately, I've still not succeeded in reproducing the problem that you reported. Could you provide me with a whole of a minimal sample project that can reproduce the issue?

By the way, as far as I can read the code fragment you posted above, once the "Disabled" property of the state object is set to true, the browser's default keyboard shortcuts will be available. For example, hitting Ctrl+F will open the search box built into the web browser. Is that your intentional design?