Skip to content

Commit 60fba29

Browse files
committed
fix: 重构固定搜索栏功能
1 parent ae59f14 commit 60fba29

File tree

2 files changed

+56
-49
lines changed

2 files changed

+56
-49
lines changed

src/BootstrapBlazor/Components/Select/MultiSelect.razor

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -48,63 +48,71 @@
4848
<span class="@AppendClassString"><i class="@DropdownIcon"></i></span>
4949
}
5050
</div>
51-
<div class="dropdown-menu">
52-
<div class="@SearchClassString">
53-
<input type="text" class="form-control search-text" autocomplete="off" value="@SearchText" aria-label="search" />
54-
<i class="@SearchIconString"></i>
55-
<i class="@SearchLoadingIconString"></i>
56-
</div>
57-
@if (ShowToolbar)
51+
<div class="@DropdownMenuClassString">
52+
@if (ShowSearch)
5853
{
59-
<div class="toolbar">
60-
@if (ShowDefaultButtons)
61-
{
62-
<DynamicElement TagName="button" type="button" class="btn" OnClick="SelectAll">@SelectAllText</DynamicElement>
63-
<DynamicElement TagName="button" type="button" class="btn" OnClick="InvertSelect">@ReverseSelectText</DynamicElement>
64-
<DynamicElement TagName="button" type="button" class="btn" OnClick="Clear">@ClearText</DynamicElement>
65-
}
66-
@ButtonTemplate
54+
<div class="dropdown-menu-search">
55+
<input type="text" class="search-text form-control" autocomplete="off" value="@SearchText" aria-label="search" />
56+
<i class="@SearchIconString"></i>
57+
<i class="@SearchLoadingIconString"></i>
6758
</div>
6859
}
69-
@foreach (var itemGroup in Rows.GroupBy(i => i.GroupName))
60+
@if (Rows.Count == 0)
7061
{
71-
if (!string.IsNullOrEmpty(itemGroup.Key))
72-
{
73-
if (GroupItemTemplate != null)
74-
{
75-
@GroupItemTemplate(itemGroup.Key)
76-
}
77-
else
62+
<div class="dropdown-item">@NoSearchDataText</div>
63+
}
64+
else
65+
{
66+
<div class="dropdown-menu-body">
67+
@if (ShowToolbar)
7868
{
79-
<Divider Text="@itemGroup.Key" />
80-
}
81-
}
82-
@foreach (var item in itemGroup)
83-
{
84-
<DynamicElement OnClick="() => ToggleRow(item.Value)" TriggerClick="@CheckCanTrigger(item)" class="@GetItemClassString(item)">
85-
<div class="multi-select-item">
86-
<div class="form-check">
87-
<input class="form-check-input" type="checkbox" disabled="@CheckCanSelect(item)" checked="@GetCheckedString(item)" />
88-
</div>
89-
@if (ItemTemplate != null)
69+
<div class="toolbar">
70+
@if (ShowDefaultButtons)
9071
{
91-
@ItemTemplate(item)
72+
<DynamicElement TagName="button" type="button" class="btn" OnClick="SelectAll">@SelectAllText</DynamicElement>
73+
<DynamicElement TagName="button" type="button" class="btn" OnClick="InvertSelect">@ReverseSelectText</DynamicElement>
74+
<DynamicElement TagName="button" type="button" class="btn" OnClick="Clear">@ClearText</DynamicElement>
9275
}
93-
else if (IsMarkupString)
76+
@ButtonTemplate
77+
</div>
78+
}
79+
@foreach (var itemGroup in Rows.GroupBy(i => i.GroupName))
80+
{
81+
if (!string.IsNullOrEmpty(itemGroup.Key))
82+
{
83+
if (GroupItemTemplate != null)
9484
{
95-
@((MarkupString)item.Text)
85+
@GroupItemTemplate(itemGroup.Key)
9686
}
9787
else
9888
{
99-
<span>@item.Text</span>
89+
<Divider Text="@itemGroup.Key" />
10090
}
101-
</div>
102-
</DynamicElement>
103-
}
104-
}
105-
@if (Rows.Count == 0)
106-
{
107-
<div class="dropdown-item">@NoSearchDataText</div>
91+
}
92+
@foreach (var item in itemGroup)
93+
{
94+
<DynamicElement OnClick="() => ToggleRow(item.Value)" TriggerClick="@CheckCanTrigger(item)" class="@GetItemClassString(item)">
95+
<div class="multi-select-item">
96+
<div class="form-check">
97+
<input class="form-check-input" type="checkbox" disabled="@CheckCanSelect(item)" checked="@GetCheckedString(item)" />
98+
</div>
99+
@if (ItemTemplate != null)
100+
{
101+
@ItemTemplate(item)
102+
}
103+
else if (IsMarkupString)
104+
{
105+
@((MarkupString)item.Text)
106+
}
107+
else
108+
{
109+
<span>@item.Text</span>
110+
}
111+
</div>
112+
</DynamicElement>
113+
}
114+
}
115+
</div>
108116
}
109117
</div>
110118
</div>

src/BootstrapBlazor/Components/Select/MultiSelect.razor.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,15 @@ public partial class MultiSelect<TValue>
4040
.AddClass("d-none", SelectedItems.Count != 0)
4141
.Build();
4242

43-
private string? SearchClassString => CssBuilder.Default("search")
44-
.AddClass("show", ShowSearch)
45-
.Build();
46-
4743
/// <summary>
4844
/// 获得 SearchLoadingIcon 图标字符串
4945
/// </summary>
5046
private string? SearchLoadingIconString => CssBuilder.Default("icon searching-icon")
5147
.AddClass(SearchLoadingIcon)
5248
.Build();
49+
private string? DropdownMenuClassString => CssBuilder.Default("dropdown-menu")
50+
.AddClass("is-fixed-search", ShowSearch && IsFixedSearch)
51+
.Build();
5352

5453
/// <summary>
5554
/// 获得/设置 绑定数据集

0 commit comments

Comments
 (0)