This is a migrated thread and some comments may be shown as answers.

@onkeydown event on TelerikEditor

1 Answer 679 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Nicola
Top achievements
Rank 1
Nicola asked on 20 Apr 2021, 12:48 PM

Is there a way to handle @onkeydown event on <TelerikEditor>?

I tried this way:

<TelerikEditor Id="myEditor" @bind-Value="@myEditorValue" @onkeydown="OnKeyDownMyEditor"></TelerikEditor>

and i get the error:

blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Object of type 'Telerik.Blazor.Components.TelerikEditor' does not have a property matching the name 'onkeydown'.
System.InvalidOperationException: Object of type 'Telerik.Blazor.Components.TelerikEditor' does not have a property matching the name 'onkeydown'.

 

I get this kind of error any time i try to handle an event in a Telerik component using the regular Blazor way, so i guess this is not the proper way to do it.

1 Answer, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 20 Apr 2021, 02:54 PM

Hi Nicola,

You can capture keyboard events from the editor in the same way like with other inputs - the only extra thing is that the editor needs to be in its Div edit mode.

Here is an example:

<div @onkeydown="@OnKeydownHandler">
    <TelerikEditor EditMode="@EditorEditMode.Div" @bind-Value="@TheEditorContent">
    </TelerikEditor>
</div>


@code {
    string TheEditorContent { get; set; } = @"<h1>Lorem ipsum</h1><p>Dolor sit amet.</p>";

    async Task OnKeydownHandler(KeyboardEventArgs e)
    {
        Console.WriteLine(e.Key);
    }
}

Regards,
Marin Bratanov
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
Editor
Asked by
Nicola
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or