Skip to content

Commit 560bb21

Browse files
ArgoZhangJaders77
andauthored
feat(Table): add AutoSearchOnInput parameter (#6306)
* feat: add AutoSearchOnInput parameter * feat: 更新代码 * test: 更新单元测试 * chore: bump version 9.8.0-beta04 Co-Authored-By: Jaders77 <[email protected]> --------- Co-authored-by: Jaders77 <[email protected]>
1 parent 29d02df commit 560bb21

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
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.8.0-beta03</Version>
4+
<Version>9.8.0-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Table/Table.razor

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,18 @@
169169
@if (ShowSearchTextTooltip)
170170
{
171171
<Tooltip Placement="Placement.Top" Title="@SearchTooltip" Sanitize="false" IsHtml="true">
172-
<BootstrapInput class="table-toolbar-search" @onkeyup="OnSearchKeyUp" placeholder="@SearchPlaceholderText" @bind-Value="@SearchText" ShowLabel="false" />
172+
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
173+
@onkeyup="OnSearchKeyUp" Value="@SearchText" OnValueChanged="OnSearchTextValueChanged"
174+
ShowLabel="false" UseInputEvent="AutoSearchOnInput">
175+
</BootstrapInput>
173176
</Tooltip>
174177
}
175178
else
176179
{
177-
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText" @bind-Value="@SearchText" ShowLabel="false" />
180+
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
181+
Value="@SearchText" OnValueChanged="OnSearchTextValueChanged"
182+
ShowLabel="false" UseInputEvent="AutoSearchOnInput">
183+
</BootstrapInput>
178184
}
179185
}
180186
@if (ShowSearchButton)
@@ -984,13 +990,17 @@
984990
@if (ShowSearchTextTooltip)
985991
{
986992
<Tooltip Placement="Placement.Top" Title="@SearchTooltip" Sanitize="false" IsHtml="true">
987-
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText" @onkeyup="OnSearchKeyUp" @bind-Value="@SearchText" ShowLabel="false" SkipValidate="true">
993+
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
994+
@onkeyup="OnSearchKeyUp" Value="@SearchText" OnValueChanged="OnSearchTextValueChanged"
995+
ShowLabel="false" SkipValidate="true" UseInputEvent="AutoSearchOnInput">
988996
</BootstrapInput>
989997
</Tooltip>
990998
}
991999
else
9921000
{
993-
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText" @onkeyup="OnSearchKeyUp" @bind-Value="@SearchText" SkipValidate="true">
1001+
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
1002+
@onkeyup="OnSearchKeyUp" Value="@SearchText" OnValueChanged="OnSearchTextValueChanged"
1003+
SkipValidate="true" UseInputEvent="AutoSearchOnInput">
9941004
</BootstrapInput>
9951005
}
9961006
}

src/BootstrapBlazor/Components/Table/Table.razor.Search.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ protected List<IFilterAction> GetAdvanceSearches()
279279
/// <returns></returns>
280280
protected List<IFilterAction> GetSearches() => Columns.Where(col => col.GetSearchable()).ToSearches(SearchText);
281281

282+
private async Task OnSearchTextValueChanged(string? value)
283+
{
284+
SearchText = value;
285+
286+
await SearchClick();
287+
}
288+
282289
private async Task OnSearchKeyUp(KeyboardEventArgs args)
283290
{
284291
if (args.Key == "Enter")

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ namespace BootstrapBlazor.Components;
1616
[CascadingTypeParameter(nameof(TItem))]
1717
public partial class Table<TItem> : ITable, IModelEqualityComparer<TItem> where TItem : class
1818
{
19+
/// <summary>
20+
/// Gets or sets a value indicating whether automatic search functionality is enabled. Default value is false.
21+
/// </summary>
22+
[Parameter]
23+
public bool AutoSearchOnInput { get; set; }
24+
1925
/// <summary>
2026
/// 获得/设置 不支持过滤类型提示信息 默认 null 读取资源文件内容
2127
/// </summary>

test/UnitTest/Components/TableTest.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public async Task ShowSearch_Ok()
377377
}
378378

379379
[Fact]
380-
public void OnSearchKeyUp_Ok()
380+
public async Task OnSearchKeyUp_Ok()
381381
{
382382
var resetSearch = false;
383383
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
@@ -389,6 +389,7 @@ public void OnSearchKeyUp_Ok()
389389
pb.Add(a => a.ShowToolbar, true);
390390
pb.Add(a => a.ShowSearch, true);
391391
pb.Add(a => a.ShowSearchText, true);
392+
pb.Add(a => a.AutoSearchOnInput, false);
392393
pb.Add(a => a.ShowSearchTextTooltip, false);
393394
pb.Add(a => a.SearchMode, SearchMode.Top);
394395
pb.Add(a => a.Items, Foo.GenerateFoo(localizer, 2));
@@ -407,8 +408,9 @@ public void OnSearchKeyUp_Ok()
407408
});
408409
});
409410
var searchBox = cut.Find(".table-toolbar-search");
410-
cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Enter" }));
411-
cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Escape" }));
411+
await cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Enter" }));
412+
await cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Escape" }));
413+
await cut.InvokeAsync(() => searchBox.Change("0"));
412414
Assert.True(resetSearch);
413415
}
414416

0 commit comments

Comments
 (0)