Infragistics
Close
Angular React Web Components Blazor React
Open Source

Tabs

The Ignite UI for React Tabs component organizes related content at the same level of hierarchy into tabs and shows the content of the selected tab.

Each tab holds its header and its content in one element. The Tabs component supports keyboard navigation, and it shows scroll buttons when the tab headers don’t fit.

Live Demo

Anatomy

The React Tabs component consists of a container with tab items, optional scroll buttons, and a content area for the selected tab.

Tabs anatomy showing the scroll buttons, inactive and active tabs, a tab with left, top, and right icons, and the content area
1. Tabs Container: groups and aligns all tab items
2. Header Button (optional): navigation arrows appear for tabs that aren’t visible in the tab container
3. Label: text that names the tab and indicates what content it opens
4. Active Tab Item: a single selectable tab element that is active
5. Left Icon (optional): icon shown before the label to add context to the tab
6. Top Icon (optional): icon shown above the label to add context to the tab
7. Right Icon (optional): icon shown after the label to add context to the tab
8. Content Area: the panel where content for the selected tab is displayed

The igc-tabs element renders the header strip and the scroll buttons. Each igc-tab renders its own header and content, and the Tabs component places the content of all tabs below the header strip:

igc-tabs[role="tablist"]
└─ #shadow-root
   └─ div[part="tabs"]                                 // the scrollable header strip
      └─ div[part="inner"]
         ├─ igc-icon-button[part="start-scroll-button"] // rendered when the headers overflow
         ├─ slot                                       // the igc-tab elements
         │  └─ igc-tab
         │     └─ #shadow-root
         │        ├─ div[part="tab-header"][role="tab"]
         │        │  └─ div[part="base"]
         │        │     ├─ slot[name="prefix"][part="prefix"]
         │        │     ├─ div[part="content"]
         │        │     │  └─ slot[name="label"]        // falls back to the label property
         │        │     └─ slot[name="suffix"][part="suffix"]
         │        └─ div[part="tab-body"][role="tabpanel"] // visible only for the selected tab
         │           └─ slot                           // the content of the tab
         ├─ igc-icon-button[part="end-scroll-button"]   // rendered when the headers overflow
         └─ div[part="selected-indicator"]
            └─ span                                    // follows the selected tab header

Getting Started

To use the React Tabs, follow the Ignite UI for React Getting Started topic for the basic project setup, then add the component for your target platform.

Install the igniteui-react package:

npm install igniteui-react

Then import the IgrTabs and IgrTab wrappers and the theme CSS:

import { IgrTabs, IgrTab } from 'igniteui-react';
import 'igniteui-webcomponents/themes/light/bootstrap.css';

After registration, render the IgrTabs with a IgrTab for each section. The label of a tab becomes its header, and the children of the tab become its content:

<IgrTabs>
  <IgrTab label="Overview">
    <p>The overview content.</p>
  </IgrTab>
  <IgrTab label="Details">
    <p>The details content.</p>
  </IgrTab>
</IgrTabs>

When no tab is selected on the first render, the React Tabs component selects the first enabled tab. When you later set selected to false on the selected tab, no tab is selected.

Usage

Use the React Tabs to organize different views of the same information or switch between similar or related data sets.

Type

The Tabs are available in two types - Short, showing only text by default, with the option to have prefix and suffix icons, and Tall, which also has an additional third icon on top of the text.

For a short tab, set the label of the tab. For a tall tab, place an Icon and a <span> in the label slot instead, and the Tabs component shows the icon above the text. The label slot takes precedence over the label property. Register the icons first, as described in the Icon topic:

<IgrTabs>
  <IgrTab label="Cart" />
  <IgrTab label="Shipping" />
</IgrTabs>

<IgrTabs>
  <IgrTab>
    <IgrIcon slot="label" name="shopping_basket" collection="material" />
    <span slot="label">Cart</span>
  </IgrTab>
  <IgrTab>
    <IgrIcon slot="label" name="delivery" collection="material" />
    <span slot="label">Shipping</span>
  </IgrTab>
</IgrTabs>

To show content before and after the label, such as an icon or a badge, place it in the prefix and suffix slots of the tab:

<IgrTab>
  <IgrIcon slot="prefix" name="inbox" collection="material" />
  <span slot="label">Inbox</span>
  <IgrBadge slot="suffix">12</IgrBadge>
</IgrTab>

Responsiveness

The Tabs can be Content Fit to fill up the available horizontal space by adapting their width, or Fixed with scrolling buttons to navigate a large number of tab items. This allows fitting more content than what is normally possible with the other mode in the same total space.

