Light Dark System

Tab Group

<p-tab-group> | PTabGroup
Since 1.0 stable

Tab groups organize content into a container that shows one section at a time.

Tab groups make use of tabs and tab panels. Each tab must be slotted into the nav slot and its panel must refer to a tab panel of the same name.

General Custom Advanced Disabled This is the general tab panel. This is the custom tab panel. This is the advanced tab panel. This is a disabled tab panel.
<p-tab-group>
  <p-tab slot="nav" panel="general">General</p-tab>
  <p-tab slot="nav" panel="custom">Custom</p-tab>
  <p-tab slot="nav" panel="advanced">Advanced</p-tab>
  <p-tab slot="nav" panel="disabled" disabled>Disabled</p-tab>

  <p-tab-panel name="general">This is the general tab panel.</p-tab-panel>
  <p-tab-panel name="custom">This is the custom tab panel.</p-tab-panel>
  <p-tab-panel name="advanced">This is the advanced tab panel.</p-tab-panel>
  <p-tab-panel name="disabled">This is a disabled tab panel.</p-tab-panel>
</p-tab-group>
import PTab from 'pure-uikit/dist/react/tab';
import PTabGroup from 'pure-uikit/dist/react/tab-group';
import PTabPanel from 'pure-uikit/dist/react/tab-panel';

const App = () => (
  <PTabGroup>
    <PTab slot="nav" panel="general">
      General
    </PTab>
    <PTab slot="nav" panel="custom">
      Custom
    </PTab>
    <PTab slot="nav" panel="advanced">
      Advanced
    </PTab>
    <PTab slot="nav" panel="disabled" disabled>
      Disabled
    </PTab>

    <PTabPanel name="general">This is the general tab panel.</PTabPanel>
    <PTabPanel name="custom">This is the custom tab panel.</PTabPanel>
    <PTabPanel name="advanced">This is the advanced tab panel.</PTabPanel>
    <PTabPanel name="disabled">This is a disabled tab panel.</PTabPanel>
  </PTabGroup>
);

Examples

Tabs on Bottom

Tabs can be shown on the bottom by setting placement to bottom.

General Custom Advanced Disabled This is the general tab panel. This is the custom tab panel. This is the advanced tab panel. This is a disabled tab panel.
<p-tab-group placement="bottom">
  <p-tab slot="nav" panel="general">General</p-tab>
  <p-tab slot="nav" panel="custom">Custom</p-tab>
  <p-tab slot="nav" panel="advanced">Advanced</p-tab>
  <p-tab slot="nav" panel="disabled" disabled>Disabled</p-tab>

  <p-tab-panel name="general">This is the general tab panel.</p-tab-panel>
  <p-tab-panel name="custom">This is the custom tab panel.</p-tab-panel>
  <p-tab-panel name="advanced">This is the advanced tab panel.</p-tab-panel>
  <p-tab-panel name="disabled">This is a disabled tab panel.</p-tab-panel>
</p-tab-group>
import PTab from 'pure-uikit/dist/react/tab';
import PTabGroup from 'pure-uikit/dist/react/tab-group';
import PTabPanel from 'pure-uikit/dist/react/tab-panel';

const App = () => (
  <PTabGroup placement="bottom">
    <PTab slot="nav" panel="general">
      General
    </PTab>
    <PTab slot="nav" panel="custom">
      Custom
    </PTab>
    <PTab slot="nav" panel="advanced">
      Advanced
    </PTab>
    <PTab slot="nav" panel="disabled" disabled>
      Disabled
    </PTab>

    <PTabPanel name="general">This is the general tab panel.</PTabPanel>
    <PTabPanel name="custom">This is the custom tab panel.</PTabPanel>
    <PTabPanel name="advanced">This is the advanced tab panel.</PTabPanel>
    <PTabPanel name="disabled">This is a disabled tab panel.</PTabPanel>
  </PTabGroup>
);

Tabs on Start

Tabs can be shown on the starting side by setting placement to start.

General Custom Advanced Disabled This is the general tab panel. This is the custom tab panel. This is the advanced tab panel. This is a disabled tab panel.
<p-tab-group placement="start">
  <p-tab slot="nav" panel="general">General</p-tab>
  <p-tab slot="nav" panel="custom">Custom</p-tab>
  <p-tab slot="nav" panel="advanced">Advanced</p-tab>
  <p-tab slot="nav" panel="disabled" disabled>Disabled</p-tab>

  <p-tab-panel name="general">This is the general tab panel.</p-tab-panel>
  <p-tab-panel name="custom">This is the custom tab panel.</p-tab-panel>
  <p-tab-panel name="advanced">This is the advanced tab panel.</p-tab-panel>
  <p-tab-panel name="disabled">This is a disabled tab panel.</p-tab-panel>
