Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Blazor: How to use onkeyup with parameter and KeyboardEventArgs

Wenn the user set the focus to a link and presses a key, I need to register it, proof the key and get the a parameter from the link.

I know to read the key without a parameter and I know to transfer a parameter. But I can’t figure out how to do both.

How can I get a parameter (document) and the KeyboardEventArgs (or key) from the link?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@foreach (var document in DocumentList)
{
    <a tabindex="0" type="button" @onclick="() => ShowDocument(document)" 
    @onkeyup="OnDocumentKeyUp(document)">@document.Doname</a>
}

@code{
    private void OnDocumentKeyUp(Do document, KeyboardEventArgs e) // THIS IS MY WISH, BUT NOT WORKING
    {
        if (e.Code is "Enter" or "NumpadEnter" or " " or "Space")
        {
            ShowDocument(document);
        }
    }
}

>Solution :

Like this: @onkeyup="e => OnDocumentKeyUp(document, e)"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading