Components

Tabs

Easily create accessible, fully customizable tab interfaces, with robust focus management and keyboard navigation support.

Usage 

This is the tab panel for "Recent".

<ui:Tab.Group>
  <ui:Tab.List>
    <ui:Tab target="demo-recent" selected>Recent</ui:Tab>
    <ui:Tab target="demo-popular">Popular</ui:Tab>
    <ui:Tab target="demo-trending">Trending</ui:Tab>
  </ui:Tab.List>

  <ui:Tab.Panel id="demo-recent">
    <p>This is the tab panel for <b>"Recent"</b>.</p>
  </ui:Tab.Panel>

  <ui:Tab.Panel id="demo-popular" hidden>
    <p>This is the tab panel for <b>"Popular"</b>.</p>
  </ui:Tab.Panel>

  <ui:Tab.Panel id="demo-trending" hidden>
    <p>This is the tab panel for <b>"Trending"</b>.</p>
  </ui:Tab.Panel>
</ui:Tab.Group>

Tabs are built using the Tab.Group, Tab.List, Tab, and Tab.Panel components. Clicking on any tab or selecting it with the keyboard will activate the corresponding panel.

Disabling a tab 

To disable a tab, use the disabled attribute on the Tab component. Disabled tabs cannot be selected with the mouse, and are also skipped when navigating the tab list using the keyboard.

Manually activating tabs 

By default, tabs are automatically selected as the user navigates through them using the arrow kbds.

If you'd rather not change the current tab until the user presses Enter or Space, use the manual attribute on the Tab.Group component.

Remember to add styles to the :focus state of the tab so is clear to the user that the tab is focused.

This is the tab panel for "Recent".

This is the tab panel for "Disabled".

<ui:Tab.Group manual>
  <ui:Tab.List>
    <ui:Tab target="manual-recent" selected>Recent</ui:Tab>
    <ui:Tab target="manual-popular">Popular</ui:Tab>
    <ui:Tab target="manual-disabled" disabled>Disabled</ui:Tab>
    <ui:Tab target="manual-trending">Trending</ui:Tab>
  </ui:Tab.List>

  <ui:Tab.Panel id="manual-recent">
    <p>This is the tab panel for <b>"Recent"</b>.</p>
  </ui:Tab.Panel>

  <ui:Tab.Panel id="manual-popular" hidden>
    <p>This is the tab panel for <b>"Popular"</b>.</p>
  </ui:Tab.Panel>

  <ui:Tab.Panel id="manual-disabled" hidden>
    <p>This is the tab panel for "Disabled".</p>
  </ui:Tab.Panel>

  <ui:Tab.Panel id="manual-trending" hidden>
    <p>This is the tab panel for <b>"Trending"</b>.</p>
  </ui:Tab.Panel>
</ui:Tab.Group>

The manual prop has no impact on mouse interactions — tabs will still be selected as soon as they are clicked.

Tab.List Position 

You can choose on which side of the tab panels the Tab.List is rendered by setting the position attribute on the Tab.List component.

Top (default) 

This is the tab panel for "Recent".

<ui:Tab.Group position="top">
  <ui:Tab.List>
    <ui:Tab target="pt-recent" selected>Recent</ui:Tab>
    <ui:Tab target="pt-popular">Popular</ui:Tab>
    <ui:Tab target="pt-trending">Trending</ui:Tab>
  </ui:Tab.List>
  <ui:Tab.Panel id="pt-recent">
    <p>This is the tab panel for <b>"Recent"</b>.</p>
  </ui:Tab.Panel>
  <ui:Tab.Panel id="pt-popular" hidden>
    <p>This is the tab panel for <b>"Popular"</b>.</p>
  </ui:Tab.Panel>
  <ui:Tab.Panel id="pt-trending" hidden>
    <p>This is the tab panel for <b>"Trending"</b>.</p>
  </ui:Tab.Panel>
</ui:Tab.Group>

Bottom 

This is the tab panel for "Recent".

<ui:Tab.Group position="bottom">
  <ui:Tab.List>
    <ui:Tab target="pb-recent" selected>Recent</ui:Tab>
    <ui:Tab target="pb-popular">Popular</ui:Tab>
    <ui:Tab target="pb-trending">Trending</ui:Tab>
  </ui:Tab.List>
  <ui:Tab.Panel id="pb-recent">
    <p>This is the tab panel for <b>"Recent"</b>.</p>
  </ui:Tab.Panel>
  <ui:Tab.Panel id="pb-popular" hidden>
    <p>This is the tab panel for <b>"Popular"</b>.</p>
  </ui:Tab.Panel>
  <ui:Tab.Panel id="pb-trending" hidden>
    <p>This is the tab panel for <b>"Trending"</b>.</p>
  </ui:Tab.Panel>