The alignment property sets how the React Tabs component arranges the tab headers:

  • start (default): each tab header is as wide as its content, and the headers start at the start edge of the Tabs.
  • center: each tab header is as wide as its content, and the headers are centered.
  • end: each tab header is as wide as its content, and the headers end at the end edge of the Tabs.
  • justify: the tab headers stretch to fill the width of the Tabs. Use it for the Content Fit mode.
<IgrTabs alignment="justify">
  <IgrTab label="Podcasts" />
  <IgrTab label="Playlists" />
  <IgrTab label="Genres" />
</IgrTabs>

When the tab headers don’t fit, the React Tabs component shows a scroll button at each end of the header strip, which is the Fixed mode. A scroll button scrolls the strip to the next tab header that is out of view in its direction, and it’s disabled when the strip is scrolled to that end. When the user selects a tab, the Tabs component scrolls its header into view.

Amount

For most scenarios, the Tabs need to contain between two and five items. If your use case requires more than five tabs, you should consider the Fixed mode explained above.

You can add and remove tabs at run time. A tab that you add with selected set becomes the selected tab, and when you remove the selected tab, the React Tabs component selects the first enabled tab.

States

Tab Items support Active, Inactive, Active & Hover, Inactive & Hover and Disabled states. In Tabs there is always one Active tab and an arbitrary number of Inactive and Disabled ones.

Set selected on a tab to make it the active tab, and disabled to turn it off. Users can’t select a disabled tab, and the keyboard navigation skips it. When you disable the selected tab, the React Tabs component selects the first enabled tab.

<IgrTabs>
  <IgrTab label="Overview" />
  <IgrTab label="Activity" selected={true} />
  <IgrTab label="Billing" disabled={true} />
</IgrTabs>

Selection

The React Tabs component calls onChange with the newly selected tab when the user selects a tab with a click or a key. To select a tab in code, call select with the tab, or with its id or label:

import { useRef } from 'react';
import { IgrTab, IgrTabs } from 'igniteui-react';

export default function ProfileTabs() {
  const tabsRef = useRef<IgrTabs>(null);

  return (
    <>
      <IgrTabs ref={tabsRef} onChange={(e: CustomEvent<IgrTab>) => console.log(e.detail.label)}>
        <IgrTab label="Overview" />
        <IgrTab label="Details" />
      </IgrTabs>
      <button onClick={() => tabsRef.current?.select('Details')}>Show details</button>
    </>
  );
}

Selecting a tab in code, or setting selected on a tab, changes the selection without the change event. The Tabs component ignores disabled tabs and values that match no tab.

Activation

By default, the React Tabs component selects a tab as soon as the arrow keys, Home, or End move the focus to its header. Set activation to manual to move only the focus with these keys, and to select the focused tab with Enter or Space. Use the manual activation when showing the content of a tab is slow, for example when it loads data.

<IgrTabs activation="manual">
  <IgrTab label="Overview" />
  <IgrTab label="Reports" />
</IgrTabs>

Do/Don’t

The Tabs are appropriate for organizing information, and one should avoid using them as a way to design workflows and actions that come in a logical sequence, e.g. checkout process or configuration wizard. When using the short Tabs, never combine a text tab with an icon tab in the same bar. Choose one of the two content modes and use it consistently for all the items in the bar.

Tabs named Products, Cart, and Orders above a product image
Do:

Use tabs to organize related information.

Tabs named Extras, Payment, and Address used as the steps of an order workflow
Don't:

Avoid tabs for the steps of a sequential workflow, such as a checkout process.

Tabs named Podcasts, Playlists, and Genres that all use text labels
Do:

Use the same content mode, text or icons, for all tabs in a bar.

Tabs that combine the Podcasts and Playlists text labels with a music note icon tab
Don't:

Avoid combining text tabs and icon tabs in the same bar.

Properties

The React Tabs component exposes the following properties. See the API reference for the complete type definitions.

Name Type Default Description
alignment 'start' | 'end' | 'center' | 'justify' 'start' How the tab headers are arranged in the header strip.
activation 'auto' | 'manual' 'auto' Whether moving the focus to a tab header with the keyboard also selects the tab.
selectedTab IgrTab | null null Read-only. The selected tab.
selected string '' Read-only. The label of the selected tab, or its id when the tab has no label.
tabs IgrTab[] — Read-only. The tabs that are direct children of the Tabs.
Tab.label string '' The text of the tab header. The label slot takes precedence over it.
Tab.selected boolean false Whether the tab is selected.
Tab.disabled boolean false Whether the tab is disabled.

