Skip to content

Commit

Permalink
Fix: "Set number" button initializes to default(int) regardless of pa…
Browse files Browse the repository at this point in the history
…rameter type.
  • Loading branch information
jsakamoto committed Aug 8, 2024
1 parent 84281b7 commit 35e5ca7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ResetButton OnClick="() => _V1Unknown = Unknown.Value" />
</Stack>
<p>@(_V1Unknown?.ToString() ?? "(null)")</p>
@ValueDisplay(_V1Unknown)
</Template>
</Story>

Expand All @@ -30,7 +30,7 @@
</NumberParameterController>
<ResetButton OnClick="() => _V2Int32 = 123" />
</Stack>
<p>@(_V2Int32?.ToString() ?? "(null)")</p>
@ValueDisplay(_V2Int32)
</Template>
</Story>

Expand All @@ -44,7 +44,7 @@
</NumberParameterController>
<ResetButton OnClick="() => _V3Null = null" />
</Stack>
<p>@(_V3Null?.ToString() ?? "(null)")</p>
@ValueDisplay(_V3Null)
</Template>
</Story>

Expand All @@ -60,7 +60,7 @@
</NumberParameterController>
<ResetButton OnClick="() => _V1Unknown = Unknown.Value" />
</Stack>
<p>@(_V1Unknown?.ToString() ?? "(null)")</p>
@ValueDisplay(_V1Unknown)
</Template>
</Story>

Expand All @@ -75,7 +75,7 @@
</NumberParameterController>
<ResetButton OnClick="() => _V2Int32 = 123" />
</Stack>
<p>@(_V2Int32?.ToString() ?? "(null)")</p>
@ValueDisplay(_V2Int32)
</Template>
</Story>

Expand All @@ -90,7 +90,7 @@
</NumberParameterController>
<ResetButton OnClick="() => _V3Null = null" />
</Stack>
<p>@(_V3Null?.ToString() ?? "(null)")</p>
@ValueDisplay(_V3Null)
</Template>
</Story>

Expand All @@ -107,7 +107,7 @@

<ResetButton OnClick="() => _V1Unknown = Unknown.Value" />
</Stack>
<p>@(_V1Unknown?.ToString() ?? "(null)")</p>
@ValueDisplay(_V1Unknown)
</Template>
</Story>

Expand All @@ -121,7 +121,7 @@
</NumberParameterController>
<ResetButton OnClick="() => _V2Decimal = 123.45m" />
</Stack>
<p>@(_V2Decimal?.ToString() ?? "(null)")</p>
@ValueDisplay(_V2Decimal)
</Template>
</Story>

Expand All @@ -135,7 +135,7 @@
</NumberParameterController>
<ResetButton OnClick="() => _V3Null = null" />
</Stack>
<p>@(_V3Null?.ToString() ?? "(null)")</p>
@ValueDisplay(_V3Null)
</Template>
</Story>

Expand All @@ -151,7 +151,7 @@
</NumberParameterController>
<ResetButton OnClick="() => _V1Unknown = Unknown.Value" />
</Stack>
<p>@(_V1Unknown?.ToString() ?? "(null)")</p>
@ValueDisplay(_V1Unknown)
</Template>
</Story>

Expand All @@ -166,7 +166,7 @@
</NumberParameterController>
<ResetButton OnClick="() => _V2Decimal = 123.45m" />
</Stack>
<p>@(_V2Decimal?.ToString() ?? "(null)")</p>
@ValueDisplay(_V2Decimal)
</Template>
</Story>

Expand All @@ -181,14 +181,16 @@
</NumberParameterController>
<ResetButton OnClick="() => _V3Null = null" />
</Stack>
<p>@(_V3Null?.ToString() ?? "(null)") (@_V3Null?.GetType().Name)</p>
@ValueDisplay(_V3Null)
</Template>
</Story>

</Stories>

@code
{
private RenderFragment<object?> ValueDisplay = (value) => @<p>@value?.ToString() (@(value?.GetType().Name ?? "null"))</p>;

private readonly ComponentParameter Int32 = SampleComponent.CreateParameter(nameof(SampleComponent.Int32));

private readonly ComponentParameter NullableInt32 = SampleComponent.CreateParameter(nameof(SampleComponent.NullableInt32));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}
@if (this.Value is Unknown || (!nullable && this.Value is null))
{
<SquareButton Text="Set number" OnClick="@(() => OnInputAsync(0))" />
<SquareButton Text="Set number" OnClick="OnClickSetNumber" />
}
else if (nullable)
{
Expand Down Expand Up @@ -52,4 +52,9 @@ else
await this.OnInputAsync(n);
}
}

private async Task OnClickSetNumber()
{
await this.OnInputAsync(Activator.CreateInstance(this.Parameter.TypeStructure.PrimaryType));
}
}

0 comments on commit 35e5ca7

Please sign in to comment.