You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -30,11 +30,98 @@ This KB article answers the following questions:
30
30
* How to focus a button or a textbox inside a Window when the Window is made visible?
31
31
* How to focus a component after the Window opens? The JavaScript call is made before the Window actually shows, so the focusable element is `null`.
32
32
* How do you set focus on an input element in a Window, so that the user doesn't have to use their mouse?
33
+
* How to open (expand) a DropDownList automatically on Window open?
33
34
34
35
35
36
## Solution
36
37
37
-
To focus any element or component in the [Telerik UI Window for Blazor](slug:dialog-overview), follow the steps below. They are also applicable for the [Dialog component](slug:dialog-overview).
38
+
There are two ways to focus any element or component in the [Telerik UI Window for Blazor](slug:window-overview). They are also applicable for the [Dialog component](slug:dialog-overview).
39
+
40
+
*[Add a delay after changing the Window's `Visible` parameter value](#add-delay-after-changing-the-visible-parameter-value)
41
+
*[Use a boolean flag in `OnAfterRenderAsync`](#use-boolean-flag-in-onafterrenderasync)
42
+
43
+
### Add Delay after Changing the Visible Parameter Value
44
+
45
+
1. To focus a Telerik UI for Blazor component, [set the `@ref` attribute to obtain the component's reference](slug:components/textbox/overview#textbox-reference-and-methods).
46
+
1. Set the Window `Visible` parameter to `true` programmatically in some event handler.
47
+
1. Use a small `Task.Delay()` to trigger an immediate UI refresh in the same event handler. The delay allows the app to wait for the Window to display and gain focus. Without a delay, the Window and the focusable component will not exist yet.
48
+
1. Focus the desired button, textbox, or input component. If it's a Telerik UI for Blazor component, use the [`FocusAsync()` method](slug:inputs-kb-focus).
49
+
50
+
>caption Focus a component on Dialog or Window open
51
+
52
+
````RAZOR
53
+
<TelerikButton OnClick="@ShowWindow">Show Window and Focus Button</TelerikButton>
54
+
<TelerikButton OnClick="@ShowDialog">Show Dialog and Focus TextBox</TelerikButton>
1. To focus a Telerik UI for Blazor component, [set the `@ref` attribute to obtain the component's reference](slug:components/textbox/overview#textbox-reference-and-methods).
40
127
1. Raise a `bool` flag when showing the Window.
@@ -60,7 +147,7 @@ To focus any element or component in the [Telerik UI Window for Blazor](slug:dia
60
147
<p>This Button is now focused:</p>
61
148
<TelerikButton @ref="@ButtonRef"
62
149
OnClick="@OnWindowButtonClick">
63
-
Click Me
150
+
Hit Enter or Space
64
151
</TelerikButton>
65
152
<p><code>StringValue</code>: @StringValue</p>
66
153
</WindowContent>
@@ -131,7 +218,6 @@ To focus any element or component in the [Telerik UI Window for Blazor](slug:dia
0 commit comments