Skip to content

Commit 8383131

Browse files
committed
kb(tabstrip): Add KB for loading all tabs by default
1 parent c80c3c4 commit 8383131

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

components/tabstrip/persist-content.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ To keep Tab content in the DOM after the Tab is deactivated, set the `PersistCon
4646

4747
## See Also
4848

49-
* [Live Demo: TabStrip - Persist Tab Content](https://demos.telerik.com/blazor-ui/tabstrip/persist-content)
49+
* [Live Demo: TabStrip - Persist Tab Content](https://demos.telerik.com/blazor-ui/tabstrip/persist-content)
50+
* [Render All TabStrip Tabs Initially]({%slug tabstrip-kb-load-all-tabs%})
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: Render All TabStrip Tabs Initially
3+
description: Learn how to initialize, load and render all tabs on page load in the Telerik TabStrip for Blazor.
4+
type: how-to
5+
page_title: How to Render All TabStrip Tabs By Default
6+
slug: tabstrip-kb-load-all-tabs
7+
tags: telerik, blazor, tabstrip
8+
ticketid: 1673750, 1654667
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>TabStrip for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
## Description
24+
25+
This KB answers the following questions:
26+
27+
* How to preload the contents of all TabStrip tabs and keep it rendered in the DOM at all times?
28+
* How to load and render all the content of a Telerik TabStrip for Blazor?
29+
* How to access components in TabStrip tabs that haven't been opened by the user?
30+
31+
## Solution
32+
33+
Even when [`PersistTabContent="true"`]({%slug tabstrip-persist-content%}), the TabStrip initializes and renders each tab container for the first time only after the user clicks on the respective tab to activate it. This improves the app performance.
34+
35+
In scenarios where all TabStrip tabs must render initially and be in the DOM at all times, use the following approach:
36+
37+
1. Move the tab content outside the TabStrip. Use one HTML `<div>` to hold the contents of each tab.
38+
1. Hide the TabStrip tab container elements (`<div class="k-tabstrip-content">`) with a `display:none` CSS style.
39+
1. Toggle the `display` styles of the HTML `<div>`s in the [TabStrip `ActiveTabIndexChanged` event]({%slug tabstrip-events%}#activetabindexchanged).
40+
41+
>caption Render all TabStrip tabs initially
42+
43+
````RAZOR
44+
<TelerikTabStrip @bind-ActiveTabIndex="@ActiveTabIndex"
45+
Class="empty-tabstrip">
46+
<TabStripTab Title="First Tab">&nbsp;</TabStripTab>
47+
<TabStripTab Title="Second Tab">&nbsp;</TabStripTab>
48+
<TabStripTab Title="Third Tab">&nbsp;</TabStripTab>
49+
</TelerikTabStrip>
50+
51+
<div class="tabstrip-containers k-tabstrip">
52+
<div class="@( $"k-tabstrip-content {GetTabActive(0)}" )">
53+
First Tab Content
54+
</div>
55+
<div class="@( $"k-tabstrip-content {GetTabActive(1)}" )">
56+
Second Tab Content
57+
</div>
58+
<div class="@( $"k-tabstrip-content {GetTabActive(2)}" )">
59+
Third Tab Content
60+
</div>
61+
</div>
62+
63+
<style>
64+
/* hide built-in tab containers */
65+
.empty-tabstrip .k-tabstrip-content {
66+
display: none !important;
67+
}
68+
/* adjust tab borders */
69+
.tabstrip-containers .k-tabstrip-content {
70+
border-top-width: 0;
71+
}
72+
</style>
73+
74+
@code {
75+
public int ActiveTabIndex { get; set; }
76+
77+
private string GetTabActive(int index)
78+
{
79+
return ActiveTabIndex == index ? "k-active" : string.Empty;
80+
}
81+
}
82+
````
83+
84+
## See Also
85+
86+
* [Persist TabStrip Tab Content]({%slug tabstrip-persist-content%})
87+
* [TabStrip Events]({%slug tabstrip-events%})

0 commit comments

Comments
 (0)