-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Summary
Consider adding interop (extension) methods such as InvokeAsync and SetValueAsync to ElementReference. This would make it easier to manipulate DOM elements from .NET without wrapper JS code.
Motivation and goals
For .NET 10, we are extending the API for the Blazor JS interop (as discussed in #31151) in order to reduce the need to write wrapper JS code. To further support this goal, could we add similar (extension) methods that the IJSObjectReference has to the ElementReference?
Currently, there is a special baked-in support for focusing the element implemented as the extension method FocusAsync. To access other functions and properties of a DOM element, one needs to write a JS function that takes the ElementReference as an argument, and invoke such function using InvokeAsync on IJSRuntime or IJSObjectReference. (See offical docs or community tutorials.)
This workflow could be streamlined by adding support for calling InvokeAsync as well as the new GetValueAsync and SetValueAsync methods directly on the ElementReference instance.