Last modified: Dec 16, 2024

Tabs

A component that allows you to organise and switch between different content in tabs.

🚧 This documentation is a work in progress.

Usage

The Tabs component allows you to organise and switch between different content sections by clicking on the header, allowing for a space-efficient and organized way to present information.

Anatomy

Tab active anatomy
Tab anatomy

  1. Header: The clickable section title that users interact with to select or switch the content.
  2. Content Area: The area that is revealing or hiding information when the header is clicked.

Properties

PropertyTypeDescription
idstringUnique ID string for the component.
sizestringSets the size of the tabs. Enum:: "small" | "medium" | "large"
Default: medium.
defaultTabstringConfiguring a tab to be selected by default.
tabsArrayA list of tab objects containing the config(id, title, icon, children) for each tab.
tabs.idstringUnique ID of the tab in question.
tabs.titlestringThe title for the tab in question.
tabs.iconstringAn URL to the icon for the tab in question.
tabs.childrenArrayThe content of the tab in question.

Configuration

Add component

{
 "data": {
    "layout": [
    {
        "id": "tabs",
        "type": "Tabs",
        "tabs": [
         {
           "id": "tab-1",
           "children": ["test-tab-paragraph"],
           "title": "Tab 1",
           "icon": "/ttd/frontend-test/images/altinn-logo.svg"
         },
         {
           "id": "tab-2",
           "children": ["test-tab-paragraph2"],
           "title": "Tab 2"
         }
       ]
    },
  ]
 }
}

defaultTab

The ID of the specific tab that you wish to be selected by default.

Tabs

id

A string identifier for the tab. Must be unique within the current list of tabs.

title

The title of the tab can be added as text directly or referenced via a text key to a text resource.

Size

Sets the size of the tabs. Enum: "small" | "medium" | "large"
Default: medium.

icon

A URL path to the icon.

children

Defines the components to display when a tab is active by adding their IDs to an array under the children property.


Example

Tabs with paragraphs as child elements.

    {
     "data": {
        "layout": [
        {
            "id": "tabs",
            "type": "Tabs",
            "tabs": [
             {
               "id": "tab-1",
               "children": ["test-tab-paragraph"],
               "title": "Tab 1",
               "icon": "/ttd/frontend-test/images/altinn-logo.svg"
             },
             {
               "id": "tab-2",
               "children": ["test-tab-paragraph2"],
               "title": "Tab 2"
             }
           ]
        },
      ]
     }
    }
    

    Tabs example
    Tabs with two tabs