Skip to content

Add an API to focus on elements #22892

@pranavkm

Description

@pranavkm

A common ask from Blazor users is the ability to perform trivial DOM operations without having to manually write the JavaScript / JSInterop code. Having the ability to focus on DOM elements is one of the more popular ones that we'd like to address.

To solve this, we'd like to introduce FocusAsync() as an extension method to ElementRef types. Here's the usage we think would work the best:

@code {
  ElementRef myRef;

  protected override async Task OnAfterRenderAsync(bool first)
  {
      await myRef.FocusAsync();
      ...
   }
}

This would most likely use JSInterop for it's implementation, but it would be nice not to have to pass in the IJSRuntime instance.

Related issue with lots of feedback: #17472

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing one

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions