@rogieking/figui3 6.6.0 → 6.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fig.js +16 -16
- package/fig.js +29 -4
- package/package.json +1 -1
package/fig.js
CHANGED
|
@@ -3453,26 +3453,45 @@ class FigTabs extends HTMLElement {
|
|
|
3453
3453
|
this.querySelectorAll("fig-tab").forEach((tab) => tab.removeAttribute("selected"));
|
|
3454
3454
|
this.selectedTab = tabs[newIndex];
|
|
3455
3455
|
tabs[newIndex].setAttribute("selected", "true");
|
|
3456
|
-
const val = tabs[newIndex]
|
|
3456
|
+
const val = this.#resolveTabValue(tabs[newIndex]);
|
|
3457
3457
|
if (val) this.setAttribute("value", val);
|
|
3458
|
+
else this.removeAttribute("value");
|
|
3458
3459
|
tabs[newIndex].focus();
|
|
3459
3460
|
this.#syncTabIndexes();
|
|
3460
3461
|
this.#scrollSelectedTabIntoView(tabs[newIndex]);
|
|
3462
|
+
this.#emitSelectionEvents();
|
|
3461
3463
|
}
|
|
3462
3464
|
}
|
|
3463
3465
|
|
|
3464
3466
|
get value() {
|
|
3465
|
-
return this.selectedTab
|
|
3467
|
+
return this.#resolveTabValue(this.selectedTab);
|
|
3466
3468
|
}
|
|
3467
3469
|
|
|
3468
3470
|
set value(val) {
|
|
3469
3471
|
this.setAttribute("value", val);
|
|
3470
3472
|
}
|
|
3471
3473
|
|
|
3474
|
+
#emitSelectionEvents() {
|
|
3475
|
+
const val = this.value;
|
|
3476
|
+
this.dispatchEvent(
|
|
3477
|
+
new CustomEvent("input", { detail: val, bubbles: true }),
|
|
3478
|
+
);
|
|
3479
|
+
this.dispatchEvent(
|
|
3480
|
+
new CustomEvent("change", { detail: val, bubbles: true }),
|
|
3481
|
+
);
|
|
3482
|
+
}
|
|
3483
|
+
|
|
3484
|
+
#resolveTabValue(tab) {
|
|
3485
|
+
if (!tab) return "";
|
|
3486
|
+
const attrValue = tab.getAttribute("value");
|
|
3487
|
+
if (attrValue !== null) return attrValue;
|
|
3488
|
+
return tab.textContent?.trim() || "";
|
|
3489
|
+
}
|
|
3490
|
+
|
|
3472
3491
|
#selectByValue(value) {
|
|
3473
3492
|
const tabs = this.querySelectorAll("fig-tab");
|
|
3474
3493
|
for (const tab of tabs) {
|
|
3475
|
-
if (tab
|
|
3494
|
+
if (this.#resolveTabValue(tab) === value) {
|
|
3476
3495
|
this.selectedTab = tab;
|
|
3477
3496
|
tab.setAttribute("selected", "true");
|
|
3478
3497
|
} else {
|
|
@@ -3500,6 +3519,8 @@ class FigTabs extends HTMLElement {
|
|
|
3500
3519
|
if (this.hasAttribute("disabled")) return;
|
|
3501
3520
|
const target = event.target.closest("fig-tab");
|
|
3502
3521
|
if (!target || !this.contains(target)) return;
|
|
3522
|
+
const previousTab = this.selectedTab;
|
|
3523
|
+
const previousValue = this.value;
|
|
3503
3524
|
const tabs = this.querySelectorAll("fig-tab");
|
|
3504
3525
|
for (const tab of tabs) {
|
|
3505
3526
|
if (tab === target) {
|
|
@@ -3509,10 +3530,14 @@ class FigTabs extends HTMLElement {
|
|
|
3509
3530
|
tab.removeAttribute("selected");
|
|
3510
3531
|
}
|
|
3511
3532
|
}
|
|
3512
|
-
const val = target
|
|
3533
|
+
const val = this.#resolveTabValue(target);
|
|
3513
3534
|
if (val) this.setAttribute("value", val);
|
|
3535
|
+
else this.removeAttribute("value");
|
|
3514
3536
|
this.#syncTabIndexes();
|
|
3515
3537
|
this.#scrollSelectedTabIntoView(target);
|
|
3538
|
+
if (previousTab !== target || previousValue !== this.value) {
|
|
3539
|
+
this.#emitSelectionEvents();
|
|
3540
|
+
}
|
|
3516
3541
|
}
|
|
3517
3542
|
}
|
|
3518
3543
|
customElements.define("fig-tabs", FigTabs);
|
package/package.json
CHANGED