Skip to content

Commit d541608

Browse files
committed
refactor: 支持搜索状态切换
1 parent bf955e5 commit d541608

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

@@ -55,6 +55,7 @@ public partial class SelectCity
5555

5656
private readonly HashSet<string> _values = [];
5757
private string? _searchText;
58+
private bool _showSearch;
5859

5960
private string? GetActiveClass(string item) => CssBuilder.Default()
6061
.AddClass("active", _values.Contains(item) && IsMultiple)
@@ -75,6 +76,32 @@ protected override void OnParametersSet()
7576
{
7677
_values.Clear();
7778
}
79+
80+
if (ShowSearch == false)
81+
{
82+
_searchText = "";
83+
}
84+
}
85+
86+
/// <summary>
87+
/// <inheritdoc/>
88+
/// </summary>
89+
/// <param name="firstRender"></param>
90+
/// <returns></returns>
91+
protected override async Task OnAfterRenderAsync(bool firstRender)
92+
{
93+
await base.OnAfterRenderAsync(firstRender);
94+
95+
if (firstRender)
96+
{
97+
_showSearch = ShowSearch;
98+
}
99+
100+
if (!_showSearch != ShowSearch)
101+
{
102+
_showSearch = ShowSearch;
103+
await InvokeVoidAsync("resetSearch", Id, ShowSearch);
104+
}
78105
}
79106

80107
/// <summary>

0 commit comments

Comments
 (0)