Skip to content

Commit 4e4b776

Browse files
#510 - Fix Button href not updating (#548)
* #510 - Fix Button href not updating
1 parent 73fd55e commit 4e4b776

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

blazorbootstrap/Components/Button/Button.razor.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public partial class Button : BlazorBootstrapComponentBase
3030

3131
private Target previousTarget;
3232

33+
private string? previousTo = default!;
34+
3335
private string previousTooltipTitle = default!;
3436

3537
private ButtonType previousType;
@@ -93,6 +95,7 @@ protected override void OnInitialized()
9395
previousType = Type;
9496
previousTarget = Target;
9597
previousTabIndex = TabIndex;
98+
previousTo = To;
9699
previousTooltipTitle = TooltipTitle;
97100
tooltipColor = TooltipColor;
98101

@@ -137,6 +140,12 @@ protected override async Task OnParametersSetAsync()
137140
setButtonAttributesAgain = true;
138141
}
139142

143+
if (previousTo != To)
144+
{
145+
previousTo = To;
146+
setButtonAttributesAgain = true;
147+
}
148+
140149
if (previousTooltipTitle != TooltipTitle || tooltipColor != TooltipColor) setButtonAttributesAgain = true;
141150

142151
if (setButtonAttributesAgain)
@@ -201,12 +210,17 @@ private void SetAttributes()
201210
if (!Attributes.TryGetValue("role", out _))
202211
Attributes.Add("role", "button");
203212

213+
// To can be changed when the Button is used within a Virtualize component
204214
if (!Attributes.TryGetValue("href", out _))
205215
Attributes.Add("href", To!);
216+
else
217+
Attributes["href"] = To!;
206218

207219
if (Target != Target.None)
208220
if (!Attributes.TryGetValue("target", out _))
209221
Attributes.Add("target", Target.ToTargetString()!);
222+
else
223+
Attributes["target"] = Target.ToTargetString()!;
210224

211225
if (Disabled)
212226
{

0 commit comments

Comments
 (0)