Skip to content

Commit a4748c4

Browse files
authored
feat(ListGroup): add OnDoubleClickItem callback (#6777)
* feat: 增加 OnDoubleClickItem 回调方法 * doc: 更新示例 * doc: 增加本地化 * revert: 撤销条件更改 * test: 增加单元测试 * doc: 格式化内容 * doc: 格式化
1 parent 9c883de commit a4748c4

File tree

6 files changed

+52
-4
lines changed

6 files changed

+52
-4
lines changed

src/BootstrapBlazor.Server/Components/Samples/ListGroups.razor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ private AttributeItem[] GetAttributes() =>
8787
DefaultValue = " — "
8888
},
8989
new()
90+
{
91+
Name = "OnDoubleClickItem",
92+
Description = Localizer["AttrOnDoubleClickItem"],
93+
Type = "Func<TItem, Task>",
94+
ValueList = " — ",
95+
DefaultValue = " — "
96+
},
97+
new()
9098
{
9199
Name = "GetItemDisplayText",
92100
Description = Localizer["GetItemDisplayText"],

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6488,6 +6488,7 @@
64886488
"AttrHeaderText": "the title of Header",
64896489
"AttrItemTemplate": "the template of Item",
64906490
"AttrOnClickItem": "the callback on click item",
6491+
"AttrOnDoubleClickItem": "the callback on double click item",
64916492
"GetItemDisplayText": "the callback on get item display text"
64926493
},
64936494
"BootstrapBlazor.Server.Components.Samples.Marquees": {

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6488,6 +6488,7 @@
64886488
"AttrHeaderText": "标题栏文字",
64896489
"AttrItemTemplate": "选项模板",
64906490
"AttrOnClickItem": "点击候选项回调方法",
6491+
"AttrOnDoubleClickItem": "双击候选项回调方法",
64916492
"GetItemDisplayText": "获得显示项显示内容回调方法"
64926493
},
64936494
"BootstrapBlazor.Server.Components.Samples.Marquees": {

src/BootstrapBlazor/Components/ListGroup/ListGroup.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<div class="list-group-body scroll">
1515
@foreach (var item in Items)
1616
{
17-
<div @key="item" class="@GetItemClassString(item)" @onclick="() => OnClick(item)">
17+
<div @key="item" class="@GetItemClassString(item)"
18+
@onclick="() => OnClick(item)" @ondblclick="() => OnDoubleClick(item)">
1819
@if (ItemTemplate != null)
1920
{
2021
@ItemTemplate(item)

src/BootstrapBlazor/Components/ListGroup/ListGroup.razor.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public partial class ListGroup<TItem>
4444
[Parameter]
4545
public Func<TItem, Task>? OnClickItem { get; set; }
4646

47+
/// <summary>
48+
/// 获得/设置 双击 List 项目回调方法
49+
/// </summary>
50+
[Parameter]
51+
public Func<TItem, Task>? OnDoubleClickItem { get; set; }
52+
4753
/// <summary>
4854
/// 获得/设置 获得条目显示文本内容回调方法
4955
/// </summary>
@@ -78,4 +84,13 @@ private async Task OnClick(TItem item)
7884
}
7985
CurrentValue = item;
8086
}
87+
88+
private async Task OnDoubleClick(TItem item)
89+
{
90+
if (OnDoubleClickItem != null)
91+
{
92+
await OnDoubleClickItem(item);
93+
}
94+
CurrentValue = item;
95+
}
8196
}

test/UnitTest/Components/ListGroupTest.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Items_Ok()
2727
}
2828

2929
[Fact]
30-
public void ClickItem_Ok()
30+
public async Task ClickItem_Ok()
3131
{
3232
var clicked = false;
3333
var cut = Context.RenderComponent<ListGroup<Foo>>(pb =>
@@ -44,8 +44,30 @@ public void ClickItem_Ok()
4444
});
4545
});
4646
var item = cut.Find(".list-group-item");
47-
item.Click();
48-
cut.WaitForState(() => clicked);
47+
await cut.InvokeAsync(() => item.Click());
48+
Assert.True(clicked);
49+
}
50+
51+
[Fact]
52+
public async Task DoubleClickItem_Ok()
53+
{
54+
var clicked = false;
55+
var cut = Context.RenderComponent<ListGroup<Foo>>(pb =>
56+
{
57+
pb.Add(a => a.Items,
58+
[
59+
new() { Name = "Test 1" },
60+
new() { Name = "Test 1" }
61+
]);
62+
pb.Add(a => a.OnDoubleClickItem, foo =>
63+
{
64+
clicked = true;
65+
return Task.CompletedTask;
66+
});
67+
});
68+
var item = cut.Find(".list-group-item");
69+
await cut.InvokeAsync(() => item.DoubleClick());
70+
Assert.True(clicked);
4971
}
5072

5173
[Fact]

0 commit comments

Comments
 (0)