</p-tab-group>
import PTab from 'pure-uikit/dist/react/tab';
import PTabGroup from 'pure-uikit/dist/react/tab-group';
import PTabPanel from 'pure-uikit/dist/react/tab-panel';

const App = () => (
  <PTabGroup placement="start">
    <PTab slot="nav" panel="general">
      General
    </PTab>
    <PTab slot="nav" panel="custom">
      Custom
    </PTab>
    <PTab slot="nav" panel="advanced">
      Advanced
    </PTab>
    <PTab slot="nav" panel="disabled" disabled>
      Disabled
    </PTab>

    <PTabPanel name="general">This is the general tab panel.</PTabPanel>
    <PTabPanel name="custom">This is the custom tab panel.</PTabPanel>
    <PTabPanel name="advanced">This is the advanced tab panel.</PTabPanel>
    <PTabPanel name="disabled">This is a disabled tab panel.</PTabPanel>
  </PTabGroup>
);

Tabs on End

Tabs can be shown on the ending side by setting placement to end.

General Custom Advanced Disabled This is the general tab panel. This is the custom tab panel. This is the advanced tab panel. This is a disabled tab panel.
<p-tab-group placement="end">
  <p-tab slot="nav" panel="general">General</p-tab>
  <p-tab slot="nav" panel="custom">Custom</p-tab>
  <p-tab slot="nav" panel="advanced">Advanced</p-tab>
  <p-tab slot="nav" panel="disabled" disabled>Disabled</p-tab>

  <p-tab-panel name="general">This is the general tab panel.</p-tab-panel>
  <p-tab-panel name="custom">This is the custom tab panel.</p-tab-panel>
  <p-tab-panel name="advanced">This is the advanced tab panel.</p-tab-panel>
  <p-tab-panel name="disabled">This is a disabled tab panel.</p-tab-panel>
</p-tab-group>
import PTab from 'pure-uikit/dist/react/tab';
import PTabGroup from 'pure-uikit/dist/react/tab-group';
import PTabPanel from 'pure-uikit/dist/react/tab-panel';

const App = () => (
  <PTabGroup placement="end">
    <PTab slot="nav" panel="general">
      General
    </PTab>
    <PTab slot="nav" panel="custom">
      Custom
    </PTab>
    <PTab slot="nav" panel="advanced">
      Advanced
    </PTab>
    <PTab slot="nav" panel="disabled" disabled>
      Disabled
    </PTab>

    <PTabPanel name="general">This is the general tab panel.</PTabPanel>
    <PTabPanel name="custom">This is the custom tab panel.</PTabPanel>
    <PTabPanel name="advanced">This is the advanced tab panel.</PTabPanel>
    <PTabPanel name="disabled">This is a disabled tab panel.</PTabPanel>
  </PTabGroup>
);

Closable Tabs

Add the closable attribute to a tab to show a close button. This example shows how you can dynamically remove tabs from the DOM when the close button is activated.

General Closable 1 Closable 2 Closable 3 This is the general tab panel. This is the first closable tab panel. This is the second closable tab panel. This is the third closable tab panel.
<p-tab-group class="tabs-closable">
  <p-tab slot="nav" panel="general">General</p-tab>
  <p-tab slot="nav" panel="closable-1" closable>Closable 1</p-tab>
  <p-tab slot="nav" panel="closable-2" closable>Closable 2</p-tab>
  <p-tab slot="nav" panel="closable-3" closable>Closable 3</p-tab>

  <p-tab-panel name="general">This is the general tab panel.</p-tab-panel>
  <p-tab-panel name="closable-1">This is the first closable tab panel.</p-tab-panel>
  <p-tab-panel name="closable-2">This is the second closable tab panel.</p-tab-panel>
  <p-tab-panel name="closable-3">This is the third closable tab panel.</p-tab-panel>
</p-tab-group>

<script>
  const tabGroup = document.querySelector('.tabs-closable');

  tabGroup.addEventListener('p-close', async event => {
    const tab = event.target;
    const panel = tabGroup.querySelector(`p-tab-panel[name="${tab.panel}"]`);

    // Show the previous tab if the tab is currently active
    if (tab.active) {
      tabGroup.show(tab.previousElementSibling.panel);
    }

    // Remove the tab + panel
    tab.remove();
    panel.remove();
  });
