Tabs
Tabs allow users to explore multiple views of a related data set.
Default Example
Variations
- Default Example (shown above)
- Icon Example
- Double Line Example
Usage
- Tabs appear horizontally. They are never stacked and do not wrap to a second line.
- Tabs have a minimum and maximum width. Labels truncate when necessary.
- Labels are left aligned.
- Display contextual icons to the left of the label. The right side of a tab is reserved for closing and dragging mechanisms.
- While there is not a specific limit to the number of tabs that can occur in a given set, try to group tabbed content into a reasonable number of tabs to make it easy for users to find content and navigate between options.
- On Desktop, tabular navigation (left/right scrolling) occurs on the right side of the tab menu and any “adding tab” mechanism occurs on the right.
- On Mobile, there is no navigation. The entire tabular set is horizontally scrollable.
Variations
Default with Icon
Default Double Line
Developer Notes
A tabbed content container is created by adding a class of .spark-tabs to an element. Inside of this element are two main wrapping elements: .spark-tabs__nav and .spark-tabs__panels.
The navigation element should have role="menubar" as an ARIA attribute. To properly allow for scrolling of the list of tabs, inside the navigation element should be an element with a class of .spark-tabs__scroll. Inside of the scroll container there should be a <ul> with a class of .spark-tabs__list and the role="tablist" ARIA attribute. The items of the list should have a class of .spark-tabs__tab and the role="tab" ARIA attribute. A tab with the class of .active will be highlighted. There should only be one active tab at a time.
Inside the navigation element there should be an element with a class of .spark-tabs__btns that contains buttons used to navigate left and right through the tab list.
The panels element contains a list of tab panels that correspond to tabs defined in the tab list above. By default, clicking on an element in the tab list with role="tab" will open an item with a corresponding index in the tab panels with role="tabpanel".
The tabs implementation relies on JavaScript to function fully. You must instantiate the tabs using either the jQuery plugin (var tabs = $('#tabs).sparkTabs();) or the native JavaScript implementation (var tabs = new Spark.Tabs(document.querySelector('#tabs));).
It is important to store a reference to the created instance if you want to programmatically set the active tab. This can be done by calling tabs.setActive(index);, tabs.setActive(element); or tabs.setActive(#id);.