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

Example not working #10

Open
Martin-Andersen opened this issue Feb 6, 2023 · 5 comments
Open

Example not working #10

Martin-Andersen opened this issue Feb 6, 2023 · 5 comments

Comments

@Martin-Andersen
Copy link

In the old version of HotKeys. I wrote this

HotKeysContext = HotKeys.CreateContext()
                .Add(ModKeys.Ctrl, Keys.K, SetFocusInGridSearchField, "Set focus in grid search field");

I tried this in v2, not working

HotKeysContext = HotKeys.CreateContext()
            .Add(ModCode.Ctrl,Key.k, SetFocusInGridSearchField, "Set focus in grid search field");

And this not working

HotKeysContext = HotKeys.CreateContext()
            .Add(ModCode.Ctrl,Key.k, "Set focus in grid search field", _ => SetFocusInGridSearchField);

Is it because my handler is async?

private async Task SetFocusInGridSearchField()
    {
        await JsRuntime.InvokeVoidAsync("focusElement", GridSearchBoxPortfolioListGrid);
    }

@Martin-Andersen
Copy link
Author

Better headline

@jsakamoto
Copy link
Owner

@Martin-Andersen Currently, it is intentionally by design.

See also: #7 (comment)

@Pinox
Copy link

Pinox commented Sep 1, 2023

This also tripped me up a bit as the errors in Visual Studio are not that great.

Would be a great idea to add a note in the sample to the async method exception.

@wokket
Copy link

wokket commented Jan 24, 2024

Just a +1 here. Had an async Task method called on button click, tried to wire up a shortcut to call the same method per the sample, it can't resolve the method, and I get a thousand other overload options to scroll through.

My understanding of ValueTask is it's only of performance improvement if the underlyng async operation completes synchronously...They also have a drastically reduced API surface area (by design). See https://devblogs.microsoft.com/dotnet/understanding-the-whys-whats-and-whens-of-valuetask/

@jsakamoto
Copy link
Owner

Hi everyone,
I've changed my opinion that I don't provide the Add() methods of overloaded version for async Task because so many developers were confused by my decision.

So, the latest preview version of the HotKeys2 now starts to support async Task for its Add() method.

See also: https://www.nuget.org/packages/Toolbelt.Blazor.HotKeys2/3.3.0-preview.1#releasenotes-body-tab

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

4 participants