Tabs ​

The tabs component provides a set of classes to group related content into panels and show one panel at a time.

Tabs implement the spec found in the ARIA Authoring Practices Guide.

Base classes ​

The .tabs class wraps the tab list and its panels. Use .tab-list for the list and give it an accessible name with aria-label or aria-labelledby. Add one .tab-toggle button for each .tab-content panel, keeping the buttons and panels in the same order. If a panel starts with text, add tabindex="0" so readers can reach it by pressing Tab.

Initialization ​

Run the tabs generator after the markup is in the DOM.

js
import generateTabs from "@graupl/core/tabs/generator";

generateTabs();

The generator sets the roles and ARIA attributes that link each button to its panel. To select a tab initially, set aria-selected="true" on its button and add .show to its panel so it is visible before initialization. If no tab is marked as selected, the first tab is selected during initialization.

Variants ​

By default, no theme variants are generated.

If you are compiling your own version of Graupl, you can set the tabs module’s $themeable variable to true to generate the .primary, .secondary, and .tertiary variants. Add a variant class alongside .tabs to style the whole component or to an element inside it to style that part separately.

Custom Properties ​

The following custom properties can be used to customize the tabs component:

Property NameDescriptionDefault Value
--graupl-tabs-padding-xThe horizontal padding of the tabs component.var(--graupl-spacer-0)
--graupl-tabs-padding-yThe vertical padding of the tabs component.var(--graupl-spacer-0)
--graupl-tabs-paddingThe padding of the tabs component (combines y and x padding).var(--graupl-tabs-padding-y) var(--graupl-tabs-padding-x)
--graupl-tabs-colorThe text colour of the tabs component.var(--graupl-color)
--graupl-tabs-backgroundThe background colour of the tabs component.var(--graupl-background)
--graupl-tabs-border-colorThe border colour of the tabs component.var(--graupl-tabs-color)
--graupl-tabs-border-top-left-radiusThe top left border radius of the tabs component.var(--graupl-border-top-left-radius)
--graupl-tabs-border-top-right-radiusThe top right border radius of the tabs component.var(--graupl-border-top-right-radius)
--graupl-tabs-border-bottom-right-radiusThe bottom right border radius of the tabs component.var(--graupl-border-bottom-right-radius)
--graupl-tabs-border-bottom-left-radiusThe bottom left border radius of the tabs component.var(--graupl-border-bottom-left-radius)
--graupl-tabs-border-radiusThe border radius of the tabs component (combines top-left, top-right, bottom-right, and bottom-left).var(--graupl-tabs-border-top-left-radius) var(--graupl-tabs-border-top-right-radius) var(--graupl-tabs-border-bottom-right-radius) var(--graupl-tabs-border-bottom-left-radius)
--graupl-tabs-border-top-widthThe top border width of the tabs component.0rem
--graupl-tabs-border-right-widthThe right border width of the tabs component.0rem
--graupl-tabs-border-bottom-widthThe bottom border width of the tabs component.0rem
--graupl-tabs-border-left-widthThe left border width of the tabs component.0rem
--graupl-tabs-border-widthThe border width of the tabs component (combines top, right, bottom, and left widths).var(--graupl-tabs-border-top-width) var(--graupl-tabs-border-right-width) var(--graupl-tabs-border-bottom-width) var(--graupl-tabs-border-left-width)
--graupl-tabs-border-top-styleThe top border style of the tabs component.var(--graupl-border-top-style)
--graupl-tabs-border-right-styleThe right border style of the tabs component.var(--graupl-border-right-style)
--graupl-tabs-border-bottom-styleThe bottom border style of the tabs component.var(--graupl-border-bottom-style)
--graupl-tabs-border-left-styleThe left border style of the tabs component.var(--graupl-border-left-style)
--graupl-tabs-border-styleThe border style of the tabs component (combines top, right, bottom, and left styles).var(--graupl-tabs-border-top-style) var(--graupl-tabs-border-right-style) var(--graupl-tabs-border-bottom-style) var(--graupl-tabs-border-left-style)
--graupl-tabs-tab-list-column-gapThe column gap between tab toggles.var(--graupl-spacer-0)
--graupl-tabs-tab-list-row-gapThe row gap between tab toggles.var(--graupl-spacer-2)
--graupl-tabs-tab-list-gapThe gap between tab toggles (combines row and column gaps).var(--graupl-tabs-tab-list-row-gap) var(--graupl-tabs-tab-list-column-gap)
--graupl-tabs-tab-list-backgroundThe background colour of the tab list component.var(--graupl-tabs-background)
--graupl-tabs-tab-list-colorThe text colour of the tab list component.var(--graupl-tabs-color)
--graupl-tabs-tab-list-border-colorThe border colour of the tab list component.var(--graupl-tabs-border-color)
--graupl-tabs-tab-list-border-top-left-radiusThe top left border radius of the tab list component.var(--graupl-border-top-left-radius)
--graupl-tabs-tab-list-border-top-right-radiusThe top right border radius of the tab list component.var(--graupl-border-top-right-radius)
--graupl-tabs-tab-list-border-bottom-right-radiusThe bottom right border radius of the tab list component.var(--graupl-border-bottom-right-radius)
--graupl-tabs-tab-list-border-bottom-left-radiusThe bottom left border radius of the tab list component.var(--graupl-border-bottom-left-radius)
--graupl-tabs-tab-list-border-radiusThe border radius of the tab list component.var(--graupl-tabs-tab-list-border-top-left-radius) var(--graupl-tabs-tab-list-border-top-right-radius) var(--graupl-tabs-tab-list-border-bottom-right-radius) var(--graupl-tabs-tab-list-border-bottom-left-radius)
--graupl-tabs-tab-list-border-top-widthThe top border width of the tab list component.0rem
--graupl-tabs-tab-list-border-right-widthThe right border width of the tab list component.0rem
--graupl-tabs-tab-list-border-bottom-widthThe bottom border width of the tab list component.0rem
--graupl-tabs-tab-list-border-left-widthThe left border width of the tab list component.0rem
--graupl-tabs-tab-list-border-widthThe border width of the tab list component (combines top, right, bottom, and left widths).var(--graupl-tabs-tab-list-border-top-width) var(--graupl-tabs-tab-list-border-right-width) var(--graupl-tabs-tab-list-border-bottom-width) var(--graupl-tabs-tab-list-border-left-width)
--graupl-tabs-tab-list-border-top-styleThe top border style of the tab list component.var(--graupl-border-top-style)
--graupl-tabs-tab-list-border-right-styleThe right border style of the tab list component.var(--graupl-border-right-style)
--graupl-tabs-tab-list-border-bottom-styleThe bottom border style of the tab list component.var(--graupl-border-bottom-style)
--graupl-tabs-tab-list-border-left-styleThe left border style of the tab list component.var(--graupl-border-left-style)
--graupl-tabs-tab-list-border-styleThe border style of the tab list component (combines top, right, bottom, and left styles).var(--graupl-tabs-tab-list-border-top-style) var(--graupl-tabs-tab-list-border-right-style) var(--graupl-tabs-tab-list-border-bottom-style) var(--graupl-tabs-tab-list-border-left-style)
--graupl-tabs-tab-list-padding-xThe horizontal padding of the tab list component.var(--graupl-spacer-0)
--graupl-tabs-tab-list-padding-yThe vertical padding of the tab list component.var(--graupl-spacer-0)
--graupl-tabs-tab-list-paddingThe padding of the tab list component (combines y and x padding).var(--graupl-tabs-tab-list-padding-y) var(--graupl-tabs-tab-list-padding-x)
--graupl-tabs-tab-list-marginThe margin of the tab list component.0 0 calc(-1 * max(var(--graupl-tabs-tab-list-border-bottom-width), var(--graupl-tabs-tab-toggle-border-bottom-width))) 0
--graupl-tabs-tab-toggle-padding-xThe horizontal padding of the tab toggle component.var(--graupl-spacer-5)
--graupl-tabs-tab-toggle-padding-yThe vertical padding of the tab toggle component.var(--graupl-spacer-3)
--graupl-tabs-tab-toggle-paddingThe padding of the tab toggle component (combines y and x padding).var(--graupl-tabs-tab-toggle-padding-y) var(--graupl-tabs-tab-toggle-padding-x)
--graupl-tabs-tab-toggle-border-top-left-radiusThe top left border radius of the tab toggle component.var(--graupl-border-top-left-radius)
--graupl-tabs-tab-toggle-border-top-right-radiusThe top right border radius of the tab toggle component.var(--graupl-border-top-right-radius)
--graupl-tabs-tab-toggle-border-bottom-right-radiusThe bottom right border radius of the tab toggle component.var(--graupl-border-bottom-right-radius)
--graupl-tabs-tab-toggle-border-bottom-left-radiusThe bottom left border radius of the tab toggle component.var(--graupl-border-bottom-left-radius)
--graupl-tabs-tab-toggle-border-radiusThe border radius of the tab toggle component.var(--graupl-tabs-tab-toggle-border-top-left-radius) var(--graupl-tabs-tab-toggle-border-top-right-radius) var(--graupl-tabs-tab-toggle-border-bottom-right-radius) var(--graupl-tabs-tab-toggle-border-bottom-left-radius)
--graupl-tabs-tab-toggle-border-top-widthThe top border width of the tab toggle component.var(--graupl-border-top-width)
--graupl-tabs-tab-toggle-border-right-widthThe right border width of the tab toggle component.var(--graupl-border-right-width)
--graupl-tabs-tab-toggle-border-bottom-widthThe bottom border width of the tab toggle component.var(--graupl-border-bottom-width)
--graupl-tabs-tab-toggle-border-left-widthThe left border width of the tab toggle component.var(--graupl-border-left-width)
--graupl-tabs-tab-toggle-border-widthThe border width of the tab toggle component (combines top, right, bottom, and left widths).var(--graupl-tabs-tab-toggle-border-top-width) var(--graupl-tabs-tab-toggle-border-right-width) var(--graupl-tabs-tab-toggle-border-bottom-width) var(--graupl-tabs-tab-toggle-border-left-width)
--graupl-tabs-tab-toggle-border-top-styleThe top border style of the tab toggle component.var(--graupl-border-top-style)
--graupl-tabs-tab-toggle-border-right-styleThe right border style of the tab toggle component.var(--graupl-border-right-style)
--graupl-tabs-tab-toggle-border-bottom-styleThe bottom border style of the tab toggle component.var(--graupl-border-bottom-style)
--graupl-tabs-tab-toggle-border-left-styleThe left border style of the tab toggle component.var(--graupl-border-left-style)
--graupl-tabs-tab-toggle-border-styleThe border style of the tab toggle component (combines top, right, bottom, and left styles).var(--graupl-tabs-tab-toggle-border-top-style) var(--graupl-tabs-tab-toggle-border-right-style) var(--graupl-tabs-tab-toggle-border-bottom-style) var(--graupl-tabs-tab-toggle-border-left-style)
--graupl-tabs-tab-toggle-backgroundThe background colour of the tab toggle component.var(--graupl-tabs-tab-list-background)
--graupl-tabs-tab-toggle-visited-backgroundThe background colour of a visited tab toggle component.var(--graupl-tabs-tab-toggle-background)
--graupl-tabs-tab-toggle-focus-backgroundThe background colour of a focused tab toggle component.var(--graupl-tabs-tab-toggle-background)
--graupl-tabs-tab-toggle-hover-backgroundThe background colour of a hovered tab toggle component.var(--graupl-tabs-tab-list-color)
--graupl-tabs-tab-toggle-active-backgroundThe background colour of an active tab toggle component.var(--graupl-tabs-tab-toggle-hover-background)
--graupl-tabs-tab-toggle-selected-backgroundThe background colour of a selected tab toggle component.var(--graupl-tabs-tab-toggle-hover-background)
--graupl-tabs-tab-toggle-disabled-backgroundThe background colour of a disabled tab toggle component.var(--graupl-tabs-tab-list-background)
--graupl-tabs-tab-toggle-colorThe text colour of the tab toggle component.var(--graupl-tabs-tab-list-color)
--graupl-tabs-tab-toggle-visited-colorThe text colour of a visited tab toggle component.var(--graupl-tabs-tab-toggle-color)
--graupl-tabs-tab-toggle-focus-colorThe text colour of a focused tab toggle component.var(--graupl-tabs-tab-toggle-color)
--graupl-tabs-tab-toggle-hover-colorThe text colour of a hovered tab toggle component.var(--graupl-tabs-tab-list-background)
--graupl-tabs-tab-toggle-active-colorThe text colour of an active tab toggle component.var(--graupl-tabs-tab-toggle-hover-color)
--graupl-tabs-tab-toggle-selected-colorThe text colour of a selected tab toggle component.var(--graupl-tabs-tab-toggle-hover-color)
--graupl-tabs-tab-toggle-disabled-colorThe text colour of a disabled tab toggle component.var(--graupl-theme-active--primary--200)
--graupl-tabs-tab-toggle-border-colorThe border colour of the tab toggle component.var(--graupl-tabs-tab-list-border-color)
--graupl-tabs-tab-toggle-visited-border-colorThe border colour of a visited tab toggle component.var(--graupl-tabs-tab-toggle-border-color)
--graupl-tabs-tab-toggle-focus-border-colorThe border colour of a focused tab toggle component.var(--graupl-tabs-tab-toggle-border-color)
--graupl-tabs-tab-toggle-hover-border-colorThe border colour of a hovered tab toggle component.var(--graupl-tabs-tab-list-border-color)
--graupl-tabs-tab-toggle-active-border-colorThe border colour of an active tab toggle component.var(--graupl-tabs-tab-toggle-hover-border-color)
--graupl-tabs-tab-toggle-selected-border-colorThe border colour of a selected tab toggle component.var(--graupl-tabs-tab-toggle-hover-border-color)
--graupl-tabs-tab-toggle-disabled-border-colorThe border colour of a disabled tab toggle component.var(--graupl-theme-active--primary--200)
--graupl-tabs-tab-toggle-transformThe transform applied to the tab toggle component.none
--graupl-tabs-tab-toggle-visited-transformThe transform applied to a visited tab toggle component.var(--graupl-tabs-tab-toggle-transform)
--graupl-tabs-tab-toggle-focus-transformThe transform applied to a focused tab toggle component.var(--graupl-tabs-tab-toggle-transform)
--graupl-tabs-tab-toggle-hover-transformThe transform applied to a hovered tab toggle component.var(--graupl-tabs-tab-toggle-transform)
--graupl-tabs-tab-toggle-active-transformThe transform applied to an active tab toggle component.none
--graupl-tabs-tab-toggle-selected-transformThe transform applied to a selected tab toggle component.none
--graupl-tabs-tab-toggle-disabled-transformThe transform applied to a disabled tab toggle component.none
--graupl-tabs-tab-content-padding-xThe horizontal padding of the tab content component.var(--graupl-spacer-3)
--graupl-tabs-tab-content-padding-yThe vertical padding of the tab content component.var(--graupl-spacer-3)
--graupl-tabs-tab-content-paddingThe padding of the tab content component (combines y and x padding).var(--graupl-tabs-tab-content-padding-y) var(--graupl-tabs-tab-content-padding-x)
--graupl-tabs-tab-content-backgroundThe background colour of the tab content component.var(--graupl-tabs-background)
--graupl-tabs-tab-content-colorThe text colour of the tab content component.var(--graupl-tabs-color)
--graupl-tabs-tab-content-border-colorThe border colour of the tab content component.var(--graupl-tabs-border-color)
--graupl-tabs-tab-content-border-top-left-radiusThe top left border radius of the tab content component.var(--graupl-border-top-left-radius)
--graupl-tabs-tab-content-border-top-right-radiusThe top right border radius of the tab content component.var(--graupl-border-top-right-radius)
--graupl-tabs-tab-content-border-bottom-right-radiusThe bottom right border radius of the tab content component.var(--graupl-border-bottom-right-radius)
--graupl-tabs-tab-content-border-bottom-left-radiusThe bottom left border radius of the tab content component.var(--graupl-border-bottom-left-radius)
--graupl-tabs-tab-content-border-radiusThe border radius of the tab content component.var(--graupl-tabs-tab-content-border-top-left-radius) var(--graupl-tabs-tab-content-border-top-right-radius) var(--graupl-tabs-tab-content-border-bottom-right-radius) var(--graupl-tabs-tab-content-border-bottom-left-radius)
--graupl-tabs-tab-content-border-top-widthThe top border width of the tab content component.var(--graupl-border-top-width)
--graupl-tabs-tab-content-border-right-widthThe right border width of the tab content component.var(--graupl-border-right-width)
--graupl-tabs-tab-content-border-bottom-widthThe bottom border width of the tab content component.var(--graupl-border-bottom-width)
--graupl-tabs-tab-content-border-left-widthThe left border width of the tab content component.var(--graupl-border-left-width)
--graupl-tabs-tab-content-border-widthThe border width of the tab content component (combines top, right, bottom, and left widths).var(--graupl-tabs-tab-content-border-top-width) var(--graupl-tabs-tab-content-border-right-width) var(--graupl-tabs-tab-content-border-bottom-width) var(--graupl-tabs-tab-content-border-left-width)
--graupl-tabs-tab-content-border-top-styleThe top border style of the tab content component.var(--graupl-border-top-style)
--graupl-tabs-tab-content-border-right-styleThe right border style of the tab content component.var(--graupl-border-right-style)
--graupl-tabs-tab-content-border-bottom-styleThe bottom border style of the tab content component.var(--graupl-border-bottom-style)
--graupl-tabs-tab-content-border-left-styleThe left border style of the tab content component.var(--graupl-border-left-style)
--graupl-tabs-tab-content-border-styleThe border style of the tab content component (combines top, right, bottom, and left styles).var(--graupl-tabs-tab-content-border-top-style) var(--graupl-tabs-tab-content-border-right-style) var(--graupl-tabs-tab-content-border-bottom-style) var(--graupl-tabs-tab-content-border-left-style)
--graupl-tabs-tab-content-show-displayThe display value for tab content when shown.block
--graupl-tabs-tab-content-hide-displayThe display value for tab content when hidden.none
--graupl-tabs-tab-content-transitioning-displayThe display value for tab content while transitioning.block
--graupl-tabs-tab-content-displayThe display value for tab content.none
--graupl-tabs-tab-content-show-opacityThe opacity value for tab content when shown.1
--graupl-tabs-tab-content-hide-opacityThe opacity value for tab content when hidden.0
--graupl-tabs-tab-content-transitioning-opacityThe opacity value for tab content while transitioning.0
--graupl-tabs-tab-content-opacityThe opacity value for tab content.var(--graupl-tabs-tab-content-hide-opacity)
--graupl-tabs-transition-durationThe transition duration for tab content.var(--graupl-transition-duration-fast)
--graupl-tabs-tab-content-transition-timing-functionThe transition timing function for tab content.var(--graupl-transition-timing-function)
--graupl-tabs-tab-content-transitionThe transition for tab content changes.opacity var(--graupl-tabs-transition-duration) var(--graupl-tabs-tab-content-transition-timing-function)
--graupl-tabs-tab-content-transition-reduced-motionThe transition for tab content changes when reduced motion is enabled.opacity var(--graupl-tabs-transition-duration) var(--graupl-tabs-tab-content-transition-timing-function)

