Skip to content

Commit 2b5c187

Browse files
committed
Merge branch 'fix-link' into refactor-dynamic
2 parents da15e6d + c0fe15f commit 2b5c187

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

src/BootstrapBlazor/Components/Button/LinkButton.razor.cs renamed to src/BootstrapBlazor/Components/Button/LinkButton.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6+
using Microsoft.AspNetCore.Components.Rendering;
7+
using Microsoft.AspNetCore.Components.Web;
8+
using System;
9+
610
namespace BootstrapBlazor.Components;
711

812
/// <summary>
913
/// LinkButton 组件
1014
/// </summary>
11-
public partial class LinkButton
15+
public sealed class LinkButton : ButtonBase
1216
{
1317
/// <summary>
1418
/// 获得/设置 Url 默认为 #
@@ -59,6 +63,48 @@ public partial class LinkButton
5963

6064
private bool TriggerClick => !IsDisabled || (string.IsNullOrEmpty(Url));
6165

66+
/// <summary>
67+
/// <inheritdoc />
68+
/// </summary>
69+
/// <param name="builder"></param>
70+
protected override void BuildRenderTree(RenderTreeBuilder builder)
71+
{
72+
builder.OpenElement(0, TagName);
73+
builder.AddAttribute(1, "class", ClassString);
74+
builder.AddAttribute(2, "href", UrlString);
75+
builder.AddAttribute(3, "target", Target);
76+
builder.AddAttribute(4, "disabled", Disabled);
77+
builder.AddAttribute(5, "aria-disabled", DisabledString);
78+
builder.AddAttribute(6, "tabindex", Tab);
79+
builder.AddAttribute(7, "id", Id);
80+
builder.AddAttribute(8, "role", "button");
81+
82+
if (TriggerClick)
83+
{
84+
builder.AddAttribute(9, "onclick", EventCallback.Factory.Create<MouseEventArgs>(this, OnClickButton));
85+
builder.AddEventPreventDefaultAttribute(10, "onclick", Prevent);
86+
builder.AddEventStopPropagationAttribute(11, "onclick", StopPropagation);
87+
}
88+
89+
if (!string.IsNullOrEmpty(Icon))
90+
{
91+
builder.AddContent(12, new MarkupString($"<i class=\"{Icon}\"></i>"));
92+
}
93+
94+
if (!string.IsNullOrEmpty(ImageUrl))
95+
{
96+
builder.AddContent(13, new MarkupString($"<img alt=\"img\" class=\"{ImageCss}\" src=\"{ImageUrl}\" />"));
97+
}
98+
99+
if (!string.IsNullOrEmpty(Text))
100+
{
101+
builder.AddContent(14, new MarkupString($"<span>{Text}</span>"));
102+
}
103+
104+
builder.AddContent(15, ChildContent);
105+
builder.CloseElement();
106+
}
107+
62108
private async Task OnClickButton()
63109
{
64110
if (OnClickWithoutRender != null)

src/BootstrapBlazor/Components/Button/LinkButton.razor

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)