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
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ private AttributeItem[] GetAttributes() =>
DefaultValue = " — "
},
new()
{
Name = "OnDoubleClickItem",
Description = Localizer["AttrOnDoubleClickItem"],
Type = "Func<TItem, Task>",
ValueList = " — ",
DefaultValue = " — "
},
new()
{
Name = "GetItemDisplayText",
Description = Localizer["GetItemDisplayText"],
Expand Down
1 change: 1 addition & 0 deletions src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -6488,6 +6488,7 @@
"AttrHeaderText": "the title of Header",
"AttrItemTemplate": "the template of Item",
"AttrOnClickItem": "the callback on click item",
"AttrOnDoubleClickItem": "the callback on double click item",
"GetItemDisplayText": "the callback on get item display text"
},
"BootstrapBlazor.Server.Components.Samples.Marquees": {
Expand Down
1 change: 1 addition & 0 deletions src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -6488,6 +6488,7 @@
"AttrHeaderText": "标题栏文字",
"AttrItemTemplate": "选项模板",
"AttrOnClickItem": "点击候选项回调方法",
"AttrOnDoubleClickItem": "双击候选项回调方法",
"GetItemDisplayText": "获得显示项显示内容回调方法"
},
"BootstrapBlazor.Server.Components.Samples.Marquees": {
Expand Down
3 changes: 2 additions & 1 deletion src/BootstrapBlazor/Components/ListGroup/ListGroup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<div class="list-group-body scroll">
@foreach (var item in Items)
{
<div @key="item" class="@GetItemClassString(item)" @onclick="() => OnClick(item)">
<div @key="item" class="@GetItemClassString(item)"
@onclick="() => OnClick(item)" @ondblclick="() => OnDoubleClick(item)">
@if (ItemTemplate != null)
{
@ItemTemplate(item)
Expand Down
15 changes: 15 additions & 0 deletions src/BootstrapBlazor/Components/ListGroup/ListGroup.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public partial class ListGroup<TItem>
[Parameter]
public Func<TItem, Task>? OnClickItem { get; set; }

/// <summary>
/// 获得/设置 双击 List 项目回调方法
/// </summary>
[Parameter]
public Func<TItem, Task>? OnDoubleClickItem { get; set; }

/// <summary>
/// 获得/设置 获得条目显示文本内容回调方法
/// </summary>
Expand Down Expand Up @@ -78,4 +84,13 @@ private async Task OnClick(TItem item)
}
CurrentValue = item;
}

private async Task OnDoubleClick(TItem item)
{
if (OnDoubleClickItem != null)
{
await OnDoubleClickItem(item);
}
CurrentValue = item;
}
}
28 changes: 25 additions & 3 deletions test/UnitTest/Components/ListGroupTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Items_Ok()
}

[Fact]
public void ClickItem_Ok()
public async Task ClickItem_Ok()
{
var clicked = false;
var cut = Context.RenderComponent<ListGroup<Foo>>(pb =>
Expand All @@ -44,8 +44,30 @@ public void ClickItem_Ok()
});
});
var item = cut.Find(".list-group-item");
item.Click();
cut.WaitForState(() => clicked);
await cut.InvokeAsync(() => item.Click());
Assert.True(clicked);
}

[Fact]
public async Task DoubleClickItem_Ok()
{
var clicked = false;
var cut = Context.RenderComponent<ListGroup<Foo>>(pb =>
{
pb.Add(a => a.Items,
[
new() { Name = "Test 1" },
new() { Name = "Test 1" }
]);
pb.Add(a => a.OnDoubleClickItem, foo =>
{
clicked = true;
return Task.CompletedTask;
});
});
var item = cut.Find(".list-group-item");
await cut.InvokeAsync(() => item.DoubleClick());
Assert.True(clicked);
}

[Fact]
Expand Down
Loading