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
17 changes: 9 additions & 8 deletions src/BootstrapBlazor/Components/Table/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,17 @@
{
<Tooltip Placement="Placement.Top" Title="@SearchTooltip" Sanitize="false" IsHtml="true">
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
@onkeyup="OnSearchKeyUp" Value="@SearchText"
OnValueChanged="OnSearchTextValueChanged"
Value="@SearchText" SkipValidate="true"
OnEnterAsync="OnEnterAsync" OnEscAsync="OnEscAsync"
Comment on lines +200 to +201
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

The BootstrapInput component is missing two-way binding for the Value parameter. Currently only Value="@SearchText" is set, but there's no ValueChanged handler or @bind-Value directive. This means the SearchText property will not be updated as the user types in the search box, breaking the AutoSearchOnInput feature when UseInputEvent is set to AutoSearchOnInput (true).

The OnEnterAsync and OnEscAsync callbacks only update SearchText when Enter or Esc keys are pressed, but not during regular typing. To fix this, either:

  1. Add @bind-Value="@SearchText" instead of just Value="@SearchText", OR
  2. Add ValueChanged="@((string? v) => SearchText = v)" to handle value updates

Copilot uses AI. Check for mistakes.
ShowLabel="false" UseInputEvent="AutoSearchOnInput">
</BootstrapInput>
</Tooltip>
}
else
{
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
Value="@SearchText" OnValueChanged="OnSearchTextValueChanged"
Value="@SearchText" SkipValidate="true"
OnEnterAsync="OnEnterAsync" OnEscAsync="OnEscAsync"
Comment on lines +209 to +210
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

Same issue as the first BootstrapInput instance: missing two-way binding for the Value parameter. The SearchText property will not be updated as the user types, breaking the AutoSearchOnInput feature. Add @bind-Value="@SearchText" instead of just Value="@SearchText", or add ValueChanged="@((string? v) => SearchText = v)".

Copilot uses AI. Check for mistakes.
ShowLabel="false" UseInputEvent="AutoSearchOnInput">
</BootstrapInput>
}
Expand Down Expand Up @@ -1049,18 +1050,18 @@
{
<Tooltip Placement="Placement.Top" Title="@SearchTooltip" Sanitize="false" IsHtml="true">
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
@onkeyup="OnSearchKeyUp" Value="@SearchText"
OnValueChanged="OnSearchTextValueChanged"
Value="@SearchText"
OnEnterAsync="OnEnterAsync" OnEscAsync="OnEscAsync"
Comment on lines +1053 to +1054
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

Same issue: missing two-way binding for the Value parameter. The SearchText property will not be updated as the user types, breaking the AutoSearchOnInput feature. Add @bind-Value="@SearchText" instead of just Value="@SearchText", or add ValueChanged="@((string? v) => SearchText = v)".

Copilot uses AI. Check for mistakes.
ShowLabel="false" SkipValidate="true" UseInputEvent="AutoSearchOnInput">
</BootstrapInput>
</Tooltip>
}
else
{
<BootstrapInput class="table-toolbar-search" placeholder="@SearchPlaceholderText"
@onkeyup="OnSearchKeyUp" Value="@SearchText"
OnValueChanged="OnSearchTextValueChanged"
SkipValidate="true" UseInputEvent="AutoSearchOnInput">
Value="@SearchText"
OnEnterAsync="OnEnterAsync" OnEscAsync="OnEscAsync"
Comment on lines +1062 to +1063
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

Same issue: missing two-way binding for the Value parameter. The SearchText property will not be updated as the user types, breaking the AutoSearchOnInput feature. Add @bind-Value="@SearchText" instead of just Value="@SearchText", or add ValueChanged="@((string? v) => SearchText = v)".

Copilot uses AI. Check for mistakes.
ShowLabel="false" SkipValidate="true" UseInputEvent="AutoSearchOnInput">
</BootstrapInput>
}
}
Expand Down
39 changes: 15 additions & 24 deletions src/BootstrapBlazor/Components/Table/Table.razor.Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +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;
using System.Reflection;

namespace BootstrapBlazor.Components;
Expand Down Expand Up @@ -163,11 +162,22 @@ protected async Task ResetSearchClick()
Utility.Reset(SearchModel, CreateSearchModel());
}

PageIndex = 1;
await QueryAsync();
await SearchClick();
await ToggleLoading(false);
}

private async Task OnEnterAsync(string? v)
{
SearchText = v;
await SearchClick();
}

private async Task OnEscAsync(string? v)
{
SearchText = null;
await ResetSearchClick();
}

/// <summary>
/// <para lang="zh">查询方法</para>
/// <para lang="en">Search Method</para>
Expand Down Expand Up @@ -304,28 +314,9 @@ protected List<IFilterAction> GetAdvanceSearches()
/// </summary>
protected List<IFilterAction> GetSearches() => Columns.Where(col => col.GetSearchable()).ToSearches(SearchText);

private async Task OnSearchTextValueChanged(string? value)
{
SearchText = value;

await SearchClick();
}

private async Task OnSearchKeyUp(KeyboardEventArgs args)
{
if (args.Key == "Enter")
{
await SearchClick();
}
else if (args.Key == "Escape")
{
await ClearSearchClick();
}
}

/// <summary>
/// <para lang="zh">重置搜索按钮调用此方法</para>
/// <para lang="en">Reset Search Button Click Method</para>
/// <para lang="zh">点击重置搜索按钮时调用此方法</para>
/// <para lang="en">Method called when the reset search button is clicked</para>
/// </summary>
protected async Task ClearSearchClick()
{
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/Table/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace BootstrapBlazor.Components;
public partial class Table<TItem> : ITable, IModelEqualityComparer<TItem> where TItem : class
{
/// <summary>
/// <para lang="zh">获得/设置 a value indicating 是否 automatic search functionality is enabled. 默认 value is false</para>
/// <para lang="en">Gets or sets a value indicating whether automatic search functionality is enabled. Default value is false</para>
/// <para lang="zh">获得/设置 模糊搜索栏输入时是否自动搜索 默认值 false</para>
/// <para lang="en">Gets or sets whether to auto search on fuzzy search bar input. Default false</para>
/// </summary>
[Parameter]
public bool AutoSearchOnInput { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ public async Task OnSearchKeyUp_Ok()
});
});
});
var searchBox = cut.Find(".table-toolbar-search");
await cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Enter" }));
await cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Escape" }));
await cut.InvokeAsync(() => searchBox.Change("0"));
var searchBox = cut.FindComponents<BootstrapInput<string?>>().FirstOrDefault(i => i.Markup.Contains("table-toolbar-search"));
Assert.NotNull(searchBox);
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

The test no longer verifies that typing in the search box updates the SearchText property. The removed line searchBox.Change("0") was testing value updates through user input. While the new test verifies the EnterCallback and EscCallback work, it doesn't test the core functionality of the search box accepting and propagating user input. Consider adding a test that verifies SearchText is updated when the user types in the search box, not just when Enter/Esc keys are pressed.

Suggested change
Assert.NotNull(searchBox);
Assert.NotNull(searchBox);
// Simulate user typing in the search box and verify that the table's SearchText is updated
searchBox.Change("0");
var table = cut.FindComponent<Table<Foo>>();
Assert.Equal("0", table.Instance.SearchText);

Copilot uses AI. Check for mistakes.
await cut.InvokeAsync(() => searchBox.Instance.EnterCallback());
await cut.InvokeAsync(() => searchBox.Instance.EscCallback());
Assert.True(resetSearch);
}

Expand Down