Sass variables ​

The following Sass variables can be used to customize the generation of the tabs component.

VariableDescriptionDefault Value
$selector-baseThe selector base for the component."."
$modifier-selector-baseThe selector base for component modifiers."."
$generate-base-theme-mapA flag to generate the base theme maps for tabs variants.true
$themeableA flag that determines whether theme modifiers are generated.false
$tabs-selector-baseThe selector base for the tabs component."."
$tabs-selectorThe tabs component selector."tabs"
$tabs-tab-list-selector-baseThe selector base for the tabs list component."."
$tabs-tab-list-selectorThe tab list component selector."tab-list"
$tabs-tab-toggle-selector-baseThe selector base for the individual tab toggle component."."
$tabs-tab-toggle-selectorThe individual tab toggle component selector."tab-toggle"
$tabs-tab-content-selector-baseThe selector base for the individual tab content component."."
$tabs-tab-content-selectorThe individual tab content component selector."tab-content"
$tabs-theme-selector-baseThe selector base for the tabs theme component modifiers."."
$tabs-theme-selector-prefixThe tabs theme component modifier selector prefix.""
$tabs-tab-content-open-selector-baseThe selector base applied to the open modifier."."
$tabs-tab-content-open-selectorThe selector applied to the open modifier."show"
$tabs-tab-content-closed-selector-baseThe selector base applied to the closed modifier."."
$tabs-tab-content-closed-selectorThe selector applied to the closed modifier."hide"
$tabs-tab-content-transitioning-selector-baseThe selector base applied to the transitioning modifier."."
$tabs-tab-content-transitioning-selectorThe selector applied to the transitioning modifier."transitioning"
$tabs-tab-content-show-displayThe default display value for open tab contents.block
$tabs-tab-content-hide-displayThe default display value for closed tab contents.none
$tabs-tab-content-transitioning-displayThe default display value for transitioning tab contents.block
$tabs-tab-content-show-opacityThe default opacity value for open tab contents.1
$tabs-tab-content-hide-opacityThe default opacity value for closed tab contents.0
$tabs-tab-content-transitioning-opacityThe default opacity value for transitioning tab contents.0
$tabs-tab-toggle-initial-transformThe initial transform of the tab toggle component.none
$tabs-tab-toggle-final-transformThe final transform of the tab toggle component.none
$tabs-tab-toggle-disabled-transformThe disabled transform of the tab toggle component.none
$tabs-theme-mappingsA map of properties and color shades used generate all tabs variants.map.merge($-tabs-theme-mappings, $tabs-theme-mappings)
$tabs-theme-mapA map of all properties, colors, and color shades used to generate all tabs variants.map.deep-merge($-tabs-theme-map, $tabs-theme-map)

