Skip to content

Commit a674583

Browse files
authored
Merge branch 'main' into studder
Signed-off-by: celadaris <amorales13r@gmail.com>
2 parents fd89544 + 698666c commit a674583

4 files changed

Lines changed: 43 additions & 9 deletions

File tree

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.5.6-beta04</Version>
4+
<Version>9.5.6-beta05</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ protected override void OnInitialized()
118118
if (!string.IsNullOrEmpty(Value))
119119
{
120120
_filterItems = GetFilterItemsByValue(Value); // Use the new helper
121+
121122
if (DisplayCount != null)
122123
{
123124
_filterItems = [.. _filterItems.Take(DisplayCount.Value)];
@@ -240,6 +241,7 @@ public async Task PerformFilteringAndCommitValue(string val)
240241
else
241242
{
242243
// Use the helper method for standard filtering
244+
243245
_filterItems = GetFilterItemsByValue(val);
244246
}
245247

@@ -255,6 +257,15 @@ public async Task PerformFilteringAndCommitValue(string val)
255257
_shouldRender = true;
256258
}
257259

260+
private List<string> GetFilterItemsByValue(string val)
261+
{
262+
var comparison = IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
263+
var items = IsLikeMatch
264+
? Items.Where(s => s.Contains(val, comparison))
265+
: Items.Where(s => s.StartsWith(val, comparison));
266+
return [.. items];
267+
}
268+
258269
/// <summary>
259270
/// REMOVED: Original TriggerChange method.
260271
/// Its functionality (updating value, rendering dropdown) is now handled by

src/BootstrapBlazor/Components/Watermark/Watermark.razor.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ export function dispose(id) {
4141
Data.remove(id);
4242

4343
if (watermark) {
44-
const { ob } = watermark;
44+
const { el, ob } = watermark;
4545
ob.disconnect();
4646

4747
delete watermark.ob;
48+
document.body.removeAttribute('data-bb-watermark');
49+
el.remove();
4850
}
4951
}
5052

@@ -102,13 +104,13 @@ const createWatermark = watermark => {
102104
if (mark) {
103105
mark.remove();
104106
}
107+
el.appendChild(div);
105108

106-
if (bg.isPage) {
107-
document.body.appendChild(div);
108-
}
109-
else {
110-
el.appendChild(div);
109+
if (options.isPage) {
110+
document.body.setAttribute('data-bb-watermark', "true");
111+
document.body.appendChild(el);
111112
}
113+
112114
options.bg = bg;
113115
requestAnimationFrame(() => monitor(watermark));
114116
}
@@ -179,8 +181,12 @@ const monitor = watermark => {
179181

180182
const clearWatermark = watermark => {
181183
const { el, ob } = watermark;
182-
ob.disconnect();
183-
el.innerHTML = '';
184+
if (ob) {
185+
ob.disconnect();
186+
}
187+
if (el) {
188+
el.innerHTML = '';
189+
}
184190
}
185191

186192
const getWatermark = props => {

test/UnitTest/Components/AutoCompleteTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ public async Task Items_Ok()
4040
Assert.Equal("Test", cut.Instance.Value);
4141
}
4242

43+
[Fact]
44+
public void Value_Ok()
45+
{
46+
var cut = Context.RenderComponent<AutoComplete>(pb =>
47+
{
48+
pb.Add(a => a.Items, new List<string>() { "test1", "test12", "test123", "test1234" });
49+
pb.Add(a => a.Value, "test12");
50+
pb.Add(a => a.DisplayCount, 2);
51+
});
52+
var menus = cut.FindAll(".dropdown-item");
53+
54+
// 由于 Value = test12
55+
// 并且设置了 DisplayCount = 2
56+
// 候选项只有 2 个
57+
Assert.Equal(2, menus.Count);
58+
}
59+
4360
[Fact]
4461
public void Debounce_Ok()
4562
{

0 commit comments

Comments
 (0)