Editor / DOM Helper / initTabs
Function: initTabs()
ts
function initTabs(params): void;Initializes a tab system with the provided configuration and handles tab switching behavior. This function creates a set of tabs and associates them with a specified container. It also sets an initial active tab and switches between tabs when a tab is clicked.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The configuration object to initialize the tabs. |
Returns
void
Example
ts
// Example usage of the initTabs function
const tabsConfig = {
targetId: 'myTabContainer',
tabsLabel: ['Tab 1', 'Tab 2', 'Tab 3'],
initialTab: 'Tab 2',
};
initTabs(tabsConfig);
// In the above example:
// - The tab container is identified by 'myTabContainer'.
// - Three tabs are created with the labels "Tab 1", "Tab 2", and "Tab 3".
// - The second tab ("Tab 2") is set as the initially active tab.Throws
Throws an error if the params.targetId is missing or invalid.
Throws
Throws an error if the params.tabsLabel is empty or not provided.
Throws
Throws an error if the params.initialTab does not match any label in tabsLabel.