Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.8.0-beta03</Version>
<Version>9.8.0-beta04</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 14 additions & 4 deletions src/BootstrapBlazor/Components/Table/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,18 @@
@if (ShowSearchTextTooltip)
{
<Tooltip Placement="Placement.Top" Title="@SearchTooltip" Sanitize="false" IsHtml="true">
<BootstrapInput class="table-toolbar-search" @onkeyup="OnSearchKeyUp" placeholder="@SearchPlaceholderText" @bind-Value="@SearchText" ShowLabel="false" />
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
@onkeyup="OnSearchKeyUp" Value="@SearchText" OnValueChanged="OnSearchTextValueChanged"
ShowLabel="false" UseInputEvent="AutoSearchOnInput">
</BootstrapInput>
</Tooltip>
}
else
{
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText" @bind-Value="@SearchText" ShowLabel="false" />
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
Value="@SearchText" OnValueChanged="OnSearchTextValueChanged"
ShowLabel="false" UseInputEvent="AutoSearchOnInput">
</BootstrapInput>
}
}
@if (ShowSearchButton)
Expand Down Expand Up @@ -984,13 +990,17 @@
@if (ShowSearchTextTooltip)
{
<Tooltip Placement="Placement.Top" Title="@SearchTooltip" Sanitize="false" IsHtml="true">
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText" @onkeyup="OnSearchKeyUp" @bind-Value="@SearchText" ShowLabel="false" SkipValidate="true">
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
@onkeyup="OnSearchKeyUp" Value="@SearchText" OnValueChanged="OnSearchTextValueChanged"
ShowLabel="false" SkipValidate="true" UseInputEvent="AutoSearchOnInput">
</BootstrapInput>
</Tooltip>
}
else
{
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText" @onkeyup="OnSearchKeyUp" @bind-Value="@SearchText" SkipValidate="true">
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
@onkeyup="OnSearchKeyUp" Value="@SearchText" OnValueChanged="OnSearchTextValueChanged"
SkipValidate="true" UseInputEvent="AutoSearchOnInput">
</BootstrapInput>
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/BootstrapBlazor/Components/Table/Table.razor.Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ protected List<IFilterAction> GetAdvanceSearches()
/// <returns></returns>
protected List<IFilterAction> GetSearches() => Columns.Where(col => col.GetSearchable()).ToSearches(SearchText);

private async Task OnSearchTextValueChanged(string? value)
Copy link

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since OnSearchTextValueChanged triggers a search on every input change when AutoSearchOnInput is enabled, consider debouncing the invocation of SearchClick to mitigate potential performance issues during rapid input.

Copilot uses AI. Check for mistakes.
{
SearchText = value;

await SearchClick();
}

private async Task OnSearchKeyUp(KeyboardEventArgs args)
{
if (args.Key == "Enter")
Expand Down
6 changes: 6 additions & 0 deletions src/BootstrapBlazor/Components/Table/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ namespace BootstrapBlazor.Components;
[CascadingTypeParameter(nameof(TItem))]
public partial class Table<TItem> : ITable, IModelEqualityComparer<TItem> where TItem : class
{
/// <summary>
/// Gets or sets a value indicating whether automatic search functionality is enabled. Default value is false.
/// </summary>
[Parameter]
public bool AutoSearchOnInput { get; set; }

/// <summary>
/// 获得/设置 不支持过滤类型提示信息 默认 null 读取资源文件内容
/// </summary>
Expand Down
8 changes: 5 additions & 3 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public async Task ShowSearch_Ok()
}

[Fact]
public void OnSearchKeyUp_Ok()
public async Task OnSearchKeyUp_Ok()
{
var resetSearch = false;
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
Expand All @@ -389,6 +389,7 @@ public void OnSearchKeyUp_Ok()
pb.Add(a => a.ShowToolbar, true);
pb.Add(a => a.ShowSearch, true);
pb.Add(a => a.ShowSearchText, true);
pb.Add(a => a.AutoSearchOnInput, false);
pb.Add(a => a.ShowSearchTextTooltip, false);
pb.Add(a => a.SearchMode, SearchMode.Top);
pb.Add(a => a.Items, Foo.GenerateFoo(localizer, 2));
Expand All @@ -407,8 +408,9 @@ public void OnSearchKeyUp_Ok()
});
});
var searchBox = cut.Find(".table-toolbar-search");
cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Enter" }));
cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Escape" }));
await cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Enter" }));
await cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Escape" }));
await cut.InvokeAsync(() => searchBox.Change("0"));
Assert.True(resetSearch);
}

Expand Down