Tabs

Content in tabs: a label and its content per row.

When to use it

A few parts of equal weight where the visitor needs only one at a time: the plans of a service, instructions per system.

When not to

Content everyone must read, and more than five or six tabs (use headings and a table of contents).

Accessibility

Tabs follow the WAI-ARIA tab pattern: arrows move between tabs and the panel follows. Without the script, every part is shown under its own heading.

See it live

The component library shows this component in the default theme, in every variant: open it in the component library

The tabs example as the component library shows it in the default theme

Fields

What the component’s dialog asks for. In a Doc, keyed rows start with the key; rows in order follow the order below. Each row is one item, its cells in the order of the fields.

Field

Key

Kind

Required

Label

label

Plain text, one line

Yes

Content

content

Text with headings, lists, links and bold

Yes

Variants

This component has no variants of its own; a theme can add some.

Warnings it can raise

The editor and the build say these when a block of this component needs a fix. All warnings are listed in the warnings reference.

Code

What it says

single_item_container

A {block} has a single item; a simpler component would do.

unnamed_item

Item {index} of a {block} has no title; a generic name is used.

In Google Docs

A component is a table. Its first cell names it; the rows below hold its fields. This is the example table:

tabs

Summer

Hiking, climbing and kayaking.

Winter

Ski touring and snowshoeing.

In a page file

In a site kept as a folder or in Git, the same component is a block of the page’s JSON file:

JSON
{
  "name": "tabs",
  "rows": [
    [
      "Summer",
      "Hiking, climbing and kayaking."
    ],
    [
      "Winter",
      "Ski touring and snowshoeing."
    ]
  ]
}

Markup and classes

What the component writes takes these classes, for a theme’s CSS: the component’s own name, name__part for its parts and name--variant for each variant (the variant’s plain name is there too).

Class

What it marks

tabs

The component

tabs__label

A part of it

tabs__list

A part of it

tabs__panel

A part of it

tabs__tab

A part of it

tabs--enhanced

Added by the component itself: a setting, or what its script does

The HTML the example above writes, as the component library builds it in the default theme:

html
<div class="tabs" data-tabs>
<h3 class="tabs__label" id="tabs-1-label-1">Summer</h3>
<div class="tabs__panel" id="tabs-1-panel-1"><p>Hiking, climbing and kayaking.</p></div>
<h3 class="tabs__label" id="tabs-1-label-2">Winter</h3>
<div class="tabs__panel" id="tabs-1-panel-2"><p>Ski touring and snowshoeing.</p></div>
</div>

Visitor texts

Texts it shows visitors, in the page’s language. Every one is in the visitor texts reference.

Key

Text

site.tabs.untitled

Tab {n}

Extending it

Its files in SeedPage. A theme or a site changes the markup by giving a file of the same name (the Liquid part), and a new component can extend this one.

  • src/components/tabs.js
  • src/components/tabs/tabs.liquid
  • src/components/tabs.client.js

It has a browser script, the .client.js file above. Without it the component still shows all its content; the script only adds behaviour.