Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable not working #25

Open
Int32Overflow opened this issue Jun 28, 2024 · 4 comments
Open

Disable not working #25

Int32Overflow opened this issue Jun 28, 2024 · 4 comments

Comments

@Int32Overflow
Copy link

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
Copy link
Owner

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?

@geralt18
Copy link

geralt18 commented Jul 17, 2024

Hi @jsakamoto ,

I attach sample project.
On Index page you can use "?" (question mark) to show help window and I also set State.Disable to true.
But you can press F1, F2 or F3 and you can see that Shortcuts are working because app navigates to new Urls.
Please don't pay attention to this popup window - I'm new to Blazor.

I hope that it will help you diagnose that problem.

BlazorHotKeysTest.zip

@Int32Overflow
Copy link
Author

Int32Overflow commented Jul 19, 2024

@geralt18 Sorry for the late reply. Thank you very much for your time and effort.
I also tried it out in a small project and it seems to work here too. Now I have to look for the error again in my large project...
I will reply again.

@Int32Overflow
Copy link
Author

@geralt18 If I use the same HotKeyEntryState for multiple hotkeys, disabled is not working as expected. Is that by design?
HotKey-demo

  • Pressing both hot keys (CTRL+A & CTRL+S) on first tab. Everythink is working as espected
  • Pressing both hot keys on second tab. CTRL+A is still working but CTRL+S is opening as expected the save dialog of the browser, because the hot keys should be disabled.

HotKeyTest.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants