diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Tabs/Tabs_Demo_10_Events_Example.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Tabs/Tabs_Demo_10_Events_Example.razor index 0feb28735..877d97d26 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Tabs/Tabs_Demo_10_Events_Example.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Tabs/Tabs_Demo_10_Events_Example.razor @@ -1,30 +1,34 @@  - +

This is the placeholder content for the Home tab.

- +

This is the placeholder content for the Profile tab.

- +

This is the placeholder content for the Contact tab.

-

Current Active Tab: @activeTabTitle

-

Previous Active Tab: @previousActiveTabTitle

+

Current Active Tab Name: @activeTabName

+

Current Active Tab Title: @activeTabTitle

+

Previous Active Tab Name: @previousActiveTabName

+

Previous Active Tab Title: @previousActiveTabTitle

@code { + private string? activeTabName; private string? activeTabTitle; + private string? previousActiveTabName; private string? previousActiveTabTitle; private void OnTabShowingAsync(TabsEventArgs args) @@ -35,7 +39,9 @@ OnShowing="@(args => OnTabShowingAsync(args))" private void OnTabShownAsync(TabsEventArgs args) { + activeTabName = args.ActiveTabName; activeTabTitle = args.ActiveTabTitle; + previousActiveTabName = args.PreviousActiveTabName; previousActiveTabTitle = args.PreviousActiveTabTitle; } diff --git a/blazorbootstrap/Components/Tabs/Tabs.razor.cs b/blazorbootstrap/Components/Tabs/Tabs.razor.cs index f64d9137d..f19354983 100644 --- a/blazorbootstrap/Components/Tabs/Tabs.razor.cs +++ b/blazorbootstrap/Components/Tabs/Tabs.razor.cs @@ -69,43 +69,49 @@ protected override async Task OnInitializedAsync() [JSInvokable] public async Task bsHiddenTab(string activeTabId, string previousActiveTabId) { - var activeTabTitle = tabs?.FirstOrDefault(x => x.Id == activeTabId)?.Title; - var previousActiveTabTitle = tabs?.FirstOrDefault(x => x.Id == previousActiveTabId)?.Title; + var activeTab = tabs?.FirstOrDefault(x => x.Id == activeTabId); + var previousActiveTab = tabs?.FirstOrDefault(x => x.Id == previousActiveTabId); - var args = new TabsEventArgs(activeTabTitle!, previousActiveTabTitle!); + var args = new TabsEventArgs(activeTab?.Name!, activeTab?.Title!, previousActiveTab?.Name!, previousActiveTab?.Title!); await OnHidden.InvokeAsync(args); } [JSInvokable] public async Task bsHideTab(string activeTabId, string previousActiveTabId) { - var activeTabTitle = tabs?.FirstOrDefault(x => x.Id == activeTabId)?.Title; - var previousActiveTabTitle = tabs?.FirstOrDefault(x => x.Id == previousActiveTabId)?.Title; + var activeTab = tabs?.FirstOrDefault(x => x.Id == activeTabId); + var previousActiveTab = tabs?.FirstOrDefault(x => x.Id == previousActiveTabId); - var args = new TabsEventArgs(activeTabTitle!, previousActiveTabTitle!); + var args = new TabsEventArgs(activeTab?.Name!, activeTab?.Title!, previousActiveTab?.Name!, previousActiveTab?.Title!); await OnHiding.InvokeAsync(args); } [JSInvokable] public async Task bsShownTab(string activeTabId, string previousActiveTabId) { - var activeTabTitle = tabs?.FirstOrDefault(x => x.Id == activeTabId)?.Title; - var previousActiveTabTitle = tabs?.FirstOrDefault(x => x.Id == previousActiveTabId)?.Title; + var activeTab = tabs?.FirstOrDefault(x => x.Id == activeTabId); + var previousActiveTab = tabs?.FirstOrDefault(x => x.Id == previousActiveTabId); - var args = new TabsEventArgs(activeTabTitle!, previousActiveTabTitle!); + var args = new TabsEventArgs(activeTab?.Name!, activeTab?.Title!, previousActiveTab?.Name!, previousActiveTab?.Title!); await OnShown.InvokeAsync(args); } [JSInvokable] public async Task bsShowTab(string activeTabId, string previousActiveTabId) { - var activeTabTitle = tabs?.FirstOrDefault(x => x.Id == activeTabId)?.Title; - var previousActiveTabTitle = tabs?.FirstOrDefault(x => x.Id == previousActiveTabId)?.Title; + var activeTab = tabs?.FirstOrDefault(x => x.Id == activeTabId); + var previousActiveTab = tabs?.FirstOrDefault(x => x.Id == previousActiveTabId); - var args = new TabsEventArgs(activeTabTitle!, previousActiveTabTitle!); + var args = new TabsEventArgs(activeTab?.Name!, activeTab?.Title!, previousActiveTab?.Name!, previousActiveTab?.Title!); await OnShowing.InvokeAsync(args); } + /// + /// Gets the active tab. + /// + /// Returns the cuurent active . + public Tab GetActiveTab() => activeTab; + /// /// Initializes the most recently added tab, optionally displaying it. /// diff --git a/blazorbootstrap/EventArguments/Tabs/TabsEventArgs.cs b/blazorbootstrap/EventArguments/Tabs/TabsEventArgs.cs index 6d9d5ccdc..95d03af9c 100644 --- a/blazorbootstrap/EventArguments/Tabs/TabsEventArgs.cs +++ b/blazorbootstrap/EventArguments/Tabs/TabsEventArgs.cs @@ -4,9 +4,11 @@ public class TabsEventArgs : EventArgs { #region Constructors - public TabsEventArgs(string activeTabTitle, string previousActiveTabTitle) + public TabsEventArgs(string activeTabName, string activeTabTitle, string previousActiveTabName, string previousActiveTabTitle) { + ActiveTabName = activeTabName; ActiveTabTitle = activeTabTitle; + PreviousActiveTabName = previousActiveTabName; PreviousActiveTabTitle = previousActiveTabTitle; } @@ -15,12 +17,22 @@ public TabsEventArgs(string activeTabTitle, string previousActiveTabTitle) #region Properties, Indexers /// - /// Gets the active tab title. + /// Gets the active name. + /// + public string ActiveTabName { get; } + + /// + /// Gets the active title. /// public string ActiveTabTitle { get; } /// - /// Gets the previous active tab title. + /// Gets the previous active name. + /// + public string PreviousActiveTabName { get; } + + /// + /// Gets the previous active title. /// public string PreviousActiveTabTitle { get; } diff --git a/docs/docs/05-components/tabs.mdx b/docs/docs/05-components/tabs.mdx index 75d625d59..cba9371af 100644 --- a/docs/docs/05-components/tabs.mdx +++ b/docs/docs/05-components/tabs.mdx @@ -27,6 +27,7 @@ Documentation and examples for using Blazor Bootstrap Tabs components. | Name | Description | Added Version | |:--|:--|:--| +| GetActiveTab() | Gets the active tab. | 3.0.0 | | InitializeRecentTab(bool showTab) | Initializes the most recently added tab, optionally displaying it. | 1.11.0 | | RemoveTabByIndex(int tabIndex) | Removes the tab by index. | 2.2.0 | | RemoveTabByName(string tabName) | Removes the tab by name. | 2.2.0 |