mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 17:31:42 +08:00
2d693740c6
* docs(module:input): api correction & comments * fix(module:input): clear icon in sync with antD * fix(module:input): add parameter bordered * fix(module:textarea): add parameter ShowCounter * fix(module:input): Focus with behaviors * docs: add missing docs, rearrange order * fix(module:search): update to match new standard look doc(module:search): add API & demos * fix(module:inputgroup): override style to remove whitespace\ docs: same as react * fix(module:inputpassword): support custom icon docs: same as react * fix(module:input): add blur method docs: add blur method * fix(module:input): add readonly parameter * tests * fix * fix(module:input): sequence correction * Update components/core/Base/AntComponentBase.cs Co-authored-by: James Yeung <shunjiey@hotmail.com> * review fixes * fix: clean-up * tests: fix missing mock * fix: focus * fix(module:input): bind clear button to _inputValue * tests: clear button show/hide * tests: package update Co-authored-by: James Yeung <shunjiey@hotmail.com>
63 lines
2.0 KiB
C#
63 lines
2.0 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 BlurAsyc(this IJSRuntime jSRuntime, ElementReference target)
|
|
{
|
|
try
|
|
{
|
|
await jSRuntime.InvokeVoidAsync(JSInteropConstants.Blur, target);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public static async Task FocusAsync(this IJSRuntime jSRuntime, ElementReference target, bool preventScroll = false)
|
|
{
|
|
#if NET6_0_OR_GREATER
|
|
await target.FocusAsync(preventScroll);
|
|
#else
|
|
try
|
|
{
|
|
await jSRuntime.InvokeVoidAsync(JSInteropConstants.Focus, target, preventScroll);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
throw;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
public static async Task FocusAsync(this IJSRuntime jSRuntime, ElementReference target, FocusBehavior behavior, bool preventScroll = false)
|
|
{
|
|
try
|
|
{
|
|
await jSRuntime.InvokeVoidAsync(JSInteropConstants.Focus, target, preventScroll, behavior);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
}
|