Skip to content
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
4 changes: 2 additions & 2 deletions maui/src/Expander/SfExpander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ void OnExpanderLoaded(object? sender, EventArgs e)
/// </summary>
void UpdateContentViewLayoutAndVisibility()
{
if ((!IsViewLoaded && !IsExpanded && FlowDirection != FlowDirection.RightToLeft && !Content!.IsVisible) || (Content == null && FlowDirection != FlowDirection.RightToLeft) || ContentView == null)
if (!IsViewLoaded || Content == null || ContentView == null)
Copy link
Preview

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simplified condition removes important checks for IsExpanded, FlowDirection, and Content.IsVisible. While this may fix the immediate issue, it could potentially affect other scenarios. Consider adding a comment explaining why these conditions were removed to help future maintainers understand the reasoning.

Suggested change
if (!IsViewLoaded || Content == null || ContentView == null)
// The following checks are necessary to ensure that the content view layout and visibility
// are only updated when the expander is loaded, expanded, in a valid flow direction,
// and the content is visible. Removing these checks may cause unexpected behavior in
// certain scenarios. See CodeQL rule: "The simplified condition removes important checks for
// IsExpanded, FlowDirection, and Content.IsVisible."
if (!IsViewLoaded || Content == null || ContentView == null || !IsExpanded || FlowDirection == FlowDirection.MatchParent || !Content.IsVisible)

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the issue is only on Windows, is it wise to remove all of it for all the platforms?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it...

{
return;
}
Expand Down Expand Up @@ -1225,7 +1225,7 @@ static Easing GetEasing(ExpanderAnimationEasing easing)
/// <param name="newvalue"></param>
void OnContentChanged(View? oldvalue, View? newvalue)
{
if ((!IsViewLoaded && !IsExpanded && FlowDirection != FlowDirection.RightToLeft && !Content!.IsVisible) || ContentView == null)
if (!IsViewLoaded || ContentView == null)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,112 @@ public void OnPropertyChanged_ShouldUpdateProperty_WhenIsEnabledChanges()
Assert.False(expander.IsEnabled);
}

[Fact]
public void Constructor_AllowsNullContent_AndRetainsHeader()
{
var header = new Label { Text = "Header" };
var content = new Label { Text = "Content" };
var expander = new SfExpander()
{
Header = header,
Content = content,
IsExpanded = true,
IsViewLoaded = true,
};

var oldValue = expander.Content;
expander.Content = null;
var newValue = expander.Content;
Assert.Null(expander.Content);
Assert.NotNull(expander.Header);
}

[Fact]
public void SettingHeaderToNull_DoesNotAffectContent()
{
var content = new Label { Text = "Content" };
var expander = new SfExpander()
{
Header = null!,
Content = content,
IsExpanded = true,
IsViewLoaded = true
};

Assert.Null(expander.Header);
Assert.NotNull(expander.Content);
}

[Fact]
public void SettingHeaderAndContentToNull_DoesNotThrow()
{
var expander = new SfExpander()
{
Header = null!,
Content = null,
IsExpanded = true,
IsViewLoaded = true
};

Assert.Null(expander.Header);
Assert.Null(expander.Content);
}

[Fact]
public void SettingContentToNull_RetainsHeader_WithRTL()
{
var header = new Label { Text = "Header" };
var content = new Label { Text = "Content" };
var expander = new SfExpander()
{
Header = header,
Content = content,
IsExpanded = true,
IsViewLoaded = true,
FlowDirection = FlowDirection.RightToLeft
};

expander.Content = null;
Assert.Null(expander.Content);
Assert.NotNull(expander.Header);
Assert.Equal(FlowDirection.RightToLeft, expander.FlowDirection);
}

[Fact]
public void SettingHeaderAndContentToNull_WithRTL()
{
var expander = new SfExpander()
{
Header = null!,
Content = null,
IsExpanded = true,
IsViewLoaded = true,
FlowDirection = FlowDirection.RightToLeft
};

Assert.Null(expander.Header);
Assert.Null(expander.Content);
Assert.Equal(FlowDirection.RightToLeft, expander.FlowDirection);
}

[Fact]
public void SettingHeaderToNull_RetainsContent_WithRTL()
{
var content = new Label { Text = "Content" };
var expander = new SfExpander()
{
Header = null!,
Content = content,
IsExpanded = true,
IsViewLoaded = true,
FlowDirection = FlowDirection.RightToLeft
};

Assert.Null(expander.Header);
Assert.NotNull(expander.Content);
Assert.Equal(FlowDirection.RightToLeft, expander.FlowDirection);
}

#endregion

}
Expand Down