SettingGroup
Mock of Obsidian’s SettingGroup, which groups setting rows under an optional heading.
The DOM mirrors Obsidian’s: SettingGroup.groupEl holds a search container (.setting-group-search), SettingGroup.listEl, and a heading row (a name and SettingGroup.controlEl) that is attached at the top of the group only while it has a heading or a control. Every added row or control is handed to its callback synchronously.
Import:
import { SettingGroup } from 'obsidian-test-mocks/obsidian';Signature:
export class SettingGroupConstructor
new SettingGroup(containerEl: HTMLElement)Creates the group inside containerEl, without a heading.
Properties
| Property | Type | Description |
|---|---|---|
| components | BaseComponent[] | The components added to the group itself (its search input and extra buttons), in the order they were added. |
| controlEl | HTMLDivElement | The element in the heading row that holds the group's extra buttons. |
| groupEl | HTMLDivElement | The group's outer element, holding the heading, the search container and the list. |
| listEl | HTMLDivElement | The element the group's settings are added to. |
| settings | Setting[] | The setting rows added with SettingGroup.addSetting, in order. |
Methods
| Method | Returns | Description |
|---|---|---|
| addClass(classes?) | this | Adds CSS classes to the group's outer element. |
| addExtraButton(callback) | this | Adds an extra (icon) button to the group's heading row, attaching the heading row if it is not already shown. |
| addSearch(callback) | this | Adds a search input to the group's search container, at the start of the group, for filtering its rows or for quick entry. |
| addSetting(callback) | this | Adds a setting row to the group's list. |
| asOriginalType__() | SettingGroupOriginal | Mock-only: views this mock as Obsidian's SettingGroup type. |
| constructor__(_containerEl) | void | Mock-only construction hook, called at the end of the constructor; a no-op meant for vi.spyOn(SettingGroup.prototype, 'constructor__'). |
| setHeading(text) | this | Sets the group's heading. The heading row is attached at the top of SettingGroup.groupEl while the heading is non-empty or SettingGroup.controlEl holds a control, and detached otherwise. Obsidian tests whether the heading row is shown with isShown(), which is always false without layout, so the mock tests whether the row is attached instead. |
| static create__(containerEl) | SettingGroup | Mock-only factory: creates a setting group, spyable via vi.spyOn(SettingGroup, 'create__'). |
| static fromOriginalType__(value) | SettingGroup | Mock-only: views a value typed as Obsidian's SettingGroup as this mock. |