!2583 feat(#I4ZSLV): add tooltip api on ButtonBase

* test: 增加单元测试
* feat: 增加显示/销毁 Tooltip 方法
This commit is contained in:
Argo 2022-03-27 16:07:57 +00:00
parent 5072fa7760
commit cfd1d1fb09
2 changed files with 39 additions and 0 deletions

View File

@ -211,4 +211,29 @@ public abstract class ButtonBase : TooltipComponentBase
IsDisabled = disable;
StateHasChanged();
}
/// <summary>
/// 显示 Tooltip 方法
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public virtual async Task ShowTooltip(string message)
{
if (!string.IsNullOrEmpty(Id))
{
await JSRuntime.InvokeVoidAsync(null, "bb_tooltip", Id, "show", message, "auto", false, "focus");
}
}
/// <summary>
/// 销毁 Tooltip 方法
/// </summary>
/// <returns></returns>
public virtual async Task RemoveTooltip()
{
if (!string.IsNullOrEmpty(Id))
{
await JSRuntime.InvokeVoidAsync(null, "bb_tooltip", Id, "dispose");
}
}
}

View File

@ -321,4 +321,18 @@ public class ButtonTest : BootstrapBlazorTestBase
await tcs.Task;
Assert.True(valid);
}
[Fact]
public async Task ShowTooltip_Ok()
{
var cut = Context.RenderComponent<Button>();
await cut.InvokeAsync(() => cut.Instance.ShowTooltip("Test"));
}
[Fact]
public async Task RemoveTooltip_Ok()
{
var cut = Context.RenderComponent<Button>();
await cut.InvokeAsync(() => cut.Instance.RemoveTooltip());
}
}