JavaScript options ​

Pass constructor settings in the generator’s options object. The generator initializes each instance by default. When calling the Tabs constructor directly, initialize defaults to false.

Property NameDescriptionDefault Value
contextThe element that scopes the selector when locating tabs.document
selectorThe selector used to find tabs in the DOM..tabs
optionsAn object of options passed through to the Tabs constructor (see below).{}
options.tabListSelectorThe selector for the tab list element..tab-list
options.tabTogglesSelectorThe selector for tab toggle elements..tab-toggle
options.tabContentsSelectorThe selector for tab content elements..tab-content
options.expandClassThe class(es) applied when a tab is open.show
options.collapseClassThe class(es) applied when a tab is closed.hide
options.transitionClassThe class(es) applied while a tab is transitioning.null
options.transitionDurationDuration (ms) for transitions between open/closed states.300
options.expandDurationDuration (ms) for closed → open; -1 uses transitionDuration.-1
options.collapseDurationDuration (ms) for open → closed; -1 uses transitionDuration.-1
options.automaticActivationWhen true, focusing a tab toggle also activates it.false
options.prefixPrefix for generated CSS custom properties.graupl-
options.keyKey used when generating IDs; null auto-generates a random key.null
options.initializeClassThe class applied while the tabs are initializing.initializing
options.initializeWhen true, initializes the tabs immediately on creation.true when using the generator