The Web Components Tabs is a lightweight and user-friendly component that organizes corresponding content in a tab format or a collection of tabs typically placed horizontally. The Web Components Tab enables end-users to easily click through and display different views. There are several features and customization options like tab orientation, templating, built-in header styles, animation, scroll buttons, and more.
The Ignite UI for Web Components Tabs organizes and switches between similar data sets. The tabs are placed at the top of the data content. When a tab is selected the panel with the corresponding id is displayed. The component could be used with only tabs defined (without any panels).
Web Components Tabs Example
The Web Components Tabs example below displays three different tabs aligned in a single line so you can navigate across each in a fast and easy way.
<!DOCTYPE html><html><head><title>Tabs Overview</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v6.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-tabs><igc-tabpanel="home"><igc-iconname="home"></igc-icon></igc-tab><igc-tabpanel="search"><igc-iconname="search"></igc-icon></igc-tab><igc-tabpanel="favorite"><igc-iconname="favorite"></igc-icon></igc-tab><igc-tab-panelid="home">Home tab panel</igc-tab-panel><igc-tab-panelid="search">Search tab panel</igc-tab-panel><igc-tab-panelid="favorite">Favorite tab panel</igc-tab-panel></igc-tabs></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Like this sample? Get access to our complete Ignite UI for Web Components toolkit and start building your own apps in minutes. Download it for free.
How to use Tabs with Ignite UI for Web Components
First, you need to install the Ignite UI for Web Components by running the following command:
The IgcTabsComponent emits Change event when the user selects an item either by key press or click. The select method allows you to select a tab by specifying its panel as string value.
If the selected tab is not specified on initial load, the first tab that is not disabled will be selected.
The default behavior, which selects a tab when the user is navigating with the arrow keys, could be modified by the activation property. Setting it to Manual will focus the next/previous tab on arrow key press, but the tab will be selected only after pressing Space or Enter
Disabled Tab
A tab is disabled by setting the disabled attribute:
<igc-tabpanel="first"disabled>Tab 1</igc-tab>html
Alignment
The alignment property controls how Web Components tabs are positioned. It accepts the following values:
Start (default): the width of the tab depends on the content (label, icon, both) and all tabs have equal padding. First tab is aligned to the tabs container's left side.
Center: the width of the tab depends on the content and occupies the tabs container's center.
End: the width of the tab depends on the content and all tabs have equal padding. Last tab is aligned to the tabs container's right side.
Justify: all tabs are equal in width and fully fit the tabs container.
If the space is not enough to fit all tabs, scroll buttons are displayed.
<!DOCTYPE html><html><head><title>Tabs Alignment</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v6.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-radio-groupid="radio-group"alignment="horizontal"><igc-radioname="alignment"value="start"label-position="after"checked>Start</igc-radio><igc-radioname="alignment"value="center"label-position="after">Center</igc-radio><igc-radioname="alignment"value="end"label-position="after">End</igc-radio><igc-radioname="alignment"value="justify"label-position="after">Justify</igc-radio></igc-radio-group><igc-tabsid="tabs"><igc-tabpanel="basics">Basics</igc-tab><igc-tabpanel="details">Details</igc-tab><igc-tabpanel="custom">Custom</igc-tab><igc-tabpanel="disabled"disabled>Disabled</igc-tab><igc-tab-panelid="basics">Basics tab panel</igc-tab-panel><igc-tab-panelid="details">Details tab panel</igc-tab-panel><igc-tab-panelid="custom">Custom tab panel</igc-tab-panel><igc-tab-panelid="disabled">Disabled tab panel won't be displayed</igc-tab-panel></igc-tabs></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Scrolling
Scroll buttons are shown when the available space is not enough to render all Web Components tabs. The start scroll button is disabled if the first tab is in view. Respectively, when last tab is in view the end scroll button is disabled. By pressing one of the scroll buttons the tabs are scrolled so the tab in that direction is fully visible, or if it is already visible the previous/next tab in that direction is displayed.
<!DOCTYPE html><html><head><title>Tabs Scrolling</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v6.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-tabsid="tabs"></igc-tabs></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Keyboard Navigation
Keys
Description
←
Selects previous (next in Right-to-Left mode) tab. If activation is set to Manual only focuses the tab. Scrolls to end if on first tab.
→
Selects next (previous in Right-to-Left mode) tab. If activation is set to Manual only focuses the tab. Scrolls to start if on last tab.
Each tab has default slot to display information - icon, text or both and prefix and suffix slots to show additional content in the beginning and/or in the end.
<!DOCTYPE html><html><head><title>Tabs Prefix Suffix</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v6.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-tabs><igc-tabpanel="home"><igc-iconslot="prefix"name="home"></igc-icon><span>Home</span><igc-icon-buttonslot="suffix"name="close"variant="flat"></igc-icon-button></igc-tab><igc-tabpanel="search"><igc-iconslot="prefix"name="search"></igc-icon><span>Search</span><igc-icon-buttonslot="suffix"name="close"variant="flat"></igc-icon-button></igc-tab><igc-tabpanel="favorite"><igc-iconslot="prefix"name="favorite"></igc-icon><span>Favorite</span><igc-icon-buttonslot="suffix"name="close"variant="flat"></igc-icon-button></igc-tab><igc-tab-panelid="home">Home tab panel</igc-tab-panel><igc-tab-panelid="search">Search tab panel</igc-tab-panel><igc-tab-panelid="favorite">Favorite tab panel</igc-tab-panel></igc-tabs></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html