From 51bb38e1729cc0176fbdd7956f050e24be10b3ae Mon Sep 17 00:00:00 2001 From: capdiem Date: Sat, 24 Aug 2024 17:00:24 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(ListItem):=20do=20not=20rend?= =?UTF-8?q?er=20the=20element=20when=20there=20is=20not=20subtitle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/List/MListItem.razor | 40 ++++++++++++------- .../Components/List/MListItem.razor.cs | 2 - 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/Masa.Blazor/Components/List/MListItem.razor b/src/Masa.Blazor/Components/List/MListItem.razor index 3761389bfa..478bc75b69 100644 --- a/src/Masa.Blazor/Components/List/MListItem.razor +++ b/src/Masa.Blazor/Components/List/MListItem.razor @@ -4,14 +4,14 @@ + 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()) @@ -52,15 +52,25 @@ RenderFragment GenContent() => __builder => { - if (HasBuiltInContent) + var hasTitle = !string.IsNullOrWhiteSpace(Title); + var hasSubtitle = !string.IsNullOrWhiteSpace(Subtitle); + + if (hasTitle || hasSubtitle) { - - @Title - - - @Subtitle - + @if (hasTitle) + { + + @Title + + } + + @if (hasSubtitle) + { + + @Subtitle + + } } }; diff --git a/src/Masa.Blazor/Components/List/MListItem.razor.cs b/src/Masa.Blazor/Components/List/MListItem.razor.cs index 0a35988914..d84534fe6b 100644 --- a/src/Masa.Blazor/Components/List/MListItem.razor.cs +++ b/src/Masa.Blazor/Components/List/MListItem.razor.cs @@ -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)