</script>
import PTab from 'pure-uikit/dist/react/tab';
import PTabGroup from 'pure-uikit/dist/react/tab-group';
import PTabPanel from 'pure-uikit/dist/react/tab-panel';

const App = () => {
  function handleClose(event) {
    //
    // This is a crude example that removes the tab and its panel from the DOM.
    // There are better ways to manage tab creation/removal in React, but that
    // would significantly complicate the example.
    //
    const tab = event.target;
    const tabGroup = tab.closest('p-tab-group');
    const tabPanel = tabGroup.querySelector(`[aria-labelledby="${tab.id}"]`);

    tab.remove();
    tabPanel.remove();
  }

  return (
    <PTabGroup className="tabs-closable" onPClose={handleClose}>
      <PTab slot="nav" panel="general">
        General
      </PTab>
      <PTab slot="nav" panel="closable-1" closable onPClose={handleClose}>
        Closable 1
      </PTab>
      <PTab slot="nav" panel="closable-2" closable onPClose={handleClose}>
        Closable 2
      </PTab>
      <PTab slot="nav" panel="closable-3" closable onPClose={handleClose}>
        Closable 3
      </PTab>

      <PTabPanel name="general">This is the general tab panel.</PTabPanel>
      <PTabPanel name="closable-1">This is the first closable tab panel.</PTabPanel>
      <PTabPanel name="closable-2">This is the second closable tab panel.</PTabPanel>
      <PTabPanel name="closable-3">This is the third closable tab panel.</PTabPanel>
    </PTabGroup>
  );
};

Scrolling Tabs

When there are more tabs than horizontal space allows, the nav will be scrollable.

Tab 1 Tab 2 Tab 3 Tab 4 Tab 5 Tab 6 Tab 7 Tab 8 Tab 9 Tab 10 Tab 11 Tab 12 Tab 13 Tab 14 Tab 15 Tab 16 Tab 17 Tab 18 Tab 19 Tab 20 Tab panel 1 Tab panel 2 Tab panel 3 Tab panel 4 Tab panel 5 Tab panel 6 Tab panel 7 Tab panel 8 Tab panel 9 Tab panel 10 Tab panel 11 Tab panel 12 Tab panel 13 Tab panel 14 Tab panel 15 Tab panel 16 Tab panel 17 Tab panel 18 Tab panel 19 Tab panel 20
<p-tab-group>
  <p-tab slot="nav" panel="tab-1">Tab 1</p-tab>
  <p-tab slot="nav" panel="tab-2">Tab 2</p-tab>
  <p-tab slot="nav" panel="tab-3">Tab 3</p-tab>
  <p-tab slot="nav" panel="tab-4">Tab 4</p-tab>
  <p-tab slot="nav" panel="tab-5">Tab 5</p-tab>
  <p-tab slot="nav" panel="tab-6">Tab 6</p-tab>
  <p-tab slot="nav" panel="tab-7">Tab 7</p-tab>
  <p-tab slot="nav" panel="tab-8">Tab 8</p-tab>
  <p-tab slot="nav" panel="tab-9">Tab 9</p-tab>
  <p-tab slot="nav" panel="tab-10">Tab 10</p-tab>
  <p-tab slot="nav" panel="tab-11">Tab 11</p-tab>
  <p-tab slot="nav" panel="tab-12">Tab 12</p-tab>
  <p-tab slot="nav" panel="tab-13">Tab 13</p-tab>
  <p-tab slot="nav" panel="tab-14">Tab 14</p-tab>
  <p-tab slot="nav" panel="tab-15">Tab 15</p-tab>
  <p-tab slot="nav" panel="tab-16">Tab 16</p-tab>
  <p-tab slot="nav" panel="tab-17">Tab 17</p-tab>
  <p-tab slot="nav" panel="tab-18">Tab 18</p-tab>
  <p-tab slot="nav" panel="tab-19">Tab 19</p-tab>
  <p-tab slot="nav" panel="tab-20">Tab 20</p-tab>

  <p-tab-panel name="tab-1">Tab panel 1</p-tab-panel>
  <p-tab-panel name="tab-2">Tab panel 2</p-tab-panel>
  <p-tab-panel name="tab-3">Tab panel 3</p-tab-panel>
  <p-tab-panel name="tab-4">Tab panel 4</p-tab-panel>
  <p-tab-panel name="tab-5">Tab panel 5</p-tab-panel>
  <p-tab-panel name="tab-6">Tab panel 6</p-tab-panel>
  <p-tab-panel name="tab-7">Tab panel 7</p-tab-panel>
  <p-tab-panel name="tab-8">Tab panel 8</p-tab-panel>
  <p-tab-panel name="tab-9">Tab panel 9</p-tab-panel>
  <p-tab-panel name="tab-10">Tab panel 10</p-tab-panel>
  <p-tab-panel name="tab-11">Tab panel 11</p-tab-panel>
  <p-tab-panel name="tab-12">Tab panel 12</p-tab-panel>
  <p-tab-panel name="tab-13">Tab panel 13</p-tab-panel>
  <p-tab-panel name="tab-14">Tab panel 14</p-tab-panel>
  <p-tab-panel name="tab-15">Tab panel 15</p-tab-panel>
  <p-tab-panel name="tab-16">Tab panel 16</p-tab-panel>
  <p-tab-panel name="tab-17">Tab panel 17</p-tab-panel>
  <p-tab-panel name="tab-18">Tab panel 18</p-tab-panel>
  <p-tab-panel name="tab-19">Tab panel 19</p-tab-panel>
  <p-tab-panel name="tab-20">Tab panel 20</p-tab-panel>
