Skip to content

Add support to focus components in blazor #26486

@MarvinKlein1508

Description

@MarvinKlein1508

Is your feature request related to a problem? Please describe.

In NET 5 you have added FocusAsync() for ElementReferences. This works fine for all non component html elements. However, I am using EditForm which uses Input components. Unfortunately I am unable to set the focus to these inputs and users of my app have to click on my input first in order to enter information. I really want to set the focus on this components as well to get a better user experience in the app.

Perhaps it might be even possible to add the overwritable methods OnFocus() and OnFocusAsync() to the component itself. What the user can do then is just focus the component and the component itself can manage which control of it should be focused.

For example lets say I have a component called CustomerList.razor. My component contains an input for a search query and a button.

In Index.razor I implement CustomerList and set the Focus to this component which triggers the OnFocus() methods of CustomerList. Within this method I can specify which element of CustomerList should be focused.

Let me know what you think.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions