Window Keyboard Navigation
This article describes how the Window keyboard navigation works and how to customize it. The article extends the general information about keyboard navigation in Telerik UI for Blazor.
The Window's keyboard navigation is active while the component is visible and focused.
Default Keys
The following sections list the default built-in keyboard shortcuts and the actions that they perform when the Window is focused. Also check the Window Keyboard Navigation demo.
| Key Combination | Description |
|---|---|
Alt + ArrowDown | Minimizes a Window in the default state and restores it if maximized. |
Alt + ArrowUp | Maximizes a Window in the default state and restores it if minimized. |
Escape | Closes the Window. |
Using Custom Keys
The Window supports replacing the default built-in keyboard shortcuts or adding new ones that perform the same actions.
To override the built-in Window keyboard shortcuts, you need to create a Dictionary<string, WindowKeyboardCommand?>> that defines:
- Key names as
stringvalues. Use the same key names as in theKeyboardEventArgs.Keyproperty, for example,"B","Enter", or"ArrowDown". - Keyboard commands to execute as
WindowKeyboardCommandvalues.
Set the Dictionary to the Window CustomKeyboardShortcuts parameter.
Setting custom WindowKeyboardCommand keyboard shortcuts
<TelerikWindow CustomKeyboardShortcuts="@WindowCustomShortcuts" />
@code {
private Dictionary<string, WindowKeyboardCommand?> WindowCustomShortcuts = new()
{
{ "Escape", WindowKeyboardCommand.Minimize }
};
}
Keyboard Command
The WindowKeyboardCommand enum represents a user action, for example, Minimize, Close, and others.
You can define multiple keyboard shortcuts that execute the same keyboard command. If a Window keyboard command has no custom key, the component uses the default key. To disable a built-in keyboard command for a specific key, use null.
Example
The following sample shows how to:
- Disable closing the Window with the
Escapekey. - Minimize, restore, and maximize the Window with a custom key.
<TelerikButton OnClick="@( () => WindowVisible = !WindowVisible )">Toggle Window</TelerikButton>
<TelerikWindow @bind-Visible="@WindowVisible"
CustomKeyboardShortcuts="@WindowCustomKeyboardShortcuts">
<WindowActions>
<WindowAction Name="Minimize" />
<WindowAction Name="Maximize" />
<WindowAction Name="Close" />
</WindowActions>
<WindowTitle>
Window Title
</WindowTitle>
<WindowContent>
Window Content
</WindowContent>
</TelerikWindow>
@code {
private bool WindowVisible { get; set; }
private Dictionary<string, WindowKeyboardCommand?> WindowCustomKeyboardShortcuts { get; set; } = new Dictionary<string, WindowKeyboardCommand?>
{
{ "Escape", null },
{ "m", WindowKeyboardCommand.Minimize },
{ "r", WindowKeyboardCommand.Maximize }
};
}