Overview

Displays tabs:

This component is the most straightforward way to implement tabs. Its usage is recommended whenever possible.

Basic usage

Tab panels' content is passed via slots named by corresponding tabs' IDs from objects of the tabs array.

Each tabbed interface needs to have ariaLabel or ariaLabelledBy and also an identifier, tabsID, that is unique in regard to a page where tabs are rendered.


      <KTabs
        tabsId="coachReportsTabs"
        ariaLabel="Coach reports"
        :tabs="tabs"
      >
        <template #tabLessons> Lessons tab content </template>
        <template #tabLearners> Learners tab content </template>
        <template #tabGroups> Groups tab content </template>
      </KTabs>
    

      data() {
        return {
          tabs: [
            { id: 'tabLessons', label: 'Lessons' },
            { id: 'tabLearners', label: 'Learners' },
            { id: 'tabGroups', label: 'Groups' },
          ],
        };
      },
    

With router

When implementing tabs with the router, it's the router view rather than KTabs that is responsible for displaying the active tab content.

In such a case, define to property with a router link object as its value in objects of the tabs array:


      data() {
        return {
          tabs: [
            { id: 'tabLessons', label: 'Lessons', to: { path: '/lessons' } },
            { id: 'tabLearners', label: 'Learners', to: { path: '/learners' } },
            { id: 'tabGroups', label: 'Groups', to: { path: '/groups' } },
          ],
        };
      },
    

Then, tabs will be rendered as router links and you can use the router view to display the active tab content:


      <KTabs
        tabsId="coachReportsTabs"
        ariaLabel="Coach reports"
        :tabs="tabs"
      >
        <router-view />
      </KTabs>
    

Note that here, tabs content is not passed to KTabs via named slots, for it's the router view that's responsible for rendering it.

However, it is still required to wrap the active tab content in KTabs. Otherwise, even though tabs may seem to function correctly at first glance, accessibility would be broken.

Do

          <KTabs
            tabsId="coachReportsTabs"
            ariaLabel="Coach reports"
            :tabs="tabs"
          >
            <!-- the active tab content is displayed in this router view -->
            <router-view />
          </KTabs>
        

Place the router view to KTabs default slot

Don't

          <KTabs
            tabsId="coachReportsTabs"
            ariaLabel="Coach reports"
            :tabs="tabs"
          />
          <!-- the active tab content is displayed in this router view -->
          <router-view />
        

Place the router view outside of KTabs

More tabs on a page

When there are two or more tabbed interfaces on one page, it is important to identify each one of them with an ID unique in regard to the page. Otherwise, some a11y features may break.

This is achieved by providing a unique value to tabsId property:


      <KTabs tabsId="firstTabs" />
      <KTabs tabsId="secondTabs" />
    

Appearance

There are several ways to adjust tabs styling. You can refer to the props and slots overview below and also to KTabsList: Appearance to see examples as KTabsList accepts exactly the same styling props and slots.

Related

Props

Name Description Type Default Required
tabs
An array of tab objects { id, label, to } where id and label properties are required and to is optional. When to is provided, tabs render as router links. Otherwise, they render as buttons.
array true
ariaLabel
A label that describes the purpose of the set of tabs. Providing either ariaLabel or ariaLabelledBy is required.
string ''
ariaLabelledBy
ID reference to a DOM element which provides a label that describes the purpose of the set of tabs. Providing either ariaLabel or ariaLabelledBy is required.
string ''
color
Tabs text color. Defaults to $themeTokens.annotation.
string null
colorActive
Text color of an active tab. Defaults to $themeTokens.primary.
string null
backgroundColor
Tabs background color. Defaults to $themeTokens.surface.
string null
hoverBackgroundColor
Tabs hover background color. Defaults to $themeBrand.primary.v_100.
string null
appearanceOverrides
Tabs styles that complement or override default styles or styles defined via props (will be sent to $computedClass, which means that styles that are accepted by $computedClass, e.g. pseudo-classes, are supported)
object null
appearanceOverridesActive
An active tab styles that complement or override default styles or styles defined via props (will be sent to $computedClass, which means that styles that are accepted by $computedClass, e.g. pseudo-classes, are supported)
object null
enablePrint
Tab list items are hidden when printing by default. enablePrint set to true makes them visible in print mode.
boolean false
tabsId
An ID of a tabbed interface represented by this component. Needs to be be unique in regards to all tabbed interfaces rendered on one page.
string true

Events

Name Description
error
Emitted with an error when a misconfiguration error occurs, if a listener is attached

Slots

Name Description
tab
Optional slot for tab labels. Exposes tab object and isActive boolean.
default
An alternative to using slots named by tabs' IDs.
slot