Tabs
Organize content into separate views where only one view is visible at a time.
The tabs component horizontally layers content sections in an accessible, conformant way. Keystone provide this component as partials (for template use) and as shortcodes (for content use).
The component leverages the partial decorators(Opens in a new tab)
construct introduced in Hugo v0.154.0.
Tabs Pattern
A set of tab elements and their associated tab panels.
A set of tab elements contained in a tablist element.
An element in the tab list that serves as a label for one of the tab panels and can be activated to display that panel.
The element that contains the content associated with a tab.
Reference
The component is composed of a parent ui/tabs and child ui/tab-panel partials.
Parent: ui/tabs
- items
"items" (slice "Tab 1" "Tab 2")— (slice of strings, required)- A list of labels for the tabs.
- These must match the
itemargument in the child partials. - variant
"variant" "pill"— (string, optional)- The visual style of the component.
- Options:
pill,line(default) - label
"label" "Tabs ARIA descriptor"— (string, optional)- Defines the aria-label for the tab list
Child: ui/tab-panel
- item
"item" "Tab 1"— (string, required)- The identifier for the panel.
- Must match one of the strings in the parent
itemsslice.
Installation
The Tabs component is disabled by default to save resources.
Uncomment the imports in the following files:
Javascript
Create the Alpine module:
Import and register it in main.js:
Hugo Partials
Create the parent ui/tabs and child ui/tab-panel partials.
Parent Partial
Child Partial
Hugo Shortcodes
Create the parent ui/tabs and child ui/tab-panel shortcodes.
Parent Shortcode
Child Shortcode
CSS Styling
Create the CSS component:
Import it in your main Tailwind file:
Usage
Use tabs to toggle between mutually exclusive options or content in your templates.
Using Partials (Templates)
When working inside layout files (e.g. layouts/home.html), use the with context pattern:
Using Shortcodes (Markdown)
When working inside content files (e.g. content/install.md), use the shortcode syntax:
Tips & tricks
Internationalization (i18n)
For multilingual templates add the same i18n string as items/item.
Accessibility
The component follows the WAI-ARIA Tabs Pattern(Opens in a new tab) and the WCAG 2.2 Criteria:
- Screen Reader Ready: Automatically generates the required links between buttons and panels.
- Smart Focus: Only the active tab is placed in the tab order. Users can TAB past the entire list.
- Keyboard Traversal: Users can navigate the list using arrow keys ( ) without needing to press ENTER on every item.
- Mobile Friendly: Hides Tabs that overflow horizzontaly and scrolls the active tab into view on small screens to prevent navigation from being hidden.