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
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.8.0-beta01</Version>
<Version>9.8.0-beta02</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 6 additions & 2 deletions src/BootstrapBlazor/Components/Tab/Tab.razor
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ else
var item = TabItems.Find(i => i.IsActive);
if (item != null)
{
@RenderTabItem(item)
<div id="@item.Id" class="@GetTabItemClassString(item)">
@RenderTabItem(item)
</div>
}
}
else
{
foreach (var item in TabItems)
{
@RenderTabItem(item)
<div @key="@item" id="@item.Id" class="@GetTabItemClassString(item)">
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Adding @key to the div may affect Blazor's diffing behavior.

If item is a complex object, property changes may not trigger updates as expected. Using a unique, stable value like item.Id as the key is recommended.

@RenderTabItem(item)
</div>
}
}
</CascadingValue>
Expand Down
6 changes: 5 additions & 1 deletion src/BootstrapBlazor/Components/Tab/Tab.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ public partial class Tab

private bool IsPreventDefault => _contextMenuZone != null;

private static string? GetTabItemClassString(TabItem item) => CssBuilder.Default("tabs-body-content")
.AddClass("d-none", item is { IsActive: false })
.Build();

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand Down Expand Up @@ -1054,7 +1058,7 @@ public async Task DragItemCallback(int originIndex, int currentIndex)
private async Task OnRefreshAsync()
{
// refresh the active tab item
var item = TabItems.FirstOrDefault(i => i.IsActive);
var item = TabItems.Find(i => i.IsActive);

if (item is not null)
{
Expand Down
11 changes: 3 additions & 8 deletions src/BootstrapBlazor/Components/Tab/TabItemContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ private void RenderContent()
_renderHandle.Render(BuildRenderTree);
}

private object _key = new();
private Guid _key = Guid.NewGuid();

private void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, "div");
builder.SetKey(_key);
builder.AddAttribute(5, "class", ClassString);
builder.AddAttribute(6, "id", Item.Id);
builder.AddAttribute(5, "class", "tabs-body-content-wrap");
builder.AddContent(10, RenderItemContent(Item.ChildContent));
builder.CloseElement();
}
Expand All @@ -79,16 +78,12 @@ private RenderFragment RenderItemContent(RenderFragment? content) => builder =>
builder.CloseComponent();
};

private string? ClassString => CssBuilder.Default("tabs-body-content")
.AddClass("d-none", !Item.IsActive)
.Build();

/// <summary>
/// Render method
/// </summary>
public void Render()
{
_key = new object();
_key = Guid.NewGuid();
RenderContent();
}

Expand Down
Loading