</p-tab-group>
import PTab from 'pure-uikit/dist/react/tab';
import PTabGroup from 'pure-uikit/dist/react/tab-group';
import PTabPanel from 'pure-uikit/dist/react/tab-panel';

const App = () => (
  <PTabGroup>
    <PTab slot="nav" panel="tab-1">
      Tab 1
    </PTab>
    <PTab slot="nav" panel="tab-2">
      Tab 2
    </PTab>
    <PTab slot="nav" panel="tab-3">
      Tab 3
    </PTab>
    <PTab slot="nav" panel="tab-4">
      Tab 4
    </PTab>
    <PTab slot="nav" panel="tab-5">
      Tab 5
    </PTab>
    <PTab slot="nav" panel="tab-6">
      Tab 6
    </PTab>
    <PTab slot="nav" panel="tab-7">
      Tab 7
    </PTab>
    <PTab slot="nav" panel="tab-8">
      Tab 8
    </PTab>
    <PTab slot="nav" panel="tab-9">
      Tab 9
    </PTab>
    <PTab slot="nav" panel="tab-10">
      Tab 10
    </PTab>
    <PTab slot="nav" panel="tab-11">
      Tab 11
    </PTab>
    <PTab slot="nav" panel="tab-12">
      Tab 12
    </PTab>
    <PTab slot="nav" panel="tab-13">
      Tab 13
    </PTab>
    <PTab slot="nav" panel="tab-14">
      Tab 14
    </PTab>
    <PTab slot="nav" panel="tab-15">
      Tab 15
    </PTab>
    <PTab slot="nav" panel="tab-16">
      Tab 16
    </PTab>
    <PTab slot="nav" panel="tab-17">
      Tab 17
    </PTab>
    <PTab slot="nav" panel="tab-18">
      Tab 18
    </PTab>
    <PTab slot="nav" panel="tab-19">
      Tab 19
    </PTab>
    <PTab slot="nav" panel="tab-20">
      Tab 20
    </PTab>

    <PTabPanel name="tab-1">Tab panel 1</PTabPanel>
    <PTabPanel name="tab-2">Tab panel 2</PTabPanel>
    <PTabPanel name="tab-3">Tab panel 3</PTabPanel>
    <PTabPanel name="tab-4">Tab panel 4</PTabPanel>
    <PTabPanel name="tab-5">Tab panel 5</PTabPanel>
    <PTabPanel name="tab-6">Tab panel 6</PTabPanel>
    <PTabPanel name="tab-7">Tab panel 7</PTabPanel>
    <PTabPanel name="tab-8">Tab panel 8</PTabPanel>
    <PTabPanel name="tab-9">Tab panel 9</PTabPanel>
    <PTabPanel name="tab-10">Tab panel 10</PTabPanel>
    <PTabPanel name="tab-11">Tab panel 11</PTabPanel>
    <PTabPanel name="tab-12">Tab panel 12</PTabPanel>
    <PTabPanel name="tab-13">Tab panel 13</PTabPanel>
    <PTabPanel name="tab-14">Tab panel 14</PTabPanel>
    <PTabPanel name="tab-15">Tab panel 15</PTabPanel>
    <PTabPanel name="tab-16">Tab panel 16</PTabPanel>
    <PTabPanel name="tab-17">Tab panel 17</PTabPanel>
    <PTabPanel name="tab-18">Tab panel 18</PTabPanel>
    <PTabPanel name="tab-19">Tab panel 19</PTabPanel>
    <PTabPanel name="tab-20">Tab panel 20</PTabPanel>
  </PTabGroup>
);

