mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-16 01:41:14 +08:00
b22f9495f4
* feat: use ResizeObserver Api instead of window.resize * fix(module:select): fall back to window.resize in IE11. * fix(module:domEventService): switch from IsIE11 to IsResizeObserverSupported * fix: Console.WriteLine removed Co-authored-by: James Yeung <shunjiey@hotmail.com>
36 lines
1.3 KiB
C#
36 lines
1.3 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);
|
|
|
|
public static ValueTask<bool> IsResizeObserverSupported(this IJSRuntime jSRuntime) => jSRuntime.InvokeAsync<bool>(JSInteropConstants.IsResizeObserverSupported);
|
|
}
|
|
}
|