Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CountUp): not show the Value when set value to 0 #2236

Merged
merged 2 commits into from
Oct 7, 2023
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
13 changes: 11 additions & 2 deletions src/BootstrapBlazor.Shared/Samples/CountUps.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

<DemoBlock Title="@Localizer["CountUpsNormalTitle"]" Introduction="@Localizer["CountUpsNormalIntro"]" Name="Normal">
<section ignore>
<div class="row mb-2">
<div class="col-12">
更改配置后,改变 Value 值后生效
</div>
</div>
<div class="row mb-2">
<div class="col-12 col-sm-6 col-md-4 col-lg-3">
<BootstrapInputGroup>
Expand Down Expand Up @@ -89,9 +94,13 @@
</div>
</section>
<div class="mb-2">
<CountUp TValue="double" Value="@Value2" Option="_option" OnCompleted="OnCompleted" class="fw-bold fs-1"></CountUp>
<CountUp TValue="double" Value="@Value" Option="_option" OnCompleted="OnCompleted" class="fw-bold fs-1"></CountUp>
</div>
<Button Icon="fa-solid fa-gear" Text="Update" OnClick="OnUpdate"></Button>
<BootstrapInputGroup>
<BootstrapInputGroupLabel DisplayText="Value"></BootstrapInputGroupLabel>
<BootstrapInput @bind-Value="Value2"></BootstrapInput>
<Button Icon="fa-solid fa-gear" Text="Update" OnClick="OnUpdate"></Button>
</BootstrapInputGroup>
<ConsoleLogger @ref="_logger" class="mt-2" />
</DemoBlock>

Expand Down
6 changes: 3 additions & 3 deletions src/BootstrapBlazor.Shared/Samples/CountUps.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace BootstrapBlazor.Shared.Samples;
/// </summary>
public partial class CountUps
{
private static Random Rnd { get; } = new();

private static readonly CountUpOption _option = new() { DecimalPlaces = 2 };

private double Value2 { get; set; }

private double Value { get; set; }

private ConsoleLogger? _logger;

private bool _useOnCompleted;
Expand All @@ -31,7 +31,7 @@ protected override void OnInitialized()

private void OnUpdate()
{
Value2 = Rnd.Next(12345, 999999) / 100.0;
Value = Value2;
}

private Task OnCompleted()
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/CountUp/CountUp.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@namespace BootstrapBlazor.Components
@inherits BootstrapModuleComponentBase
@attribute [BootstrapModuleAutoLoader(JSObjectReference = true, AutoInvokeInit = false, AutoInvokeDispose = false)]
@attribute [BootstrapModuleAutoLoader(JSObjectReference = true, AutoInvokeDispose = false)]
@typeparam TValue

<span @attributes="AdditionalAttributes" class="@ClassString" id="@Id"></span>
15 changes: 9 additions & 6 deletions src/BootstrapBlazor/Components/CountUp/CountUp.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);

if (Module != null)
if (!firstRender && !PreviousValue.Equals(Value))
{
if (!PreviousValue.Equals(Value))
{
PreviousValue = Value;
PreviousValue = Value;

await Module.InvokeVoidAsync("init", Id, Interop, Value, OnCompleted != null ? nameof(OnCompleteCallback) : null, Option);
}
await InvokeInitAsync();
}
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, Value, OnCompleted != null ? nameof(OnCompleteCallback) : null, Option);

/// <summary>
/// OnCompleted 回调方法
/// </summary>
Expand Down