Skip to content

Commit

Permalink
#16 Add lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Nix1983 committed Oct 31, 2023
1 parent 2f14caf commit bb8f94c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Components/Tabs/Tab.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
[Parameter] public string? Title { get; set; }
[Parameter] public RenderFragment? Header { get; set; }
[Parameter] public EventCallback<MouseEventArgs> OnClick { get; set; }
public bool IsContentLoaded { get; set; } = false;

private bool _isDisabled;

Expand All @@ -48,8 +49,13 @@
protected override void OnInitialized()
{
ContainerTabSet?.AddTab(this);
if (ContainerTabSet?.ActiveTab == this)
{
IsContentLoaded = true;
}
}


public void Dispose()
{
ContainerTabSet?.RemoveTab(this);
Expand All @@ -61,7 +67,9 @@
{
return;
}
IsContentLoaded = true;
ContainerTabSet?.SetActivateTab(this);
OnClick.InvokeAsync();
}

}
13 changes: 9 additions & 4 deletions Components/Tabs/Tabs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
<div class="card-body">
<div class="tab-content">
<div class="tab-pane active show" role="tabpanel" id="@ActiveTab?.Title-id">
<div> @ActiveTab?.ChildContent</div>
@if (ActiveTab?.IsContentLoaded == true)
{
@ActiveTab?.ChildContent
}
</div>
</div>
</div>
Expand All @@ -33,9 +36,11 @@
if (ActiveTab == null)
{
await SetActivateTab(tab);
tab.IsContentLoaded = true;
}
}


public async Task RemoveTab(Tab tab)
{
TabsList.Remove(tab);
Expand All @@ -61,7 +66,7 @@
}
}

public void ActivateAlternativeTab(Tab deactivatedTab)
public async Task ActivateAlternativeTab(Tab deactivatedTab)
{

if (TabsList.Count <= 1) return;
Expand All @@ -72,15 +77,15 @@

if (index > 0 && !TabsList[index - 1].IsDisabled)
{
SetActivateTab(TabsList[index - 1]);
await SetActivateTab(TabsList[index - 1]);
return;
}

for (int i = index + 1; i < TabsList.Count; i++)
{
if (!TabsList[i].IsDisabled)
{
SetActivateTab(TabsList[i]);
await SetActivateTab(TabsList[i]);
return;
}
}
Expand Down

0 comments on commit bb8f94c

Please sign in to comment.