diff --git a/src/BootstrapBlazor.Shared/Locales/en.json b/src/BootstrapBlazor.Shared/Locales/en.json index 57c3e3a641bd973c34fd26d72bd429c40a0808a2..72bdcd54a1ce1b9e7179a986653c15d476935a93 100644 --- a/src/BootstrapBlazor.Shared/Locales/en.json +++ b/src/BootstrapBlazor.Shared/Locales/en.json @@ -1239,7 +1239,11 @@ "Att10": "Whether to disable Fasle by default", "Att11": "Whether to get the focus automatically Default is fasle", "IsSelectAllTextOnFocus": "Whether auto select the all text after focus", - "ValidateRules": "Customer validation collection" + "IsSelectAllTextOnEnter": "Whether auto select the all text after presses enter", + "SelectAllTextAsync": "Select the all text method", + "ValidateRules": "Customer validation collection", + "P8": "Use IsSelectAllTextOnEnter The user presses enter to select the all text", + "P9": "Execute @ref.SelectAllTextAsync() method select the all text" }, "BootstrapBlazor.Shared.Samples.InputNumbers": { "Title": "InputNumber", diff --git a/src/BootstrapBlazor.Shared/Locales/zh.json b/src/BootstrapBlazor.Shared/Locales/zh.json index 1b0e868535738e7ef6539a3c85ce36df89fe79c7..2ee928b8d1a5862fb78e5464b5ab68ba68587d2d 100644 --- a/src/BootstrapBlazor.Shared/Locales/zh.json +++ b/src/BootstrapBlazor.Shared/Locales/zh.json @@ -1241,7 +1241,12 @@ "Att10": "是否禁用", "Att11": "是否自动获取焦点", "IsSelectAllTextOnFocus": "获得焦点后自动选择输入框内所有字符串", - "ValidateRules": "自定义验证集合" + "IsSelectAllTextOnEnter": "Enter 键自动选择输入框内所有字符串", + "SelectAllTextAsync": "选择输入框内所有字符串方法", + "ValidateRules": "自定义验证集合", + "P8": "可通过设置 IsSelectAllTextOnEnter 用户按下 Enter 键自动选择输入框内所有字符串 ", + "P9": "执行 @ref.SelectAllTextAsync() 选择输入框内所有字符串" + }, "BootstrapBlazor.Shared.Samples.InputNumbers": { "Title": "InputNumber 组件", diff --git a/src/BootstrapBlazor.Shared/Samples/Inputs.razor b/src/BootstrapBlazor.Shared/Samples/Inputs.razor index 0bffc95ce7bb8880468c653af9b89328c7afda19..7f4c2991456ae586c8e6a583a50e96ad59932abb 100644 --- a/src/BootstrapBlazor.Shared/Samples/Inputs.razor +++ b/src/BootstrapBlazor.Shared/Samples/Inputs.razor @@ -15,7 +15,16 @@ - +
+
+ @Localizer["Span1"] +
+
+ +
+
+ +
@@ -52,8 +61,17 @@
@((MarkupString)Localizer["Div1"].Value)
+

@((MarkupString)Localizer["P9"].Value)

+
+
+ @Localizer["Span1"] +
+
+ +
+
-
+
diff --git a/src/BootstrapBlazor.Shared/Samples/Inputs.razor.cs b/src/BootstrapBlazor.Shared/Samples/Inputs.razor.cs index 8c35cdd68cccc1e904653fb2cb47f8f57239c123..982fa0a306570cf74b9a556fa9e8bf3d9219a326 100644 --- a/src/BootstrapBlazor.Shared/Samples/Inputs.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/Inputs.razor.cs @@ -27,6 +27,8 @@ public partial class Inputs [NotNull] private BlockLogger? Trace { get; set; } + BootstrapInput? input1; + /// /// /// @@ -49,6 +51,12 @@ public partial class Inputs Trace.Log($"Esc {Localizer["Log"]}: {val}"); return Task.CompletedTask; } + + private async Task OnEnterSelectAllAsync(string val) + { + Trace.Log($"Enter call SelectAllText {Localizer["Log"]}: {val}"); + await input1!.SelectAllTextAsync(); + } private IEnumerable GetAttributes() => new[] { diff --git a/src/BootstrapBlazor/Components/Input/BootstrapInput.js b/src/BootstrapBlazor/Components/Input/BootstrapInput.js index e0ec1de2e8cd20c06597b4196d20b95500a58f42..5e057fd29060571d7254f8df3200e4ce90ecae48 100644 --- a/src/BootstrapBlazor/Components/Input/BootstrapInput.js +++ b/src/BootstrapBlazor/Components/Input/BootstrapInput.js @@ -11,11 +11,22 @@ } }); }, - bb_input_selectAll: function (el) { + bb_input_selectAll_focus: function (el) { var $el = $(el); $el.on('focus', function () { $(this).select(); }); + }, + bb_input_selectAll_enter: function (el) { + var $el = $(el); + $el.on('keyup', function (e) { + if (e.key === 'Enter') { + $(this).select(); + } + }); + }, + bb_input_selectAll: function (el) { + $(el).select(); } }); })(jQuery); diff --git a/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs b/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs index 93230d2e3b76caaa17b8e646cc73eff87da1f08e..a962b0882895052d1c935ce34c1a4f0c5718c95b 100644 --- a/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs +++ b/src/BootstrapBlazor/Components/Input/BootstrapInputBase.cs @@ -73,6 +73,12 @@ public abstract class BootstrapInputBase : ValidateBase [Parameter] public bool IsSelectAllTextOnFocus { get; set; } + /// + /// 获得/设置 Enter 键自动选择输入框内所有字符串 默认 false 未启用 + /// + [Parameter] + public bool IsSelectAllTextOnEnter { get; set; } + /// /// 获得/设置 是否自动修剪空白 默认 false 未启用 /// @@ -93,6 +99,12 @@ public abstract class BootstrapInputBase : ValidateBase /// public ValueTask FocusAsync() => FocusElement.FocusAsync(); + /// + /// 全选文字 + /// + /// + public async ValueTask SelectAllTextAsync() => await JSRuntime.InvokeVoidAsync(FocusElement, "bb_input_selectAll"); + private JSInterop>? Interop { get; set; } /// @@ -135,7 +147,11 @@ public abstract class BootstrapInputBase : ValidateBase } if (IsSelectAllTextOnFocus) { - await JSRuntime.InvokeVoidAsync(FocusElement, "bb_input_selectAll"); + await JSRuntime.InvokeVoidAsync(FocusElement, "bb_input_selectAll_focus"); + } + if (IsSelectAllTextOnEnter) + { + await JSRuntime.InvokeVoidAsync(FocusElement, "bb_input_selectAll_enter"); } if (IsAutoFocus) { diff --git a/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js b/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js index 1d9eb6e70943f587dcc0ab6ced57defc81f14eb7..2d5730179ded85563a7fb34f75a828a80b9e110f 100644 --- a/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js +++ b/src/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js @@ -13,4 +13,4 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this /*! Summernote v0.8.18 | (c) 2013- Alan Hong and other contributors | MIT license */ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("jquery"));else if("function"==typeof define&&define.amd)define(["jquery"],e);else{var n="object"==typeof exports?e(require("jquery")):e(t.jQuery);for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}(self,(function(t){return(()=>{"use strict";var e={9458:e=>{e.exports=t}},n={};function o(t){var i=n[t];if(void 0!==i)return i.exports;var r=n[t]={exports:{}};return e[t](r,r.exports,o),r.exports}o.amdO={},o.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return o.d(e,{a:e}),e},o.d=(t,e)=>{for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{o.r(i);var t=o(9458),e=o.n(t);function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e){for(var n=0;n'),u=s('