Skip to content
5 changes: 4 additions & 1 deletion src/BootstrapBlazor/Components/Textarea/Textarea.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
{
<BootstrapLabel required="@Required" for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
}
<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>
<textarea @attributes="AdditionalAttributes" placeholder="@PlaceHolder" id="@Id" class="@ClassName" disabled="@Disabled"
@bind-value="@CurrentValueAsString" @bind-value:event="@EventString"
@onkeyup="OnKeyUp"
@onblur="OnBlur" data-bb-scroll="@AutoScrollString" @ref="FocusElement"></textarea>
24 changes: 24 additions & 0 deletions src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

using Microsoft.AspNetCore.Components.Web;

namespace BootstrapBlazor.Components;

/// <summary>
Expand Down Expand Up @@ -34,6 +36,12 @@
[Parameter]
public bool IsAutoScroll { get; set; }

/// <summary>
/// 获得/设置 文本框按键回调委托方法 默认为 null
/// </summary>
[Parameter]
public Func<KeyboardEventArgs, Task>? OnKeyUpAsync { get; set; }

Check warning on line 43 in src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L43 was not covered by tests

/// <summary>
/// 获得 客户端是否自动滚屏标识
/// </summary>
Expand All @@ -53,4 +61,20 @@
await InvokeVoidAsync("execute", Id, "update");
}
}

private async Task OnKeyUp(KeyboardEventArgs args)
{

Check warning on line 66 in src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L66 was not covered by tests
if (args.Key == "Enter" && OnEnterAsync != null)
{
await OnEnterAsync(Value);
}

Check warning on line 70 in src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs

View check run for this annotation

Codecov / codecov/patch

src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs#L68-L70

Added lines #L68 - L70 were not covered by tests
if (args.Key == "Escape" && OnEscAsync != null)
{
await OnEscAsync(Value);
}

Check warning on line 74 in src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs

View check run for this annotation

Codecov / codecov/patch

src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs#L72-L74

Added lines #L72 - L74 were not covered by tests
if (OnKeyUpAsync != null)
{
await OnKeyUpAsync(args);
}
}

Check warning on line 79 in src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs

View check run for this annotation

Codecov / codecov/patch

src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs#L76-L79

Added lines #L76 - L79 were not covered by tests
}