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(ListItem): do not render the element when there is not subtitle #2115

Merged
merged 1 commit into from
Aug 26, 2024
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
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
Loading