Skip to content

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 SettingsTabs

Constructor

new SettingsTabs(containerEl: HTMLElement)

Creates new settings tabs.

Properties

PropertyTypeDescription
panelElHTMLElementThe panel the selected tab renders into.
tabBarElHTMLElementThe row of tab buttons.

Methods

MethodReturnsDescription
addTab(tab)thisAdds a tab. The first tab added is selected.
getSelectedTabId()null | stringGets the id of the selected tab.
onTabChange(callback)thisSets the callback to be called when the user selects another tab.
selectTab(tabId)thisSelects 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: