Skip to content

Commit ede9754

Browse files
Merge tabstrip-events-3357 into production (#3360)
* docs(TabStri): Revamp Events examples * Update components/tabstrip/events.md * Update components/tabstrip/events.md --------- Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com>
1 parent 5934642 commit ede9754

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

components/tabstrip/events.md

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: Events
33
page_title: TabStrip - Events
4-
description: Events of the Tab Strip for Blazor.
4+
description: Learn about the events and event arguments of the Telerik TabStrip for Blazor.
55
slug: tabstrip-events
6-
tags: telerik,blazor,tab strip,events
6+
tags: telerik, blazor, tabstrip, events
77
published: True
88
position: 20
99
---
@@ -19,12 +19,13 @@ This article explains the events available in the Telerik TabStrip for Blazor:
1919

2020
The `ActiveTabIdChanged` event was added in [version 9.0.0](https://www.telerik.com/support/whats-new/blazor-ui/release-history/telerik-ui-for-blazor-9-0-0-(2025-q2)). It fires when the user changes the active tab. The event handler receives the new tab ID of type `string` as an argument. If the `Id` parameter of the `TabStripTab` is not set, the component will generate one automatically.
2121

22-
The `ActiveTabIdChanged` event is designed to work with the new [`ActiveTabId` parameter](slug:tabstrip-tabs-collection).
22+
The `ActiveTabIdChanged` event is designed to work with the new [`ActiveTabId` parameter](slug:tabstrip-tabs-collection). Update the `ActiveTabId` parameter value manually in the `ActiveTabIdChanged` handler.
2323

24-
>caption Handle the tab ID selection changed event
24+
>caption Handle the TabStrip ActiveTabIdChanged event
2525
2626
````RAZOR
27-
<TelerikTabStrip ActiveTabIdChanged="@HandleTabIdChange">
27+
<TelerikTabStrip ActiveTabId="@TabStripActiveTabId"
28+
ActiveTabIdChanged="@TabStripActiveTabIdChanged">
2829
<TabStripTab Title="First" Id="tab1">
2930
First tab content. Click through the tabs.
3031
</TabStripTab>
@@ -36,58 +37,61 @@ The `ActiveTabIdChanged` event is designed to work with the new [`ActiveTabId` p
3637
</TabStripTab>
3738
</TelerikTabStrip>
3839
39-
@Result
40+
<p>The current active tab is <code>@TabStripActiveTabId</code></p>
4041
4142
@code {
42-
private string Result { get; set; } = string.Empty;
43+
private string TabStripActiveTabId { get; set; } = "tab1";
4344
44-
private void HandleTabIdChange(string tabId)
45+
private void TabStripActiveTabIdChanged(string newTabId)
4546
{
46-
Result = $"The current tab ID is {tabId}";
47+
TabStripActiveTabId = newTabId;
4748
}
4849
}
4950
````
5051

5152
## ActiveTabIndexChanged
5253

53-
The `ActiveTabIndexChanged` event fires when the user changes the tab that is currently shown. The event handler receives the new index as an argument.
54+
The `ActiveTabIndexChanged` event fires when the user selects another tab. The event handler receives the new zero-based index as an argument. Update the `ActiveTabIndex` parameter value manually in the `ActiveTabIndexChanged` handler.
5455

55-
If you remove programmatically the currently active tab, when it disposes, the event will fire with index `-1` as there will be no selected tab anymore.
56+
If you programmatically remove the currently active tab, the `ActiveTabIndexChanged` event fires with index `-1` as there is no selected tab anymore.
5657

57-
> The `ActiveTabIndexChanged` event and `ActiveTabIndex` parameter will be deprecated in a future releases. It is recommended to use the [`ActiveTabId`](slug:tabstrip-tabs-collection) parameter with [`ActiveTabIdChanged`](slug:tabstrip-events#activetabidchanged) event instead.
58+
> The `ActiveTabIndexChanged` event and `ActiveTabIndex` parameter will be deprecated in a future product version. Use the [`ActiveTabId`](slug:tabstrip-tabs-collection) parameter with [`ActiveTabIdChanged`](slug:tabstrip-events#activetabidchanged) event instead.
5859
59-
>caption Handle the tab selection changed event
60+
>caption Handle the TabStrip ActiveTabIndexChanged event
6061
6162
````RAZOR
62-
@result
63-
64-
<TelerikTabStrip ActiveTabIndexChanged="@TabChangedHandler">
65-
<TabStripTab Title="First">
66-
First tab content. Click through the tabs.
67-
</TabStripTab>
68-
<TabStripTab Title="Second">
69-
Second tab content.
70-
</TabStripTab>
71-
<TabStripTab Title="Third">
72-
Third tab content.
73-
</TabStripTab>
63+
<TelerikTabStrip ActiveTabIndex="@TabStripActiveTabIndex"
64+
ActiveTabIndexChanged="@TabStripActiveTabIndexChanged">
65+
<TabStripTab Title="First">
66+
First tab content. Click through the tabs.
67+
</TabStripTab>
68+
<TabStripTab Title="Second">
69+
Second tab content.
70+
</TabStripTab>
71+
<TabStripTab Title="Third">
72+
Third tab content.
73+
</TabStripTab>
7474
</TelerikTabStrip>
7575
76+
<p>The current tab index is <code>@TabStripActiveTabIndex</code></p>
77+
7678
@code {
77-
string result {get;set;}
78-
void TabChangedHandler(int newIndex)
79+
private int TabStripActiveTabIndex { get; set; }
80+
81+
private void TabStripActiveTabIndexChanged(int newTabIndex)
7982
{
80-
result = $"current tab {newIndex} selected on {DateTime.Now}";
83+
TabStripActiveTabIndex = newTabIndex;
8184
}
8285
}
8386
````
8487

85-
>caption Cancel the event
88+
If you do not update the `ActiveTabIndex` parameter value in the `ActiveTabIndexChanged` handler, the selected tab will not change, so the event will be cancelled.
8689

87-
````RAZOR
88-
@* If the tab strip is bound to a field in the view model, when you do not update that field in the event handler, you will effectively cancel the event *@
90+
>caption Cancel the ActiveTabIndexChanged event
8991
90-
<TelerikTabStrip ActiveTabIndex="@ActiveTabIndex" ActiveTabIndexChanged="@TabChangedHandler">
92+
````RAZOR
93+
<TelerikTabStrip ActiveTabIndex="@TabStripActiveTabIndex"
94+
ActiveTabIndexChanged="@TabStripActiveTabIndexChanged">
9195
<TabStripTab Title="First">
9296
First tab content. Click through the tabs.
9397
</TabStripTab>
@@ -99,22 +103,22 @@ If you remove programmatically the currently active tab, when it disposes, the e
99103
</TabStripTab>
100104
</TelerikTabStrip>
101105
106+
<p>The current tab index is <code>@TabStripActiveTabIndex</code></p>
107+
102108
@code {
103-
int ActiveTabIndex { get; set; }
104-
105-
void TabChangedHandler(int newIndex)
109+
private int TabStripActiveTabIndex { get; set; }
110+
111+
private void TabStripActiveTabIndexChanged(int newTabIndex)
106112
{
107-
// this will update the view-model for all items but the third,
108-
// effectively cancelling the event for the third tab
109-
if (newIndex != 2)
113+
if (newTabIndex != 2)
110114
{
111-
ActiveTabIndex = newIndex;
115+
TabStripActiveTabIndex = newTabIndex;
112116
}
113117
}
114118
}
115119
````
116120

117121
## See Also
118122

119-
* [TabStrip Overview](slug:components/tabstrip/overview)
120-
* [Dynamic Tabs](slug:tabstrip-tabs-collection)
123+
* [TabStrip Overview](slug:components/tabstrip/overview)
124+
* [Dynamic Tabs](slug:tabstrip-tabs-collection)

0 commit comments

Comments
 (0)