mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-03 12:39:40 +08:00
feat(Tooltip): add Offset parameter (#3809)
* feat: 增加 Offset 参数 * test: 更新单元测试 * doc: 更新文档
This commit is contained in:
parent
04b5da9211
commit
168973fb1b
@ -29,8 +29,22 @@ public partial class Tooltips
|
||||
Name = "Placement",
|
||||
Description = "Location",
|
||||
Type = "Placement",
|
||||
ValueList = "Auto / Top / Left / Bottom / Right",
|
||||
ValueList = "Auto/Top/Left/Bottom/Right",
|
||||
DefaultValue = "Auto"
|
||||
},
|
||||
new() {
|
||||
Name = "FallbackPlacements",
|
||||
Description = "Define fallback placements by providing a list of placements in array (in order of preference)",
|
||||
Type = "string",
|
||||
ValueList = " — ",
|
||||
DefaultValue = " — "
|
||||
},
|
||||
new() {
|
||||
Name = "Offset",
|
||||
Description = "offset of the tooltip relative to its target",
|
||||
Type = "string",
|
||||
ValueList = " — ",
|
||||
DefaultValue = " — "
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
data-bs-toggle="@ToggleString" data-bs-original-title="@Title"
|
||||
data-bs-selector="@Selector" data-bs-placement="@PlacementString" data-bs-custom-class="@CustomClassString"
|
||||
data-bs-trigger="@Trigger" data-bs-delay="@Delay"
|
||||
data-bs-fallbackPlacements="@FallbackPlacementsString"
|
||||
data-bs-offset="@Offset" data-bs-fallbackPlacements="@FallbackPlacementsString"
|
||||
data-bs-html="@HtmlString" data-bs-sanitize="@SanitizeString">
|
||||
<CascadingValue Value="this" IsFixed="true">
|
||||
@ChildContent
|
||||
|
@ -79,11 +79,17 @@ public partial class Tooltip : ITooltip
|
||||
public Placement Placement { get; set; } = Placement.Top;
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 位置 默认为 Placement.Top
|
||||
/// 获得/设置 位置 默认为 null
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string[]? FallbackPlacements { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 偏移量 默认为 null
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string? Offset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 自定义样式 默认 null
|
||||
/// </summary>
|
||||
@ -131,7 +137,7 @@ public partial class Tooltip : ITooltip
|
||||
/// <summary>
|
||||
/// 设置参数方法
|
||||
/// </summary>
|
||||
public void SetParameters(string title, Placement placement = Placement.Auto, string? trigger = null, string? customClass = null, bool? isHtml = null, bool? sanitize = null, string? delay = null, string? selector = null)
|
||||
public void SetParameters(string title, Placement placement = Placement.Auto, string? trigger = null, string? customClass = null, bool? isHtml = null, bool? sanitize = null, string? delay = null, string? selector = null, string? offset = null)
|
||||
{
|
||||
Title = title;
|
||||
if (placement != Placement.Auto) Placement = placement;
|
||||
@ -141,6 +147,8 @@ public partial class Tooltip : ITooltip
|
||||
if (sanitize.HasValue) Sanitize = sanitize.Value;
|
||||
if (!string.IsNullOrEmpty(delay)) Delay = delay;
|
||||
if (!string.IsNullOrEmpty(selector)) Selector = selector;
|
||||
if (!string.IsNullOrEmpty(selector)) Selector = selector;
|
||||
if (!string.IsNullOrEmpty(offset)) Offset = offset;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class TooltipTest : BootstrapBlazorTestBase
|
||||
pb.Add(a => a.Title, "test_tooltip");
|
||||
});
|
||||
var tooltip = cut.Instance;
|
||||
await cut.InvokeAsync(() => tooltip.SetParameters("title", Placement.Top, "trigger", "custom-class", true, false, "10", ".selector"));
|
||||
await cut.InvokeAsync(() => tooltip.SetParameters("title", Placement.Top, "trigger", "custom-class", true, false, "10", ".selector", "10,20"));
|
||||
Assert.Equal("title", tooltip.Title);
|
||||
Assert.Contains("data-bs-placement=\"top\"", cut.Markup);
|
||||
Assert.Contains("data-bs-trigger=\"trigger\"", cut.Markup);
|
||||
@ -45,6 +45,7 @@ public class TooltipTest : BootstrapBlazorTestBase
|
||||
Assert.Contains("data-bs-sanitize=\"false\"", cut.Markup);
|
||||
Assert.Contains("data-bs-delay=\"10\"", cut.Markup);
|
||||
Assert.Contains("data-bs-selector=\".selector\"", cut.Markup);
|
||||
Assert.Contains("data-bs-offset=\"10,20\"", cut.Markup);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
Loading…
Reference in New Issue
Block a user