</ui:Tab.Group>

Left 

This is the tab panel for "Recent".

<ui:Tab.Group position="left">
  <ui:Tab.List>
    <ui:Tab target="pl-recent" selected>Recent</ui:Tab>
    <ui:Tab target="pl-popular">Popular</ui:Tab>
    <ui:Tab target="pl-trending">Trending</ui:Tab>
  </ui:Tab.List>
  <ui:Tab.Panel id="pl-recent">
    <p>This is the tab panel for <b>"Recent"</b>.</p>
  </ui:Tab.Panel>
  <ui:Tab.Panel id="pl-popular" hidden>
    <p>This is the tab panel for <b>"Popular"</b>.</p>
  </ui:Tab.Panel>
  <ui:Tab.Panel id="pl-trending" hidden>
    <p>This is the tab panel for <b>"Trending"</b>.</p>
  </ui:Tab.Panel>
</ui:Tab.Group>

Right 

This is the tab panel for "Recent".

<ui:Tab.Group position="right">
  <ui:Tab.List>
    <ui:Tab target="pr-recent" selected>Recent</ui:Tab>
    <ui:Tab target="pr-popular">Popular</ui:Tab>
    <ui:Tab target="pr-trending">Trending</ui:Tab>
  </ui:Tab.List>
  <ui:Tab.Panel id="pr-recent">
    <p>This is the tab panel for <b>"Recent"</b>.</p>
  </ui:Tab.Panel>
  <ui:Tab.Panel id="pr-popular" hidden>
    <p>This is the tab panel for <b>"Popular"</b>.</p>
  </ui:Tab.Panel>
  <ui:Tab.Panel id="pr-trending" hidden>
    <p>This is the tab panel for <b>"Trending"</b>.</p>
  </ui:Tab.Panel>
</ui:Tab.Group>

Tab.List Align 

You can also choose if you want the tabs to aligned to the start of the list (the default), center or to the end, by setting the align attribute on the Tab.List component.

This is the tab panel for "Recent".

This is the tab panel for "Recent".

This is the tab panel for "Recent".

<div class="row">
  <ui:Tab.Group align="start">
    <ui:Tab.List>
      <ui:Tab target="a1-recent" selected>Recent</ui:Tab>
      <ui:Tab target="a1-popular">Popular</ui:Tab>
      <ui:Tab target="a1-trending">Trending</ui:Tab>
    </ui:Tab.List>
    <ui:Tab.Panel id="a1-recent">
      <p>This is the tab panel for <b>"Recent"</b>.</p>
    </ui:Tab.Panel>
    <ui:Tab.Panel id="a1-popular" hidden>
      <p>This is the tab panel for <b>"Popular"</b>.</p>
    </ui:Tab.Panel>
    <ui:Tab.Panel id="a1-trending" hidden>
      <p>This is the tab panel for <b>"Trending"</b>.</p>
    </ui:Tab.Panel>
  </ui:Tab.Group>
</div>
<div class="row">
  <ui:Tab.Group align="center">
    <ui:Tab.List>
      <ui:Tab target="a2-recent" selected>Recent</ui:Tab>
      <ui:Tab target="a2-popular">Popular</ui:Tab>
      <ui:Tab target="a2-trending">Trending</ui:Tab>
    </ui:Tab.List>
    <ui:Tab.Panel id="a2-recent">
      <p>This is the tab panel for <b>"Recent"</b>.</p>
    </ui:Tab.Panel>
    <ui:Tab.Panel id="a2-popular" hidden>
      <p>This is the tab panel for <b>"Popular"</b>.</p>
    </ui:Tab.Panel>
    <ui:Tab.Panel id="a2-trending" hidden>
      <p>This is the tab panel for <b>"Trending"</b>.</p>
    </ui:Tab.Panel>
  </ui:Tab.Group>
