feat: add persistent active tab tracking to actor sheet
This commit is contained in:
parent
df8c94a21f
commit
bcc263cc5e
1 changed files with 24 additions and 10 deletions
|
@ -48,6 +48,11 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 {
|
||||||
|
|
||||||
static TABS = {};
|
static TABS = {};
|
||||||
|
|
||||||
|
constructor(options = {}) {
|
||||||
|
super(options);
|
||||||
|
this.activeTab = "values"; // Default active tab
|
||||||
|
}
|
||||||
|
|
||||||
get title() {
|
get title() {
|
||||||
return `${this.document.name} [${game.i18n.localize("DS4.ActorSheet")}]`;
|
return `${this.document.name} [${game.i18n.localize("DS4.ActorSheet")}]`;
|
||||||
}
|
}
|
||||||
|
@ -502,6 +507,9 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 {
|
||||||
const tab = target.dataset.tab;
|
const tab = target.dataset.tab;
|
||||||
if (!tab) return;
|
if (!tab) return;
|
||||||
|
|
||||||
|
// Store the active tab
|
||||||
|
this.activeTab = tab;
|
||||||
|
|
||||||
// Find tab navigation elements
|
// Find tab navigation elements
|
||||||
const nav = target.closest(".ds4-sheet-tab-nav");
|
const nav = target.closest(".ds4-sheet-tab-nav");
|
||||||
const sheet = this.element.querySelector(".ds4-sheet-body");
|
const sheet = this.element.querySelector(".ds4-sheet-body");
|
||||||
|
@ -552,19 +560,25 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 {
|
||||||
navItems.forEach(item => item.classList.remove("active"));
|
navItems.forEach(item => item.classList.remove("active"));
|
||||||
tabContents.forEach(content => content.classList.remove("active"));
|
tabContents.forEach(content => content.classList.remove("active"));
|
||||||
|
|
||||||
// Set first tab navigation as active
|
// Find the currently active tab or default to first
|
||||||
const firstNavItem = navItems[0];
|
let targetTab = this.activeTab;
|
||||||
if (firstNavItem) {
|
let targetNavItem = nav.querySelector(`[data-tab="${targetTab}"]`);
|
||||||
firstNavItem.classList.add("active");
|
|
||||||
|
// If stored tab doesn't exist, fall back to first tab
|
||||||
|
if (!targetNavItem) {
|
||||||
|
targetNavItem = navItems[0];
|
||||||
|
targetTab = targetNavItem?.dataset.tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set target tab navigation as active
|
||||||
|
if (targetNavItem && targetTab) {
|
||||||
|
targetNavItem.classList.add("active");
|
||||||
|
|
||||||
// Set corresponding tab content as active
|
// Set corresponding tab content as active
|
||||||
const firstTab = firstNavItem.dataset.tab;
|
const activeTabContent = sheet.querySelector(`.ds4-sheet-tab[data-tab="${targetTab}"]`);
|
||||||
if (firstTab) {
|
|
||||||
const activeTabContent = sheet.querySelector(`.ds4-sheet-tab[data-tab="${firstTab}"]`);
|
|
||||||
if (activeTabContent) {
|
if (activeTabContent) {
|
||||||
activeTabContent.classList.add("active");
|
activeTabContent.classList.add("active");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue