Tabs β
Tabs consist of two or more tab items created for navigating between different sections of content.
Name | Value |
---|---|
Props | |
framed | |
View | |
Reading direction |
Overview β
When to use Tabs β
Use Tabs to navigate between different sections of content on the page. For filtering information on the screen or switching between views, use a ToggleButtonGroup instead. Tabs can be visually styled as framed or quiet (by default). Framed Tabs should only be used when appearing within a box or module.
Avoid using Tabs to structure content meant to be consumed sequentially, like the sections within an article page.
About Tabs β
The Tabs component always contains two or more Tab items. Each Tab will display different sections within the same context. For example, Tabs can display different edit views or topics.
Tabs includes the following elements.
Selected tab β
Within the Tabs component, only one tab item can be selected at a time.
Unselected tab β
The remaining tab items will remain unselected. Users can choose these tabs by clicking on them or navigating to them via the keyboardβs arrow keys.
Scroll button(s) β
When there are many tab items or limited space, arrow buttons will appear to allow scrolling to all of the tab items.
Examples β
Header row scroll β
When the width of the header row exceeds the width of its container, arrow buttons will appear to enable scrolling through Tab items.
Content for tab1
This is the content for the First Tab
Technical implementation β
Vue usage β
One or more Tab components must be provided in the default slot of the Tabs component. Each child Tab component must have a name
property. By default, the first tab will be active when the component renders.
Optional 2-way binding of active tab β
Optionally, the active tab can be bound in the parent scope using v-model:active
. This is useful in situations where the Tabs need the ability to render with a Tab other than the first in the active state and is recommended if tabs are meant to respond to URL params. The value of v-model:active
should correspond to the name
property of the active tab.
Props β
Prop name | Description | Type | Default |
---|---|---|---|
active | The name of the currently active Tab in the layout.This prop is optional; if it is provided, it should be bound using a v-model:active directive in the parent component. Two-way binding the active tab is only necessary if some tab other than the first should be active as soon as the component renders (such as in cases where the active tab is bound to URL params). If this prop is not provided, then the first tab will be active by default. Regardless, the active tab can be changed normally by user interaction (clicking on tab headings) or by using the exposed methods "select", "next", and "prev". | string | null |
framed | Whether or not the component should be displayed in a framed visual style. | boolean | false |
Methods β
Method name | Description | Signature |
---|---|---|
select | Programmatically select a tab based on its "name" prop | Params:
void |
next | Set the next tab to active, if one exists | Params:
void |
prev | Set the previous tab to active, if one exists | Params:
void |
Events β
Event name | Properties | Description |
---|---|---|
update:active | active string - The name of the current active tab | Emitted whenever the active tab changes, assuming that an active prop has been provided in the parent. |
Slots β
Name | Description | Bindings |
---|---|---|
default | One or more Tab components must be provided here |
CSS-only version β
Markup structure β
The non-JS version of the Tabs component should be seen as a navigational tool. It relies on HTML form submission to trigger a change in the current active tab. When the user clicks on a tab button (or hits Enter while tab button is focused), the browser will load a new page.
Basic setup: β
- The outermost element should be a
<div>
element with the class"cdx-tabs"
. - The
cdx-tabs__header
element should be a<form>
with the following attributes:method="get"
: we will send the form with a GET requestaction="myURL"
: The value ofaction
should be whatever URL the form data will be sent to; in this example it's simply the same URL as the page, but appended with a different URL query parameter based on the user's tab selection. In a real-world use-case, this might be a URL that can accept query parameters (say for performing a different kind of search based on which tab the user selects).
- Within the
tablist
element, every tab label is represented by a<button>
element (this is the same as in the Vue version). However, since we are submitting the data as a form, each tab button must contain aname
and avalue
attribute. In a real application, this might correspond to key-value pairs used for a given query parameter. - The tab corresponding to the current view should contain the
aria-selected="true"
attribute. All other tabs should havearia-selected="false"
. If you are using a server-side templating language like Mustache, this should be set there. - Each tab should also have an
aria-controls
attribute with a value of the ID of the correspondingtabpanel
. - Don't mess with
<button>
tabindex
β since the CSS-only version of this component has no way to bind left and right arrow keys to handler methods, the user is going to need to rely on the mouse or the tab key to navigate between tabs. - To disable a tab, simply add a
disabled
attribute to that tab's<button>
in the tablist.
The Tabs below have long labels, making the tab list too long for its container. When this happens, you can horizontally scroll to reach the rest of the Tabs list.
WARNING
Keyboard navigation between tabs can only be done via the tab key. Arrow keys will not work here.
Keyboard navigation β
Key | Function |
---|---|
Tab | It moves the focus to the next interactive element in tab order. |
Shift + Tab | It moves the focus to the previous interactive element. |
Left arrow / Right arrow | When focusing on a Tab item, the arrow keys navigate between the rest of Tab items. |