Tabs
Documentation and examples for how to use Tabs component.
How it works #
The Tabs component organizes content into multiple panels, each accessible by clicking its corresponding tab. This allows users to switch between different sections without leaving the page.
How to use:
This demo shows a basic tabbed interface with four tabs. Only one tab's content is visible at a time, and users can switch between them by clicking the tab headers.
How to use:
- Add the
Tabscomponent to your page. - Define one or more
Tabchild components insideTabs, each with aTitleand content. - Optionally, set
IsActive="true"on the tab you want to be selected by default.
<Tabs>
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
Alignment #
The Tabs component supports alignment options to control the position of the tab headers. Use the
How to use:
The following demo centers the tab headers using
Alignment parameter to center or right-align the tabs.
How to use:
- Set the
Alignmentparameter on theTabscomponent toTabsAlignment.CenterorTabsAlignment.Right. - Add your
Tabcomponents as usual.
Alignment="TabsAlignment.Center".
<Tabs Alignment="TabsAlignment.Center">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
This demo shows the tab headers aligned to the right using
Alignment="TabsAlignment.Right". Adjust alignment to match your layout needs.
<Tabs Alignment="TabsAlignment.Right">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
Sizes #
The Tabs component can be displayed in different sizes to fit your design. Use the
How to use:
This demo uses
Size parameter to set the tab size to small, medium, or large.
How to use:
- Set the
Sizeparameter on theTabscomponent toTabsSize.Small,TabsSize.Medium, orTabsSize.Large. - Add your
Tabcomponents as needed.
Size="TabsSize.Small" to render compact tabs.
<Tabs Size="TabsSize.Small">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
This demo uses
Size="TabsSize.Medium" for medium-sized tabs, suitable for most layouts.
<Tabs Size="TabsSize.Medium">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
This demo uses
Size="TabsSize.Large" for prominent, easy-to-click tabs.
<Tabs Size="TabsSize.Large">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
Styles #
The Tabs component supports different visual styles. Use the
How to use:
This demo uses
Type parameter to switch between default, boxed, and rounded tab styles.
How to use:
- Set the
Typeparameter on theTabscomponent toTabsType.BoxedorTabsType.Rounded. - Add your
Tabcomponents as usual.
Type="TabsType.Boxed" for boxed tab headers.
<Tabs Type="TabsType.Boxed">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
This demo uses
Type="TabsType.Rounded" for rounded tab headers, giving a softer appearance.
<Tabs Type="TabsType.Rounded">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
Full width #
To make the Tabs component span the entire width of its container, set the
How to use:
This demo shows tabs stretched to fill the available horizontal space.
IsFullWidth parameter to true.
How to use:
- Add the
Tabscomponent and setIsFullWidth="true". - Add your
Tabcomponents as needed.
<Tabs IsFullWidth="true">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
Combined #
You can combine alignment, style, size, and full-width options to create custom tab layouts. Set multiple parameters on the
How to use:
This demo combines centered alignment and boxed style.
Tabs component to achieve the desired appearance.
How to use:
- Set any combination of
Alignment,Type,Size, andIsFullWidthon theTabscomponent. - Add your
Tabcomponents as usual.
<Tabs Alignment="TabsAlignment.Center" Type="TabsType.Boxed">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
This demo combines boxed style with full-width tabs.
<Tabs Type="TabsType.Boxed" IsFullWidth="true">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
This demo combines rounded style with full-width tabs.
<Tabs Type="TabsType.Rounded" IsFullWidth="true">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
This demo combines centered alignment, boxed style, and medium size for a distinct look.
<Tabs Alignment="TabsAlignment.Center" Type="TabsType.Boxed" Size="TabsSize.Medium">
<Tab Title="Pictures" IsActive="true">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
Methods #
| Name | Return type | Description |
|---|---|---|
| GetActiveTab() | Tab |
Gets the active tab. |
| RemoveTabByIndex(int tabIndex) | - | Removes the tab by index. |
| RemoveTabByName(string tabName) | - | Removes the tab by name. |
| ShowFirstTab() | - | Selects the first tab and show its associated pane. |
| ShowLastTab() | - | Selects the last tab and show its associated pane. |
| ShowTabByIndex(int tabIndex) | Tab |
Selects the tab by index and show its associated pane. |
| ShowTabByName(string tabName) | Tab |
Selects the tab by name and show its associated pane. |
The Tabs component exposes methods for programmatically controlling tab selection and management. You can use a
How to use:
This demo provides buttons to switch between tabs and demonstrates how to control tabs from code.
@ref to access these methods from your code.
How to use:
- Add
@ref="tabsRef"to yourTabscomponent. - Call methods like
ShowFirstTab(),ShowTabByIndex(index), orShowTabByName(name)from your code to change the active tab. - Use
RemoveTabByIndexorRemoveTabByNameto remove tabs dynamically.
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.
This is the placeholder content for the Products tab.
This is the placeholder content for the FAQs tab.
This is the placeholder content for the About tab.
<Tabs @ref="tabsRef">
<Tab Title="Home">
<div class="pt-3">This is the placeholder content for the <b>Home</b> tab.</div>
</Tab>
<Tab Title="Profile">
<div class="pt-3">This is the placeholder content for the <b>Profile</b> tab.</div>
</Tab>
<Tab Title="Contact">
<div class="pt-3">This is the placeholder content for the <b>Contact</b> tab.</div>
</Tab>
<Tab Title="Products" Name="Products">
<div class="pt-3">This is the placeholder content for the <b>Products</b> tab.</div>
</Tab>
<Tab Title="FAQs" Name="FAQs">
<div class="pt-3">This is the placeholder content for the <b>FAQs</b> tab.</div>
</Tab>
<Tab Title="About">
<div class="pt-3">This is the placeholder content for the <b>About</b> tab.</div>
</Tab>
</Tabs>
<Buttons Class="mt-5">
<Button Color="ButtonColor.Primary" Size="ButtonSize.Small" @onclick="() => tabsRef.ShowFirstTab()">First Tab</Button>
<Button Color="ButtonColor.Link" Size="ButtonSize.Small" @onclick="() => tabsRef.ShowTabByIndex(1)">Second Tab</Button>
<Button Color="ButtonColor.Info" Size="ButtonSize.Small" @onclick="() => tabsRef.ShowTabByIndex(2)">Third Tab</Button>
<Button Color="ButtonColor.Success" Size="ButtonSize.Small" @onclick="ShowProductsTab">Products Tab</Button>
<Button Color="ButtonColor.Warning" Size="ButtonSize.Small" @onclick="ShowFAQsTab">FAQs Tab</Button>
<Button Color="ButtonColor.Danger" Size="ButtonSize.Small" @onclick="() => tabsRef.ShowLastTab()">Last Tab</Button>
</Buttons>
@code{
Tabs tabsRef = default!;
private void ShowProductsTab() => tabsRef.ShowTabByName("Products");
private void ShowFAQsTab() => tabsRef.ShowTabByName("FAQs");
}
Events #
When displaying a new tab, the events fire in the following sequence:
| Name | Event args | Description |
|---|---|---|
| OnHidden | TabEventArgs |
This event fires after a new tab is shown (and thus the previous active tab is hidden). |
| OnShown | TabEventArgs |
This event fires on tab show after a tab has been shown. |
| OnTabChanged | TabsEventArgs |
This event fires when the user clicks the corresponding tab and the tab is displayed. |
The Tabs component provides events to respond to tab changes. You can handle
How to use:
This demo logs tab events and displays them in a list, showing how to react to tab changes in your application.
OnHidden, OnShown, and OnTabChanged to perform actions when tabs are switched.
How to use:
- Add
OnHidden,OnShown, orOnTabChangedevent handlers to yourTabscomponent. - Implement the corresponding methods in your code to handle tab events and update your UI or state as needed.
- Use the event arguments to access information about the active or previous tab.
<Tabs @ref="tabsRef"
OnHidden="OnHidden"
OnShown="OnShown"
OnTabChanged="OnTabChanged">
<Tab Title="Pictures">
<div class="pt-3">This is the placeholder content for the <b>Pictures</b> tab.</div>
</Tab>
<Tab Title="Music">
<div class="pt-3">This is the placeholder content for the <b>Music</b> tab.</div>
</Tab>
<Tab Title="Videos">
<div class="pt-3">This is the placeholder content for the <b>Videos</b> tab.</div>
</Tab>
<Tab Title="Documents">
<div class="pt-3">This is the placeholder content for the <b>Documents</b> tab.</div>
</Tab>
</Tabs>
<div class="mt-5" style="max-height:200px;overflow-y:auto;">
@foreach (var item in messages)
{
<p>Event: @item.Event, Message: @item.Message, UTC Time: @item.TimeStamp</p>
}
</div>
@code {
Tabs tabsRef = default!;
List<TabMessage> messages = new List<TabMessage>();
private void OnHidden(TabEventArgs args) => messages.Add(new("OnHidden", $"Tab Title: {args.Tab.Title!}", DateTime.UtcNow));
private void OnShown(TabEventArgs args) => messages.Add(new("OnShown", $"Tab Title: {args.Tab.Title!}", DateTime.UtcNow));
private void OnTabChanged(TabsEventArgs args) => messages.Add(new("OnTabChanged", $"Active Tab Title: {args.ActiveTab.Title!}, Previous Active Tab: {args.PreviousActiveTab.Title!}", DateTime.UtcNow));
private record TabMessage(string Event, string Message, DateTime TimeStamp);
}