Skip to content

Commit 0f463da

Browse files
committed
feat: 增加 OnKeyUpAsync 参数
1 parent b2c410a commit 0f463da

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/BootstrapBlazor/Components/Textarea/Textarea.razor

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
{
77
<BootstrapLabel required="@Required" for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
88
}
9-
<textarea @attributes="AdditionalAttributes" placeholder="@PlaceHolder" id="@Id" class="@ClassName" disabled="@Disabled" @bind-value="@CurrentValueAsString" @bind-value:event="@EventString" @onblur="OnBlur" data-bb-scroll="@AutoScrollString" @ref="FocusElement"></textarea>
9+
<textarea @attributes="AdditionalAttributes" placeholder="@PlaceHolder" id="@Id" class="@ClassName" disabled="@Disabled"
10+
@bind-value="@CurrentValueAsString" @bind-value:event="@EventString"
11+
@onkeyup="OnKeyUp"
12+
@onblur="OnBlur" data-bb-scroll="@AutoScrollString" @ref="FocusElement"></textarea>

src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6+
using Microsoft.AspNetCore.Components.Web;
7+
68
namespace BootstrapBlazor.Components;
79

810
/// <summary>
@@ -34,6 +36,12 @@ public partial class Textarea
3436
[Parameter]
3537
public bool IsAutoScroll { get; set; }
3638

39+
/// <summary>
40+
/// 获得/设置 文本框按键回调委托方法 默认为 null
41+
/// </summary>
42+
[Parameter]
43+
public Func<KeyboardEventArgs, Task>? OnKeyUpAsync { get; set; }
44+
3745
/// <summary>
3846
/// 获得 客户端是否自动滚屏标识
3947
/// </summary>
@@ -53,4 +61,20 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
5361
await InvokeVoidAsync("execute", Id, "update");
5462
}
5563
}
64+
65+
private async Task OnKeyUp(KeyboardEventArgs args)
66+
{
67+
if (args.Key == "Enter" && OnEnterAsync != null)
68+
{
69+
await OnEnterAsync(Value);
70+
}
71+
if (args.Key == "Escape" && OnEscAsync != null)
72+
{
73+
await OnEscAsync(Value);
74+
}
75+
if (OnKeyUpAsync != null)
76+
{
77+
await OnKeyUpAsync(args);
78+
}
79+
}
5680
}

0 commit comments

Comments
 (0)