Methods

The React Tabs component exposes the following method. It changes the selection without emitting the change event.

Method Description
select Selects the tab that you pass, or the tab whose id or label matches the string that you pass. Ignores disabled tabs and strings that match no tab.

Events

The React Tabs component emits the following events.

Name Type Description
onChange CustomEvent<IgrTab> Emitted when the user selects a tab with a click or a key. The event detail holds the selected tab.

Styling

The React Tabs component takes its colors from the theme. Change them with the following CSS variables:

Variable What it changes
--ig-tabs-item-background The background of the tab headers.
--ig-tabs-item-text-color The text color of the tab headers.
--ig-tabs-item-icon-color The icon color of the tab headers.
--ig-tabs-item-hover-background The background of a hovered or focused tab header.
--ig-tabs-item-hover-color The text color of a hovered or focused tab header.
--ig-tabs-item-active-background The background of the selected tab header.
--ig-tabs-item-active-color The text color of the selected tab header.
--ig-tabs-item-active-icon-color The icon color of the selected tab header.
--ig-tabs-item-disabled-color The text color of a disabled tab header.
--ig-tabs-item-disabled-icon-color The icon color of a disabled tab header.
--ig-tabs-indicator-color The color of the indicator of the selected tab header.
--ig-tabs-button-background The background of the scroll buttons.
--ig-tabs-button-color The icon color of the scroll buttons.
--ig-tabs-button-hover-background The background of a hovered scroll button.
--ig-tabs-button-disabled-color The icon color of a disabled scroll button.

The igc-tabs element exposes the following CSS parts:

Part What it styles
start-scroll-button The start scroll button.
end-scroll-button The end scroll button.
selected-indicator The indicator of the selected tab header.

The igc-tab element exposes the following CSS parts:

Part What it styles
tab-header The header of the tab.
prefix The container of the prefix slot.
content The container of the label slot.
suffix The container of the suffix slot.
tab-body The content of the tab, which is visible only for the selected tab.

Sass Theming

When you modify a primary property, all related dependent properties are automatically updated to reflect the change. The primary parameters of the tabs-theme function are $item-background, from which the theme derives the colors of all tab states, and $item-active-color, from which it derives the indicator color. Create a theme with the function and include it with the tokens() mixin, which emits the matching --ig-tabs-* variables in the scope where you include it.

The Sass functions come from the igniteui-theming package. See the Theming topic for the Sass setup.

@use "igniteui-theming" as *;

$custom-tabs-theme: tabs-theme(
  $item-background: #292826,
  $item-active-color: #f4d45c
);

:root {
  @include tokens($custom-tabs-theme);
}

CSS Variables

Set the CSS variables on a Tabs component or on a container when you need local styling without a Sass build step:

.profile-tabs {
  --ig-tabs-item-active-color: #e41c77;
  --ig-tabs-indicator-color: #e41c77;
}

Use the CSS parts for other styles:

igc-tab::part(tab-header) {
  font-weight: 600;
}

igc-tabs::part(selected-indicator) {
  opacity: 0.8;
}

Styling with Tailwind

You can style the React Tabs using our custom Tailwind utility classes. Make sure to set up Tailwind first.

Set the --ig-tabs-* CSS variables with Tailwind arbitrary properties:

<IgrTabs className="[--ig-tabs-item-background:#011627] [--ig-tabs-item-active-color:#FF8040] [--ig-tabs-indicator-color:#FF8040]">
  ...
</IgrTabs>

Accessibility

The React Tabs component uses the roles of the WAI-ARIA tabs pattern: users reach the tab headers with the Tab key, move between them with the arrow keys, and select a tab to show its content.

Keyboard Interaction

The header strip of the React Tabs component is a single tab stop: only the selected tab header is in the tab order, or the first enabled tab header when no tab is selected. The content of the selected tab is the next tab stop. The following keys work while a tab header has the focus:

Key Action
Tab / Shift + Tab Moves the focus out of the header strip, to the content of the selected tab or to the previous focusable element. The Tabs component doesn’t handle these keys.
Arrow Right Moves the focus to the next enabled tab header, and from the last one to the first. In a right-to-left layout, moves it to the previous one. With the auto activation, also selects the tab.
Arrow Left Moves the focus to the previous enabled tab header, and from the first one to the last. In a right-to-left layout, moves it to the next one. With the auto activation, also selects the tab.
Home Moves the focus to the first enabled tab header. With the auto activation, also selects the tab.
End Moves the focus to the last enabled tab header. With the auto activation, also selects the tab.
Enter / Space Selects the focused tab.

