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

[Checkbox] Fix looping value error when used in a Stack #2417

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -8371,7 +8371,7 @@
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.HorizontalAlignment">
<summary>
Gets or sets the horizontal alignment of the components in the stack.
Gets or sets the horizontal alignment of the components in the stack.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.VerticalAlignment">
Expand All @@ -8381,7 +8381,7 @@
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.Orientation">
<summary>
Gets or sets the orientation of the stacked components.
Gets or sets the orientation of the stacked components.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentStack.Width">
Expand Down
23 changes: 23 additions & 0 deletions examples/Demo/Shared/Pages/Lab/CheckboxBug.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@using Microsoft.FluentUI.AspNetCore.Components
<FluentStack Orientation="Orientation.Vertical">
<FluentCheckbox Value="@Value.IsChecked"
ValueChanged="(isChecked) => ChangeDummyAsync(Value with {IsChecked = isChecked})">Checkbox</FluentCheckbox>

</FluentStack>



@code {

[Parameter, EditorRequired]
public required Dummy Value { get; set; }

[Parameter]
public EventCallback<Dummy> ValueChanged { get; set; }

private Task ChangeDummyAsync(Dummy dummy)
{
return ValueChanged.InvokeAsync(dummy);
}

}
7 changes: 7 additions & 0 deletions examples/Demo/Shared/Pages/Lab/Dummy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// ------------------------------------------------------------------------
// MIT License - Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------------------


namespace FluentUI.Demo.Shared.Pages.Lab;
public record Dummy(bool IsChecked);
14 changes: 14 additions & 0 deletions examples/Demo/Shared/Pages/Lab/IssueTester.razor
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
@page "/issue-tester"

<FluentTabs>
<FluentTab Label="Tab1">
<CheckboxBug @bind-Value=@dummy />
</FluentTab>
</FluentTabs>


@code {

private Dummy dummy = new Dummy(false);


}
25 changes: 23 additions & 2 deletions src/Core/Components/Stack/FluentStack.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

public partial class FluentStack : FluentComponentBase
{
private RenderFragment? _cachedContent;
private bool _shouldRender = true;

protected string? ClassValue => new CssBuilder(Class)
.AddClass("stack-horizontal", () => Orientation == Orientation.Horizontal)
.AddClass("stack-vertical", () => Orientation == Orientation.Vertical)
Expand All @@ -25,7 +28,7 @@
.Build();

/// <summary>
/// Gets or sets the horizontal alignment of the components in the stack.
/// Gets or sets the horizontal alignment of the components in the stack.
/// </summary>
[Parameter]
public HorizontalAlignment HorizontalAlignment { get; set; } = HorizontalAlignment.Left;
Expand All @@ -37,7 +40,7 @@
public VerticalAlignment VerticalAlignment { get; set; } = VerticalAlignment.Top;

/// <summary>
/// Gets or sets the orientation of the stacked components.
/// Gets or sets the orientation of the stacked components.
/// </summary>
[Parameter]
public Orientation Orientation { get; set; } = Orientation.Horizontal;
Expand Down Expand Up @@ -74,6 +77,24 @@
[Parameter]
public RenderFragment? ChildContent { get; set; }

protected override void OnParametersSet()
{
if (ChildContent != _cachedContent)
{
_cachedContent = ChildContent;
}
vnbaaij marked this conversation as resolved.
Show resolved Hide resolved
else
{
_shouldRender = false;
}
}

Check warning on line 91 in src/Core/Components/Stack/FluentStack.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Demo site

Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000)

Check failure on line 91 in src/Core/Components/Stack/FluentStack.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Code Lib

Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000)

Check failure on line 91 in src/Core/Components/Stack/FluentStack.razor.cs

View workflow job for this annotation

GitHub Actions / Build and Test Code Lib

Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000)

protected override bool ShouldRender()
{
return _shouldRender;
}

private string GetHorizontalAlignment()
{
return HorizontalAlignment switch
Expand Down
Loading