Skip to content

Commit 85b22b1

Browse files
ArgoZhangice6
andauthored
feat(Input): use IsClearable instead of Clearable (#5108)
* refactor: 重构参数名称 * doc: 更新示例 * test: 更新单元测试 Co-Authored-By: ice6 <[email protected]>
1 parent 6a85589 commit 85b22b1

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

src/BootstrapBlazor.Server/Components/Samples/Inputs.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,24 +227,24 @@
227227
Name="OnInput">
228228
<div class="row g-3">
229229
<div class="col-12 col-sm-6">
230-
<BootstrapInput Value="Model.Name" Clearable="true" ShowLabel="true" DisplayText="Clearable" />
230+
<BootstrapInput Value="Model.Name" IsClearable="true" ShowLabel="true" DisplayText="Clearable" />
231231
</div>
232232
</div>
233233
<div class="row form-inline g-3 mt-0">
234234
<div class="col-12 col-sm-6">
235-
<BootstrapInput Value="Model.Name" Clearable="true" ShowLabel="true" DisplayText="Clearable" />
235+
<BootstrapInput Value="Model.Name" IsClearable="true" ShowLabel="true" DisplayText="Clearable" />
236236
</div>
237237
</div>
238238
<div class="row g-3 mt-0">
239239
<div class="col-12 col-sm-6">
240240
<BootstrapInputGroup>
241241
<BootstrapInputGroupLabel ShowRequiredMark DisplayText="Clearable"></BootstrapInputGroupLabel>
242-
<BootstrapInput Value="@Model.Name" Clearable="true" />
242+
<BootstrapInput Value="@Model.Name" IsClearable="true" />
243243
</BootstrapInputGroup>
244244
</div>
245245
<div class="col-12 col-sm-6">
246246
<BootstrapInputGroup>
247-
<BootstrapInput Value="@Model.Name" Clearable="true" />
247+
<BootstrapInput Value="@Model.Name" IsClearable="true" />
248248
<BootstrapInputGroupLabel ShowRequiredMark DisplayText="Clearable"></BootstrapInputGroupLabel>
249249
</BootstrapInputGroup>
250250
</div>

src/BootstrapBlazor/Components/Input/BootstrapInput.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<BootstrapLabel required="@Required" for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
88
}
99

10-
@if (Clearable)
10+
@if (IsClearable)
1111
{
1212
<div class="bb-clearable-input">
1313
@RenderInput

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ public partial class BootstrapInput<TValue>
2626
/// 获得/设置 是否显示清空小按钮 默认 false
2727
/// </summary>
2828
[Parameter]
29-
public bool Clearable { get; set; }
29+
[Obsolete("已弃用,请使用 IsClearable 参数;Deprecated use the IsClearable parameter")]
30+
[ExcludeFromCodeCoverage]
31+
public bool Clearable { get => IsClearable; set => IsClearable = value; }
32+
33+
/// <summary>
34+
/// 获得/设置 是否显示清空小按钮 默认 false
35+
/// </summary>
36+
[Parameter]
37+
public bool IsClearable { get; set; }
3038

3139
/// <summary>
3240
/// 获得/设置 清空文本框时回调方法 默认 null
@@ -38,7 +46,15 @@ public partial class BootstrapInput<TValue>
3846
/// 获得/设置 清空小按钮图标 默认 null
3947
/// </summary>
4048
[Parameter]
41-
public string? ClearableIcon { get; set; }
49+
[Obsolete("已弃用,请使用 ClearIcon 参数;Deprecated use the ClearIcon parameter")]
50+
[ExcludeFromCodeCoverage]
51+
public string? ClearableIcon { get => ClearIcon; set => ClearIcon = value; }
52+
53+
/// <summary>
54+
/// 获得/设置 清空小按钮图标 默认 null
55+
/// </summary>
56+
[Parameter]
57+
public string? ClearIcon { get; set; }
4258

4359
/// <summary>
4460
/// 图标主题服务
@@ -50,7 +66,7 @@ public partial class BootstrapInput<TValue>
5066
private string? ReadonlyString => Readonly ? "true" : null;
5167

5268
private string? ClearableIconString => CssBuilder.Default("form-control-clear-icon")
53-
.AddClass(ClearableIcon)
69+
.AddClass(ClearIcon)
5470
.Build();
5571

5672
/// <summary>
@@ -60,7 +76,7 @@ protected override void OnParametersSet()
6076
{
6177
base.OnParametersSet();
6278

63-
ClearableIcon ??= IconTheme.GetIconByKey(ComponentIcons.InputClearIcon);
79+
ClearIcon ??= IconTheme.GetIconByKey(ComponentIcons.InputClearIcon);
6480
}
6581

6682
/// <summary>

test/UnitTest/Components/InputTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ public void Readonly_Ok()
7272
[Fact]
7373
public void Clearable_Ok()
7474
{
75-
var cut = Context.RenderComponent<BootstrapInput<string>>(builder => builder.Add(a => a.Clearable, false));
75+
var cut = Context.RenderComponent<BootstrapInput<string>>(builder => builder.Add(a => a.IsClearable, false));
7676
cut.DoesNotContain("bb-clearable-input");
7777

78-
cut.SetParametersAndRender(pb => pb.Add(a => a.Clearable, true));
78+
cut.SetParametersAndRender(pb => pb.Add(a => a.IsClearable, true));
7979
cut.Contains("bb-clearable-input");
8080
cut.Contains("form-control-clear-icon");
8181

@@ -93,7 +93,7 @@ public async Task OnClear_Ok()
9393
var clicked = false;
9494
var cut = Context.RenderComponent<BootstrapInput<string>>(builder =>
9595
{
96-
builder.Add(a => a.Clearable, true);
96+
builder.Add(a => a.IsClearable, true);
9797
builder.Add(a => a.OnClear, v =>
9898
{
9999
clicked = true;

0 commit comments

Comments
 (0)