From acfc7d4e73120820863498a56aa4cb32589397f2 Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 12 Mar 2025 16:21:50 +0800 Subject: [PATCH 1/8] 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 --- src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js b/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js index 08468520762..0ce4d740b0f 100644 --- a/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js +++ b/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js @@ -7,11 +7,13 @@ export function clear(id) { } } +const hasNoModifiers = (e) => !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey; + export function handleKeyUp(id, invoke, enter, enterCallbackMethod, esc, escCallbackMethod) { const el = document.getElementById(id) if (el) { EventHandler.on(el, 'keyup', e => { - if (enter && (e.key === 'Enter' || e.key === 'NumpadEnter')) { + if (enter && (e.key === 'Enter' || e.key === 'NumpadEnter') && hasNoModifiers(e)) { invoke.invokeMethodAsync(enterCallbackMethod, el.value) } else if (esc && e.key === 'Escape') { From 51e5d77e5134ac8e004fba8e615ab97391dfe3e4 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 13 Mar 2025 08:46:29 +0800 Subject: [PATCH 2/8] =?UTF-8?q?doc:=20=E6=9B=B4=E6=94=B9=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E4=B8=BA=E8=8B=B1=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Input/BootstrapInputBase.cs | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs b/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs index 7ee33031957..c613c12cdce 100644 --- a/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs +++ b/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs @@ -6,13 +6,13 @@ namespace BootstrapBlazor.Components; /// -/// BootstrapInputBase 组件基类 +/// Base class for BootstrapInput components /// [BootstrapModuleAutoLoader("Input/BootstrapInput.razor.js", JSObjectReference = true, AutoInvokeInit = false)] public abstract class BootstrapInputBase : ValidateBase { /// - /// 获得 class 样式集合 + /// Gets the class attribute value /// protected virtual string? ClassName => CssBuilder.Default("form-control") .AddClass($"border-{Color.ToDescriptionString()}", Color != Color.None && !IsDisabled && !IsValid.HasValue) @@ -20,72 +20,72 @@ public abstract class BootstrapInputBase : ValidateBase .Build(); /// - /// 元素实例引用 + /// Gets or sets Element reference instance /// protected ElementReference FocusElement { get; set; } /// - /// 获得/设置 input 类型 placeholder 属性 + /// Gets or sets the placeholder attribute value /// [Parameter] public string? PlaceHolder { get; set; } /// - /// 获得/设置 文本框 Enter 键回调委托方法 默认为 null + /// Gets or sets the callback method for Enter key press, default is null /// [Parameter] public Func? OnEnterAsync { get; set; } /// - /// 获得/设置 文本框 Esc 键回调委托方法 默认为 null + /// Gets or sets the callback method for Esc key press, default is null /// [Parameter] public Func? OnEscAsync { get; set; } /// - /// 获得/设置 按钮颜色 + /// Gets or sets the button color /// [Parameter] public Color Color { get; set; } = Color.None; /// - /// 获得/设置 格式化字符串 + /// Gets or sets the formatter function /// [Parameter] public Func? Formatter { get; set; } /// - /// 获得/设置 格式化字符串 如时间类型设置 yyyy-MM-dd + /// Gets or sets the format string, e.g., "yyyy-MM-dd" for date types /// [Parameter] public string? FormatString { get; set; } /// - /// 获得/设置 是否自动获取焦点 默认 false 不自动获取焦点 + /// Gets or sets whether to automatically focus, default is false /// [Parameter] public bool IsAutoFocus { get; set; } /// - /// 获得/设置 获得焦点后自动选择输入框内所有字符串 默认 false 未启用 + /// Gets or sets whether to automatically select all text on focus, default is false /// [Parameter] public bool IsSelectAllTextOnFocus { get; set; } /// - /// 获得/设置 Enter 键自动选择输入框内所有字符串 默认 false 未启用 + /// Gets or sets whether to automatically select all text on Enter key press, default is false /// [Parameter] public bool IsSelectAllTextOnEnter { get; set; } /// - /// 获得/设置 是否自动修剪空白 默认 false 未启用 + /// Gets or sets whether to automatically trim whitespace, default is false /// [Parameter] public bool IsTrim { get; set; } /// - /// 获得/设置 失去焦点回调方法 默认 null + /// Gets or sets the callback method for blur event, default is null /// [Parameter] public Func? OnBlurAsync { get; set; } @@ -94,24 +94,24 @@ public abstract class BootstrapInputBase : ValidateBase private Modal? Modal { get; set; } /// - /// 获得 input 组件类型 默认 text + /// Gets the input type, default is "text" /// protected string Type { get; set; } = "text"; /// - /// 自动获得焦点方法 + /// Method to focus the element /// /// public async Task FocusAsync() => await FocusElement.FocusAsync(); /// - /// 全选文字 + /// Method to select all text /// /// public async ValueTask SelectAllTextAsync() => await InvokeVoidAsync("select", Id); /// - /// 获得/设置 是否不注册 js 脚本处理 Enter/ESC 键盘处理函数 默认 false + /// Gets or sets whether to skip JS script registration for Enter/Esc key handling, default is false /// protected bool SkipRegisterEnterEscJSInvoke { get; set; } @@ -173,12 +173,12 @@ protected override async Task OnAfterRenderAsync(bool firstRender) } /// - /// 获得输入框 Id + /// Gets the input element Id /// protected virtual string? GetInputId() => Id; /// - /// 数值格式化委托方法 + /// Value formatting delegate method /// /// /// @@ -198,7 +198,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) protected override bool TryParseValueFromString(string value, [MaybeNullWhen(false)] out TValue result, out string? validationErrorMessage) => base.TryParseValueFromString(IsTrim ? value.Trim() : value, out result, out validationErrorMessage); /// - /// OnBlur 方法 + /// OnBlur method /// protected virtual async Task OnBlur() { @@ -209,7 +209,7 @@ protected virtual async Task OnBlur() } /// - /// 客户端 EnterCallback 回调方法 + /// Client-side EnterCallback method /// /// [JSInvokable] @@ -223,7 +223,7 @@ public async Task EnterCallback(string val) } /// - /// 客户端 EscCallback 回调方法 + /// Client-side EscCallback method /// /// [JSInvokable] From d69d35243b495f2c526b8a22c5ed3ab61f40c5f0 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 13 Mar 2025 09:08:59 +0800 Subject: [PATCH 3/8] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E4=B8=BA=E8=8B=B1=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Textarea/Textarea.razor.cs | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs b/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs index 0a0f4380f51..d86491ce830 100644 --- a/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs +++ b/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs @@ -3,45 +3,47 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using Microsoft.AspNetCore.Components.Web; + namespace BootstrapBlazor.Components; /// -/// Textarea 组件 +/// Textarea component /// public partial class Textarea { /// - /// 滚动到顶部 + /// Scroll to the top /// /// public Task ScrollToTop() => InvokeVoidAsync("execute", Id, "toTop"); /// - /// 滚动到数值 + /// Scroll to a specific value /// /// public Task ScrollTo(int value) => InvokeVoidAsync("execute", Id, "to", value); /// - /// 滚动到底部 + /// Scroll to the bottom /// /// public Task ScrollToBottom() => InvokeVoidAsync("execute", Id, "toBottom"); /// - /// 获得/设置 是否自动滚屏 默认 false + /// Gets or sets whether auto-scroll is enabled. Default is false. /// [Parameter] public bool IsAutoScroll { get; set; } /// - /// 获得/设置 是否使用 Shift + Enter 代替原回车按键行为 默认为 false + /// Gets or sets whether Shift + Enter replaces the default Enter key behavior. Default is false. /// [Parameter] public bool UseShiftEnter { get; set; } /// - /// 获得 客户端是否自动滚屏标识 + /// Gets the client-side auto-scroll identifier. /// private string? AutoScrollString => IsAutoScroll ? "auto" : null; @@ -61,4 +63,20 @@ protected override async Task OnAfterRenderAsync(bool firstRender) await InvokeVoidAsync("execute", Id, "update"); } } + + /// + /// Client-side EnterCallback method + /// + /// + [JSInvokable] + public override async Task EnterCallback(KeyboardEventArgs e, string val) + { + if (OnEnterAsync != null && TriggerEnter(e)) + { + CurrentValueAsString = val; + await OnEnterAsync(Value); + } + } + + private bool TriggerEnter(KeyboardEventArgs e) => UseShiftEnter ? e.ShiftKey : true; } From acfc4c4cdb43867eda80e10c476f481e33314a11 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 13 Mar 2025 09:09:20 +0800 Subject: [PATCH 4/8] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Input/BootstrapInput.razor.js | 6 ++---- src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js b/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js index 0ce4d740b0f..3e9b593cb0c 100644 --- a/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js +++ b/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js @@ -7,14 +7,12 @@ export function clear(id) { } } -const hasNoModifiers = (e) => !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey; - export function handleKeyUp(id, invoke, enter, enterCallbackMethod, esc, escCallbackMethod) { const el = document.getElementById(id) if (el) { EventHandler.on(el, 'keyup', e => { - if (enter && (e.key === 'Enter' || e.key === 'NumpadEnter') && hasNoModifiers(e)) { - invoke.invokeMethodAsync(enterCallbackMethod, el.value) + if (enter && (e.key === 'Enter' || e.key === 'NumpadEnter')) { + invoke.invokeMethodAsync(enterCallbackMethod, { key: e.key, code: e.code, ctrlKey: e.ctrlKey, shiftKey: e.shiftKey, altKey: e.altKey, metaKey: e.metaKey, repeat: e.repeat, type: e.type, location: e.location }, el.value) } else if (esc && e.key === 'Escape') { invoke.invokeMethodAsync(escCallbackMethod) diff --git a/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs b/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs index c613c12cdce..75700fd3f30 100644 --- a/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs +++ b/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using Microsoft.AspNetCore.Components.Web; + namespace BootstrapBlazor.Components; /// @@ -213,7 +215,7 @@ protected virtual async Task OnBlur() /// /// [JSInvokable] - public async Task EnterCallback(string val) + public virtual async Task EnterCallback(KeyboardEventArgs e, string val) { if (OnEnterAsync != null) { From 8294e39a94d65238d058abee2c8eaf0f8281bc5e Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 13 Mar 2025 09:33:57 +0800 Subject: [PATCH 5/8] =?UTF-8?q?revert:=20=E9=87=8D=E7=BD=AE=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Input/BootstrapInputBase.cs | 4 +--- .../Components/Textarea/Textarea.razor.cs | 16 ---------------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs b/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs index 75700fd3f30..c613c12cdce 100644 --- a/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs +++ b/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone -using Microsoft.AspNetCore.Components.Web; - namespace BootstrapBlazor.Components; /// @@ -215,7 +213,7 @@ protected virtual async Task OnBlur() /// /// [JSInvokable] - public virtual async Task EnterCallback(KeyboardEventArgs e, string val) + public async Task EnterCallback(string val) { if (OnEnterAsync != null) { diff --git a/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs b/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs index d86491ce830..1a85f489d2a 100644 --- a/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs +++ b/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs @@ -63,20 +63,4 @@ protected override async Task OnAfterRenderAsync(bool firstRender) await InvokeVoidAsync("execute", Id, "update"); } } - - /// - /// Client-side EnterCallback method - /// - /// - [JSInvokable] - public override async Task EnterCallback(KeyboardEventArgs e, string val) - { - if (OnEnterAsync != null && TriggerEnter(e)) - { - CurrentValueAsString = val; - await OnEnterAsync(Value); - } - } - - private bool TriggerEnter(KeyboardEventArgs e) => UseShiftEnter ? e.ShiftKey : true; } From b9d947343139635ab9accf95c06ff20f2a84bb0d Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 13 Mar 2025 09:34:11 +0800 Subject: [PATCH 6/8] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8=20js=20?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=97=AE=E9=A2=98=E4=BF=9D=E8=AF=81=E6=95=88?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Input/BootstrapInput.razor.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js b/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js index 3e9b593cb0c..70c3ba2701b 100644 --- a/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js +++ b/src/BootstrapBlazor/Components/Input/BootstrapInput.razor.js @@ -12,7 +12,11 @@ export function handleKeyUp(id, invoke, enter, enterCallbackMethod, esc, escCall if (el) { EventHandler.on(el, 'keyup', e => { if (enter && (e.key === 'Enter' || e.key === 'NumpadEnter')) { - invoke.invokeMethodAsync(enterCallbackMethod, { key: e.key, code: e.code, ctrlKey: e.ctrlKey, shiftKey: e.shiftKey, altKey: e.altKey, metaKey: e.metaKey, repeat: e.repeat, type: e.type, location: e.location }, el.value) + const useShiftEnter = el.getAttribute('data-bb-shift-enter') === 'true'; + if (!e.shiftKey && useShiftEnter) { + return; + } + invoke.invokeMethodAsync(enterCallbackMethod, el.value) } else if (esc && e.key === 'Escape') { invoke.invokeMethodAsync(escCallbackMethod) From a0310a457f4b13fe7e265c54fcae26a75179bd2f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 13 Mar 2025 09:35:52 +0800 Subject: [PATCH 7/8] =?UTF-8?q?doc:=20=E7=A7=BB=E9=99=A4=E4=B8=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs b/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs index 1a85f489d2a..54d8be133cc 100644 --- a/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs +++ b/src/BootstrapBlazor/Components/Textarea/Textarea.razor.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone -using Microsoft.AspNetCore.Components.Web; - namespace BootstrapBlazor.Components; /// From 41cb90951774537ba93dc1ffce6a4265b5574bf6 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 13 Mar 2025 09:41:24 +0800 Subject: [PATCH 8/8] chore: bump version 9.4.9-beta04 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index e14bd286f3d..d4e6cd0bbda 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 9.4.9-beta03 + 9.4.9-beta04