Skip to content

Commit

Permalink
🐛 fix(ListItem): do not render the element when there is not subtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem committed Aug 24, 2024
1 parent 8c6ef3b commit 51bb38e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 25 additions & 15 deletions src/Masa.Blazor/Components/List/MListItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

<CascadingValue Value="IsDark" Name="IsDark">
<MElement Class="@GetClass()"
Style="@GetStyle()"
Tag="@Tag"
ReferenceCaptureAction="r => Ref = r"
id="@Id"
@onclick="HandleOnClick"
__internal_stopPropagation_onclick="@OnClickStopPropagation"
__internal_preventDefault_onclick="@OnClickPreventDefault"
@attributes="@Attributes">
Style="@GetStyle()"
Tag="@Tag"
ReferenceCaptureAction="r => Ref = r"
id="@Id"
@onclick="HandleOnClick"
__internal_stopPropagation_onclick="@OnClickStopPropagation"
__internal_preventDefault_onclick="@OnClickPreventDefault"
@attributes="@Attributes">
@if (ItemContent != null)
{
@ItemContent?.Invoke(GenItemContext())
Expand Down Expand Up @@ -52,15 +52,25 @@

RenderFragment GenContent() => __builder =>
{
if (HasBuiltInContent)
var hasTitle = !string.IsNullOrWhiteSpace(Title);
var hasSubtitle = !string.IsNullOrWhiteSpace(Subtitle);

if (hasTitle || hasSubtitle)
{
<MListItemContent>
<MListItemTitle>
@Title
</MListItemTitle>
<MListItemSubtitle>
@Subtitle
</MListItemSubtitle>
@if (hasTitle)
{
<MListItemTitle>
@Title
</MListItemTitle>
}

@if (hasSubtitle)
{
<MListItemSubtitle>
@Subtitle
</MListItemSubtitle>
}
</MListItemContent>
}
};
Expand Down
2 changes: 0 additions & 2 deletions src/Masa.Blazor/Components/List/MListItem.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ public bool IsDark

protected override bool IsRoutable => Href != null && List?.Routable is true;

private bool HasBuiltInContent => !string.IsNullOrWhiteSpace(Title) || !string.IsNullOrWhiteSpace(Subtitle);

protected override bool AfterHandleEventShouldRender() => false;

protected virtual async Task HandleOnClick(MouseEventArgs args)
Expand Down

0 comments on commit 51bb38e

Please sign in to comment.