Skip to main content

Configuration

Close buttons for tabs​

Tabbar with a close button next to each tab and the active Paris tab in DHTMLX Suite

Related sample: Tabbar. Close button

The closable property adds close buttons to tabs. Users can click a close button to close the tab. Set the property to true to add close buttons to all tabs:

const tabbar = new dhx.Tabbar("tabbar_container", {
closable: true
});

To add close buttons only to specific tabs, set the closable property to an array of tab ids:

const tabbar = new dhx.Tabbar("tabbar_container", {
closable: ["paris", "london"]
});

Disabled tabs​

Tabbar with grayed out disabled Paris and Rome tabs and active London tab in DHTMLX Suite

If you don't set the disabled property, all tabs are enabled. Set the property to disable one or several tabs:

// make one tab disabled
const tabbar = new dhx.Tabbar("tabbar_container", {
disabled: "London"
});

// make several tabs disabled
const tabbar = new dhx.Tabbar("tabbar_container", {
disabled: ["Paris", "Rome"]
});

Related sample: Tabbar. Rich configuration (close, disable, overflow, active tab)

Position of tabbar​

Tabbar in left mode with tabs stacked vertically beside the content in DHTMLX Suite

Related sample: Tabbar. Mode: top, left, right, bottom

The mode property sets the side of Tabbar where tabs appear. The default value is "top". You can also set the property to "bottom", "left", or "right":

const tabbar = new dhx.Tabbar("tabbar_container", {
mode: "left"
});

Size of tabs​

The tabWidth and tabHeight properties set the width and height of tabs. The default width is 200px, and the default height is 45px. Set the properties to change the default tab size:

const tabbar = new dhx.Tabbar("tabbar_container", {
tabWidth: 190,
tabHeight: 50
});

Related sample: Tabbar. Tab size

Structure of tabs​

Define the structure of Tabbar in the views property when you initialize the component. Each tab is an object that can include the following properties:

  • id — the id of a tab
  • tab — the name of a tab
  • tabCss — the name of the CSS class used for a tab
  • css — the name of the CSS class used for a cell
  • header — the header of a cell
  • html — HTML content of a cell
  • padding — the distance between the content of a cell and the border of tabbar
  • tabWidth — the width of a tab (for more information, see views)
  • tabHeight — the height of a tab (for more information, see views)
const tabbar = new dhx.Tabbar("tabbar_container", {
views: [
{ tab: "left", css: "panel flex", header: "Left" },
{ tab: "west", css: "panel flex", header: "West" },
{ tab: "east", css: "panel flex", header: "East" },
{ tab: "right", css: "panel flex", header: "Right" }
]
});

Related sample: Tabbar. Tab size

HTML content in tab titles​

Tabbar with icons and temperature badges in tab titles in DHTMLX Suite

Use the tabTemplate option to render HTML content in tab titles, for example, an icon next to the tab name. The option is a callback function that defines the template for the titles of all tabs.

Tabbar calls the function for each tab with the following parameters:

  • cell — (object) the configuration object of the current tab (id, tab, html, and other tab properties)
  • activeTab — (string) the id of the active tab

The function returns an HTML string, and Tabbar inserts it into the DOM of the tab:

<script>
const tabbar = new dhx.Tabbar("tabbar_container", {
mode: "top",
css: "dhx_widget--bordered",
tabTemplate: (cell, activeTab) => {
const isActive = cell.id === activeTab;
return `
<i class="icon icon-${cell.icon}"></i>
<span class="${isActive ? "tab-title tab-title--active" : "tab-title"}">${cell.tab}</span>
`;
},
views: [
{ id: "vilnius", tab: "Vilnius", icon: "cloud", html: "..." },
{ id: "paris", tab: "Paris", icon: "sun", html: "..." },
{ id: "london", tab: "London", icon: "rain", html: "..." },
{ id: "rome", tab: "Rome", icon: "sun", html: "..." }
]
});
</script>

Without the tabTemplate option, Tabbar renders each tab as plain text. The tab property of a tab is always a string, and Tabbar never interprets it as HTML, whether you use tabTemplate or not. If you set tabTemplate, your function controls the rendering of all tabs and builds their entire markup.

Related sample: Tabbar. Tab with HTML template

Autosize for tabs​

If you don't set the width or height of tabs, you can make the tabs adjust automatically to the size of the Tabbar container. Set the tabAutoWidth or tabAutoHeight property to true:

const tabbar = new dhx.Tabbar("tabbar_container", {
views: [
{ tab: "left", css: "panel flex", header: "Left" },
{ tab: "west", css: "panel flex", header: "West" },
{ tab: "east", css: "panel flex", header: "East" },
{ tab: "right", css: "panel flex", header: "Right" }
],
tabAutoWidth: true,
mode: "top"
});

Related sample: Tabbar. Tab auto width

Related sample: Tabbar. Tab auto height

note

The tabAutoWidth option takes effect when mode is "top" or "bottom". The tabAutoHeight option takes effect when mode is "left" or "right".

Tabs without content​

Tabbar rendered with tabs only and an empty content area below in DHTMLX Suite

Set the noContent option to true to render tabs without content:

const tabbar = new dhx.Tabbar("tabbar_container", {
noContent: true
});

Related sample: Tabbar. Without content

Alignment​

Tabbar with center aligned tabs and the active VILNIUS tab showing content in DHTMLX Suite

From v7.0, you can align tabs with the tabAlign option:

const tabbar = new dhx.Tabbar("tabbar_container", {
views: [
{ tab: "left", css: "panel flex", header: "Left" },
{ tab: "west", css: "panel flex", header: "West" },
{ tab: "east", css: "panel flex", header: "East" },
{ tab: "right", css: "panel flex", header: "Right" }
],
tabAlign: "center"
});

Related sample: Tabbar. Tab align

The option takes the following values: "left" or "start", "center" or "middle", and "right" or "end".