</div>
<div class="row">
  <ui:Tab.Group align="end">
    <ui:Tab.List>
      <ui:Tab target="a3-recent" selected>Recent</ui:Tab>
      <ui:Tab target="a3-popular">Popular</ui:Tab>
      <ui:Tab target="a3-trending">Trending</ui:Tab>
    </ui:Tab.List>
    <ui:Tab.Panel id="a3-recent">
      <p>This is the tab panel for <b>"Recent"</b>.</p>
    </ui:Tab.Panel>
    <ui:Tab.Panel id="a3-popular" hidden>
      <p>This is the tab panel for <b>"Popular"</b>.</p>
    </ui:Tab.Panel>
    <ui:Tab.Panel id="a3-trending" hidden>
      <p>This is the tab panel for <b>"Trending"</b>.</p>
    </ui:Tab.Panel>
  </ui:Tab.Group>
</div>

Controlling the tabs with a <select> 

In narrow screens, you might want to hide the tabs and display a <select> element instead. To do so, use the Tab.Select and Tab.Option components. A Tab.Select component is a wrapper for a <select> element, and it accepts Tab.Option components as children.

arrow_drop_down

This is the tab panel for "Recent".

This is the tab panel for "Disabled".

<ui:Tab.Group>
  <ui:Tab.Select>
    <ui:Tab.Option target="select-recent">Recent</ui:Tab.Option>
    <ui:Tab.Option target="select-popular">Popular</ui:Tab.Option>
    <ui:Tab.Option target="select-disabled" disabled>Disabled</ui:Tab.Option>
    <ui:Tab.Option target="select-trending">Trending</ui:Tab.Option>
  </ui:Tab.Select>

  <ui:Tab.List data-hidden>
    <ui:Tab target="select-recent">Recent</ui:Tab>
    <ui:Tab target="select-popular" selected>Popular</ui:Tab>
    <ui:Tab target="select-disabled" disabled>Disabled</ui:Tab>
    <ui:Tab target="select-trending">Trending</ui:Tab>
  </ui:Tab.List>

  <ui:Tab.Panel id="select-recent">
    <p>This is the tab panel for <b>"Recent"</b>.</p>
  </ui:Tab.Panel>

  <ui:Tab.Panel id="select-popular" hidden>
    <p>This is the tab panel for <b>"Popular"</b>.</p>
  </ui:Tab.Panel>

  <ui:Tab.Panel id="select-disabled" hidden>
    <p>This is the tab panel for "Disabled".</p>
  </ui:Tab.Panel>

  <ui:Tab.Panel id="select-trending" hidden>
    <p>This is the tab panel for <b>"Trending"</b>.</p>
  </ui:Tab.Panel>
</ui:Tab.Group>

Component arguments 

Tab.Group 

ArgumentTypeDescription
tag str HTML tag used for rendering the wrapper. Default is div.

Tab.List 

ArgumentTypeDescription
position str top, right, botton, or left. Default is top.
align str start, center, or end. Default is start.
manual bool If true, selecting a tab with the keyboard won't activate it, you must press Enter os Space kbds to do it. Default is false.
tag str HTML tag used for rendering the wrapper. Default is nav.

Tab 

ArgumentTypeDescription
target str Required. HTML id of the panel associated with this tab.
selected bool Initially selected tab. Only one tab in the Tab.List can be selected at the time. Default is false.
disabled bool If the tab can be selected. Default is false.
tag str HTML tag used for rendering the tab. Default is button.

Tab.Panel 

ArgumentTypeDescription
hidden bool Initially hidden panel. Default is false.
tag str HTML tag used for rendering the panel. Default is div.

Tab.Select 

No arguments.

Tab.Option 

ArgumentTypeDescription
target str Required. HTML id of the panel associated with this tab.
disabled bool Display the option but not allow to select it.

Events 

The tab group emits a tab:selected event every time is selected. The event contains the target property with the tag node.

document.addEventListener("jxui:tab:selected", (event) => {
  console.log(`'${event.target.textContent}' tab selected`);
});

Accessibility notes 

Mouse interaction 

Clicking a Tab will select that tab and display the corresponding Tab.Panel.

Keyboard interaction 

All interactions apply when a Tab component is focused.

CommandDescription
/ arrow Selects the previous non-disabled tab, cycling from first to last.
/ arrow Selects the next non-disabled tab, cycling from last to first.
Enter or Space when `manual` is set. Activates the selected tab.
Home or PageUp Activates the **first** non-disabled tab.
End or PageDown Activates the **last** non-disabled tab.

Components 

Component
File
Source
Tab
tab/index.jinja
Tab.Group
tab/group.jinja
Tab.List
tab/list.jinja
Tab.Panel
tab/panel.jinja
Tab.Select
tab/select.jinja
Tab.Option
tab/option.jinja
tab/tab.css
tab/tab.js