mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 09:21:24 +08:00
c0f8859914
* set focus when the password button is clicked * add methods for selection * set selectionStart after Focus * fix typescript * set selectionEnd as well * fix a stupid if-condition-bug * remove checks for element * add selectionStart to getDomInfo * get selectionStart from Element * delete unneeded js method Co-authored-by: mihails.kuzmins <mihails.kuzmins@daytongroup.lv> Co-authored-by: James Yeung <shunjiey@hotmail.com>
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace AntDesign.Core.Extensions
|
|
{
|
|
public static class JSRuntimeExtensions
|
|
{
|
|
public static bool IsBrowser(this IJSRuntime jsRuntime) => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"));
|
|
|
|
public static async Task FocusAsync(this IJSRuntime jSRuntime, ElementReference target, bool preventScroll = false)
|
|
{
|
|
#if NET5_0_OR_GREATER
|
|
await target.FocusAsync();
|
|
#else
|
|
try
|
|
{
|
|
await jSRuntime.InvokeVoidAsync(JSInteropConstants.Focus, target, preventScroll);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
throw;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
public static ValueTask SetSelectionStartAsync(this IJSRuntime jSRuntime, ElementReference target, int selectionStart) =>
|
|
jSRuntime.InvokeVoidAsync(JSInteropConstants.SetSelectionStart, target, selectionStart);
|
|
}
|
|
}
|