SettingsTabs
Tabbed sections inside a plugin’s settings: a row of tab buttons and one panel, which renders only the selected tab. The arrow keys, Home and End move between tabs, as in the WAI-ARIA tabs pattern.
public override display(): void { this.containerEl.empty(); new SettingsTabs(this.containerEl) .addTab({ id: 'general', name: 'General', render: (el) => this.renderGeneral(el) }) .addTab({ id: 'advanced', name: 'Advanced', render: (el) => this.renderAdvanced(el) }) .selectTab(this.lastTabId) .onTabChange((tabId) => { this.lastTabId = tabId; });}In order to add the styles for the component, use initPluginContext in your plugin’s onload() function.
Alternatively, you can copy styles from https://unpkg.com/@mnaoumov/obsidian-lib/dist/styles.css.
Import:
import { SettingsTabs } from '@mnaoumov/obsidian-lib/settings-tabs';Signature:
export class SettingsTabsConstructor
new SettingsTabs(containerEl: HTMLElement)Creates new settings tabs.
Properties
| Property | Type | Description |
|---|---|---|
| panelEl | HTMLElement | The panel the selected tab renders into. |
| tabBarEl | HTMLElement | The row of tab buttons. |
Methods
| Method | Returns | Description |
|---|---|---|
| addTab(tab) | this | Adds a tab. The first tab added is selected. |
| getSelectedTabId() | null | string | Gets the id of the selected tab. |
| onTabChange(callback) | this | Sets the callback to be called when the user selects another tab. |
| selectTab(tabId) | this | Selects a tab and renders it into the panel. An unknown id, such as a stored id whose tab was since removed, leaves the selection as it is. |
Links to this page: