Skip to content

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 SettingGroup

Constructor

new SettingGroup(containerEl: HTMLElement)

Creates the group inside containerEl, without a heading.

Properties

PropertyTypeDescription
componentsBaseComponent[]The components added to the group itself (its search input and extra buttons), in the order they were added.
controlElHTMLDivElementThe element in the heading row that holds the group's extra buttons.
groupElHTMLDivElementThe group's outer element, holding the heading, the search container and the list.
listElHTMLDivElementThe element the group's settings are added to.
settingsSetting[]The setting rows added with SettingGroup.addSetting, in order.

Methods

MethodReturnsDescription
addClass(classes?)thisAdds CSS classes to the group's outer element.
addExtraButton(callback)thisAdds an extra (icon) button to the group's heading row, attaching the heading row if it is not already shown.
addSearch(callback)thisAdds 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)thisAdds a setting row to the group's list.
asOriginalType__()SettingGroupOriginalMock-only: views this mock as Obsidian's SettingGroup type.
constructor__(_containerEl)voidMock-only construction hook, called at the end of the constructor; a no-op meant for vi.spyOn(SettingGroup.prototype, 'constructor__').
setHeading(text)thisSets 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)SettingGroupMock-only factory: creates a setting group, spyable via vi.spyOn(SettingGroup, 'create__').
static fromOriginalType__(value)SettingGroupMock-only: views a value typed as Obsidian's SettingGroup as this mock.