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 @@ -19,7 +19,11 @@ public sealed partial class Consoles
/// <summary>
/// OnClear
/// </summary>
private void OnClear() => Messages.Clear();
private Task OnClear()
{
Messages.Clear();
return Task.CompletedTask;
}

/// <summary>
/// GetColor
Expand Down
3 changes: 2 additions & 1 deletion src/BootstrapBlazor/Components/Console/Console.razor
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
}
@if (OnClear != null)
{
<Button Text="@ClearButtonText" Icon="@ClearButtonIcon" Color="@ClearButtonColor" OnClick="ClearConsole" class="console-clear" />
<Button Text="@ClearButtonText" Icon="@ClearButtonIcon" Color="@ClearButtonColor"
OnClick="OnClearConsole" class="console-clear"></Button>
Copy link

Copilot AI Jun 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] For consistency with the rest of the component markup, consider using a self-closing <Button ... /> tag instead of an explicit closing </Button>.

Suggested change
OnClick="OnClearConsole" class="console-clear"></Button>
OnClick="OnClearConsole" class="console-clear" />

Copilot uses AI. Check for mistakes.
}
</div>
}
Expand Down
11 changes: 7 additions & 4 deletions src/BootstrapBlazor/Components/Console/Console.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public partial class Console
/// 获得/设置 清空委托方法
/// </summary>
[Parameter]
public Action? OnClear { get; set; }
public Func<Task>? OnClear { get; set; }

/// <summary>
/// 获得/设置 组件高度 默认为 126px;
Expand Down Expand Up @@ -150,7 +150,7 @@ public partial class Console
/// <summary>
/// 获得 是否显示 Footer
/// </summary>
protected bool ShowFooter => OnClear != null || ShowAutoScroll || FooterTemplate != null;
private bool ShowFooter => OnClear != null || ShowAutoScroll || FooterTemplate != null;

[Inject]
[NotNull]
Expand Down Expand Up @@ -194,8 +194,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
/// <summary>
/// 清空控制台消息方法
/// </summary>
public void ClearConsole()
public async Task OnClearConsole()
{
OnClear?.Invoke();
if (OnClear != null)
{
await OnClear();
}
}
}
13 changes: 7 additions & 6 deletions test/UnitTest/Components/ConsoleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Items_OK()
}

[Fact]
public void OnClear_OK()
public async Task OnClear_OK()
{
var clearClicked = false;
var cut = Context.RenderComponent<Console>(builder =>
Expand All @@ -66,13 +66,14 @@ public void OnClear_OK()
Assert.False(clearClicked);

// 实例触发 OnClear 方法
cut.Instance.ClearConsole();
await cut.Instance.OnClearConsole();

cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.OnClear, new Action(() =>
pb.Add(a => a.OnClear, new Func<Task>(() =>
{
clearClicked = true;
return Task.CompletedTask;
}));
});
cut.Find(".btn-secondary").Click();
Expand All @@ -88,7 +89,7 @@ public void ClearButtonText_OK()
{
new() { Message = "Test1" }, new() { Message = "Test2" }
});
builder.Add(a => a.OnClear, new Action(() => { }));
builder.Add(a => a.OnClear, () => Task.CompletedTask);
builder.Add(a => a.ClearButtonText, "Console Clear");
});

Expand All @@ -104,7 +105,7 @@ public void OnClearButtonText_OK()
{
new() { Message = "Test1" }, new() { Message = "Test2" }
});
builder.Add(a => a.OnClear, new Action(() => { }));
builder.Add(a => a.OnClear, () => Task.CompletedTask);
builder.Add(a => a.ClearButtonIcon, "fa-solid fa-xmark");
});

Expand All @@ -121,7 +122,7 @@ public void ClearButtonColor_OK()
{
new() { Message = "Test1" }, new() { Message = "Test2" }
});
builder.Add(a => a.OnClear, new Action(() => { }));
builder.Add(a => a.OnClear, () => Task.CompletedTask);
builder.Add(a => a.ClearButtonColor, Color.Primary);
});

Expand Down