The React Tabs component handles these keys on keydown:

  • It prevents their default action, so the arrow keys that move the focus, Home, End, and Space don’t scroll the page.
  • A key that you hold doesn’t repeat its action.
  • A key that you press together with Shift, Ctrl, Alt, or Meta does nothing.
  • The Tabs component scrolls the header that receives the focus into view.

With a pointer, a click on a tab header focuses and selects the tab. A disabled tab ignores clicks. The scroll buttons aren’t in the tab order.

Screen Readers / ARIA

The React Tabs component renders the following roles and attributes:

Element Role Attributes
igc-tabs tablist aria-orientation="horizontal", set through element internals
The tab-header part of each tab tab aria-selected, aria-disabled, aria-controls that points to the content of the tab, aria-posinset, and aria-setsize
The tab-body part of each tab tabpanel aria-labelledby that points to the header of the tab

The React Tabs component also behaves as follows for assistive technology:

  • A tab takes its accessible name from its header content: the label property or the label slot, and the content of the prefix and suffix slots.
  • The content of the tabs that aren’t selected is hidden and inert, so assistive technology and the keyboard skip it.
  • The aria-posinset and aria-setsize attributes of each tab header give screen readers the position of the tab in the set, such as “2 of 3”.
  • The Tabs component doesn’t use a live region. A changed selection reaches assistive technology through the aria-selected state and the focus.

Accessibility Compliance

Infragistics documents Ignite UI for React accessibility support for Section 508 and WCAG 2.1 guideline areas in the Accessibility Compliance topic.

Criterion How the component complies
1.3.1 Info and Relationships The tablist, tab, and tabpanel roles expose the structure, and each tab panel is labeled by its tab header through aria-labelledby.
1.4.1 Use of Color In the Material, Fluent, and Indigo themes, the selected tab header shows an indicator line under it, so the selection doesn’t depend on color alone.
2.1.1 Keyboard The arrow keys, Home, and End move between the tab headers, and Enter and Space select the focused tab.
2.1.2 No Keyboard Trap The Tabs component doesn’t handle the Tab key, so Tab and Shift + Tab move the focus out of the header strip.
2.4.3 Focus Order The header strip is a single tab stop, followed by the content of the selected tab.
2.4.7 Focus Visible The focused tab header takes the hover colors of the theme, so it stands out from the other tab headers.
4.1.2 Name, Role, Value Each tab header exposes the tab role, a name from its content, and its selected and disabled states through aria-selected and aria-disabled.

Your responsibilities:

  • Give every tab a text label that names its content. A tab takes its accessible name from its header content, so a header with an icon only needs a text alternative. See Type.
  • When you override the theme colors, keep a contrast ratio of at least 3:1 between the selected indicator and the background, as 1.4.11 Non-text Contrast requires, and keep the focused tab header distinct from the other headers.
  • Don’t use the Tabs for the steps of a sequential process. Use a Stepper, which communicates the order of the steps.

API References

Dependencies

The React Tabs component requires a theme to apply its colors and sizes. See the framework-specific setup in Getting Started.

Additional Resources

The following resources provide more React Tabs guidance and project support:

The React Tabs component shows one section of related content at a time. Use these components when the content needs a different structure:

  • Stepper - Use Stepper when users complete a sequence of steps, such as a checkout process.
  • Accordion - Use Accordion when users need to expand several sections of a vertical list at the same time.

FAQ

These questions cover common React Tabs setup, accessibility, and usage scenarios.

How do I select a tab in code?

Call the select method of the React Tabs with a tab, or with the id or the label of a tab, or set selected on the tab. The React Tabs component doesn’t emit the change event for a selection that you make in code.

Can I prevent users from switching to another tab?

The change event of the React Tabs component isn’t cancelable, because the React Tabs component emits it after the selection changes. Set disabled on the tabs that users must not open, and enable them when they become available.

Does the Tabs component keep the content of hidden tabs in the DOM?

Yes. The React Tabs component keeps the content of every tab in the DOM, hides the content of the tabs that aren’t selected, and makes it inert, so users and assistive technology can’t reach it until its tab is selected.

Should I use the Tabs for a checkout or another step-by-step process?

No. The React Tabs component organizes related information that users can open in any order, and it doesn’t communicate an order of steps. Use the React Stepper for a sequential process, such as a checkout or a configuration wizard.