Skip to content

Commit 0bab5a6

Browse files
h2lsArgoZhang
andauthored
fix(Textarea): adding new functionality to handle Shift + Enter (#5611)
* fix(keyup): prevent modifier key combinations from triggering Enter callback - Add `hasNoModifiers` helper to check for Ctrl/Shift/Alt/Meta keys - Update Enter key handling in `handleKeyUp` to ignore modifier combinations - Retain existing Escape key logic * doc: 更改注释为英文 * doc: 更新注释为英语 * refactor: 更新逻辑 * revert: 重置代码 * refactor: 使用 js 解决问题保证效率 * doc: 移除不使用的命名空间 * chore: bump version 9.4.9-beta04 --------- Co-authored-by: Argo Zhang <[email protected]>
1 parent 2cf8af4 commit 0bab5a6

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.4.9-beta03</Version>
4+
<Version>9.4.9-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export function handleKeyUp(id, invoke, enter, enterCallbackMethod, esc, escCall
1212
if (el) {
1313
EventHandler.on(el, 'keyup', e => {
1414
if (enter && (e.key === 'Enter' || e.key === 'NumpadEnter')) {
15+
const useShiftEnter = el.getAttribute('data-bb-shift-enter') === 'true';
16+
if (!e.shiftKey && useShiftEnter) {
17+
return;
18+
}
1519
invoke.invokeMethodAsync(enterCallbackMethod, el.value)
1620
}
1721
else if (esc && e.key === 'Escape') {

src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,86 +6,86 @@
66
namespace BootstrapBlazor.Components;
77

88
/// <summary>
9-
/// BootstrapInputBase 组件基类
9+
/// Base class for BootstrapInput components
1010
/// </summary>
1111
[BootstrapModuleAutoLoader("Input/BootstrapInput.razor.js", JSObjectReference = true, AutoInvokeInit = false)]
1212
public abstract class BootstrapInputBase<TValue> : ValidateBase<TValue>
1313
{
1414
/// <summary>
15-
/// 获得 class 样式集合
15+
/// Gets the class attribute value
1616
/// </summary>
1717
protected virtual string? ClassName => CssBuilder.Default("form-control")
1818
.AddClass($"border-{Color.ToDescriptionString()}", Color != Color.None && !IsDisabled && !IsValid.HasValue)
1919
.AddClass(CssClass).AddClass(ValidCss)
2020
.Build();
2121

2222
/// <summary>
23-
/// 元素实例引用
23+
/// Gets or sets Element reference instance
2424
/// </summary>
2525
protected ElementReference FocusElement { get; set; }
2626

2727
/// <summary>
28-
/// 获得/设置 input 类型 placeholder 属性
28+
/// Gets or sets the placeholder attribute value
2929
/// </summary>
3030
[Parameter]
3131
public string? PlaceHolder { get; set; }
3232

3333
/// <summary>
34-
/// 获得/设置 文本框 Enter 键回调委托方法 默认为 null
34+
/// Gets or sets the callback method for Enter key press, default is null
3535
/// </summary>
3636
[Parameter]
3737
public Func<TValue, Task>? OnEnterAsync { get; set; }
3838

3939
/// <summary>
40-
/// 获得/设置 文本框 Esc 键回调委托方法 默认为 null
40+
/// Gets or sets the callback method for Esc key press, default is null
4141
/// </summary>
4242
[Parameter]
4343
public Func<TValue, Task>? OnEscAsync { get; set; }
4444

4545
/// <summary>
46-
/// 获得/设置 按钮颜色
46+
/// Gets or sets the button color
4747
/// </summary>
4848
[Parameter]
4949
public Color Color { get; set; } = Color.None;
5050

5151
/// <summary>
52-
/// 获得/设置 格式化字符串
52+
/// Gets or sets the formatter function
5353
/// </summary>
5454
[Parameter]
5555
public Func<TValue?, string>? Formatter { get; set; }
5656

5757
/// <summary>
58-
/// 获得/设置 格式化字符串 如时间类型设置 yyyy-MM-dd
58+
/// Gets or sets the format string, e.g., "yyyy-MM-dd" for date types
5959
/// </summary>
6060
[Parameter]
6161
public string? FormatString { get; set; }
6262

6363
/// <summary>
64-
/// 获得/设置 是否自动获取焦点 默认 false 不自动获取焦点
64+
/// Gets or sets whether to automatically focus, default is false
6565
/// </summary>
6666
[Parameter]
6767
public bool IsAutoFocus { get; set; }
6868

6969
/// <summary>
70-
/// 获得/设置 获得焦点后自动选择输入框内所有字符串 默认 false 未启用
70+
/// Gets or sets whether to automatically select all text on focus, default is false
7171
/// </summary>
7272
[Parameter]
7373
public bool IsSelectAllTextOnFocus { get; set; }
7474

7575
/// <summary>
76-
/// 获得/设置 Enter 键自动选择输入框内所有字符串 默认 false 未启用
76+
/// Gets or sets whether to automatically select all text on Enter key press, default is false
7777
/// </summary>
7878
[Parameter]
7979
public bool IsSelectAllTextOnEnter { get; set; }
8080

8181
/// <summary>
82-
/// 获得/设置 是否自动修剪空白 默认 false 未启用
82+
/// Gets or sets whether to automatically trim whitespace, default is false
8383
/// </summary>
8484
[Parameter]
8585
public bool IsTrim { get; set; }
8686

8787
/// <summary>
88-
/// 获得/设置 失去焦点回调方法 默认 null
88+
/// Gets or sets the callback method for blur event, default is null
8989
/// </summary>
9090
[Parameter]
9191
public Func<TValue, Task>? OnBlurAsync { get; set; }
@@ -94,24 +94,24 @@ public abstract class BootstrapInputBase<TValue> : ValidateBase<TValue>
9494
private Modal? Modal { get; set; }
9595

9696
/// <summary>
97-
/// 获得 input 组件类型 默认 text
97+
/// Gets the input type, default is "text"
9898
/// </summary>
9999
protected string Type { get; set; } = "text";
100100

101101
/// <summary>
102-
/// 自动获得焦点方法
102+
/// Method to focus the element
103103
/// </summary>
104104
/// <returns></returns>
105105
public async Task FocusAsync() => await FocusElement.FocusAsync();
106106

107107
/// <summary>
108-
/// 全选文字
108+
/// Method to select all text
109109
/// </summary>
110110
/// <returns></returns>
111111
public async ValueTask SelectAllTextAsync() => await InvokeVoidAsync("select", Id);
112112

113113
/// <summary>
114-
/// 获得/设置 是否不注册 js 脚本处理 Enter/ESC 键盘处理函数 默认 false
114+
/// Gets or sets whether to skip JS script registration for Enter/Esc key handling, default is false
115115
/// </summary>
116116
protected bool SkipRegisterEnterEscJSInvoke { get; set; }
117117

@@ -173,12 +173,12 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
173173
}
174174

175175
/// <summary>
176-
/// 获得输入框 Id
176+
/// Gets the input element Id
177177
/// </summary>
178178
protected virtual string? GetInputId() => Id;
179179

180180
/// <summary>
181-
/// 数值格式化委托方法
181+
/// Value formatting delegate method
182182
/// </summary>
183183
/// <param name="value"></param>
184184
/// <returns></returns>
@@ -198,7 +198,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
198198
protected override bool TryParseValueFromString(string value, [MaybeNullWhen(false)] out TValue result, out string? validationErrorMessage) => base.TryParseValueFromString(IsTrim ? value.Trim() : value, out result, out validationErrorMessage);
199199

200200
/// <summary>
201-
/// OnBlur 方法
201+
/// OnBlur method
202202
/// </summary>
203203
protected virtual async Task OnBlur()
204204
{
@@ -209,7 +209,7 @@ protected virtual async Task OnBlur()
209209
}
210210

211211
/// <summary>
212-
/// 客户端 EnterCallback 回调方法
212+
/// Client-side EnterCallback method
213213
/// </summary>
214214
/// <returns></returns>
215215
[JSInvokable]
@@ -223,7 +223,7 @@ public async Task EnterCallback(string val)
223223
}
224224

225225
/// <summary>
226-
/// 客户端 EscCallback 回调方法
226+
/// Client-side EscCallback method
227227
/// </summary>
228228
/// <returns></returns>
229229
[JSInvokable]

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@
66
namespace BootstrapBlazor.Components;
77

88
/// <summary>
9-
/// Textarea 组件
9+
/// Textarea component
1010
/// </summary>
1111
public partial class Textarea
1212
{
1313
/// <summary>
14-
/// 滚动到顶部
14+
/// Scroll to the top
1515
/// </summary>
1616
/// <returns></returns>
1717
public Task ScrollToTop() => InvokeVoidAsync("execute", Id, "toTop");
1818

1919
/// <summary>
20-
/// 滚动到数值
20+
/// Scroll to a specific value
2121
/// </summary>
2222
/// <returns></returns>
2323
public Task ScrollTo(int value) => InvokeVoidAsync("execute", Id, "to", value);
2424

2525
/// <summary>
26-
/// 滚动到底部
26+
/// Scroll to the bottom
2727
/// </summary>
2828
/// <returns></returns>
2929
public Task ScrollToBottom() => InvokeVoidAsync("execute", Id, "toBottom");
3030

3131
/// <summary>
32-
/// 获得/设置 是否自动滚屏 默认 false
32+
/// Gets or sets whether auto-scroll is enabled. Default is false.
3333
/// </summary>
3434
[Parameter]
3535
public bool IsAutoScroll { get; set; }
3636

3737
/// <summary>
38-
/// 获得/设置 是否使用 Shift + Enter 代替原回车按键行为 默认为 false
38+
/// Gets or sets whether Shift + Enter replaces the default Enter key behavior. Default is false.
3939
/// </summary>
4040
[Parameter]
4141
public bool UseShiftEnter { get; set; }
4242

4343
/// <summary>
44-
/// 获得 客户端是否自动滚屏标识
44+
/// Gets the client-side auto-scroll identifier.
4545
/// </summary>
4646
private string? AutoScrollString => IsAutoScroll ? "auto" : null;
4747

0 commit comments

Comments
 (0)