Manual Activation

When focused, keyboard users can press Left or Right to select the desired tab. By default, the corresponding tab panel will be shown immediately (automatic activation). You can change this behavior by setting activation="manual" which will require the user to press Space or Enter before showing the tab panel (manual activation).

General Custom Advanced Disabled This is the general tab panel. This is the custom tab panel. This is the advanced tab panel. This is a disabled tab panel.
<p-tab-group activation="manual">
  <p-tab slot="nav" panel="general">General</p-tab>
  <p-tab slot="nav" panel="custom">Custom</p-tab>
  <p-tab slot="nav" panel="advanced">Advanced</p-tab>
  <p-tab slot="nav" panel="disabled" disabled>Disabled</p-tab>

  <p-tab-panel name="general">This is the general tab panel.</p-tab-panel>
  <p-tab-panel name="custom">This is the custom tab panel.</p-tab-panel>
  <p-tab-panel name="advanced">This is the advanced tab panel.</p-tab-panel>
  <p-tab-panel name="disabled">This is a disabled tab panel.</p-tab-panel>
</p-tab-group>
import PTab from 'pure-uikit/dist/react/tab';
import PTabGroup from 'pure-uikit/dist/react/tab-group';
import PTabPanel from 'pure-uikit/dist/react/tab-panel';

const App = () => (
  <PTabGroup activation="manual">
    <PTab slot="nav" panel="general">
      General
    </PTab>
    <PTab slot="nav" panel="custom">
      Custom
    </PTab>
    <PTab slot="nav" panel="advanced">
      Advanced
    </PTab>
    <PTab slot="nav" panel="disabled" disabled>
      Disabled
    </PTab>

    <PTabPanel name="general">This is the general tab panel.</PTabPanel>
    <PTabPanel name="custom">This is the custom tab panel.</PTabPanel>
    <PTabPanel name="advanced">This is the advanced tab panel.</PTabPanel>
    <PTabPanel name="disabled">This is a disabled tab panel.</PTabPanel>
  </PTabGroup>
);

Importing

If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.

Script Import Bundler React

To import this component from the CDN using a script tag:

<script type="module" src="https://cdn.jsdelivr.net/npm/pure-uikit@1.2.15/cdn/components/tab-group/tab-group.js"></script>

To import this component from the CDN using a JavaScript import:

import 'https://cdn.jsdelivr.net/npm/pure-uikit@1.2.15/cdn/components/tab-group/tab-group.js';

To import this component using a bundler:

import 'pure-uikit/dist/components/tab-group/tab-group.js';

To import this component as a React component:

import PTabGroup from 'pure-uikit/dist/react/tab-group';

Slots

Name Description
(default) Used for grouping tab panels in the tab group. Must be <p-tab-panel> elements.
nav Used for grouping tabs in the tab group. Must be <p-tab> elements.

Learn more about using slots.

Properties

Name Description Reflects Type Default
placement The placement of the tabs. "top" | "bottom" | "start" | "end" "top"
activation When set to auto, navigating tabs with the arrow keys will instantly show the corresponding tab panel. When set to manual, the tab will receive focus but will not show until the user presses spacebar or enter. "auto" | "manual" "auto"
noScrollControls
no-scroll-controls
Disables the scroll arrows that appear when tabs overflow. boolean false
updateComplete A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties.

Events

Name React Event Description Event Detail
p-tab-show onPTabShow Emitted when a tab is shown. { name: String }
p-tab-hide onPTabHide Emitted when a tab is hidden. { name: String }

Learn more about events.

Methods

Name Description Arguments
show() Shows the specified tab panel. panel: string

Learn more about methods.

Custom Properties

Name Description Default
--indicator-color The color of the active tab indicator.
--track-color The color of the indicator’s track (the line that separates tabs from panels).
--track-width The width of the indicator’s track (the line that separates tabs from panels).

Learn more about customizing CSS custom properties.

Parts

Name Description
base The component’s base wrapper.
nav The tab group’s navigation container where tabs are slotted in.
tabs The container that wraps the tabs.
active-tab-indicator The line that highlights the currently selected tab.
body The tab group’s body where tab panels are slotted in.
scroll-button The previous/next scroll buttons that show when tabs are scrollable, an <p-icon-button>.
scroll-button--start The starting scroll button.
scroll-button--end The ending scroll button.
scroll-button__base The scroll button’s exported base part.

Learn more about customizing CSS parts.

Dependencies

This component automatically imports the following dependencies.

  • <p-icon>
  • <p-icon-button>