mn-angular-lib 1.0.92 → 1.0.93
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.
|
@@ -8432,12 +8432,30 @@ class MnTabComponent {
|
|
|
8432
8432
|
(this.dataSource.items.length || DEFAULT_SKELETON_TAB_COUNT);
|
|
8433
8433
|
return Array.from({ length: count }, (_, index) => index);
|
|
8434
8434
|
}
|
|
8435
|
-
/**
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8435
|
+
/**
|
|
8436
|
+
* Re-resolves the active tab on every change-detection pass.
|
|
8437
|
+
*
|
|
8438
|
+
* The data source is often populated or rebuilt asynchronously (tabs that
|
|
8439
|
+
* depend on fetched data or permissions). Resolving the active tab only once
|
|
8440
|
+
* at init would leave {@link currentActive} pointing at a stale item — the
|
|
8441
|
+
* tab bar would then highlight nothing and swallow the first click — so the
|
|
8442
|
+
* selection is kept in sync with whatever the data source currently holds.
|
|
8443
|
+
*/
|
|
8444
|
+
ngDoCheck() {
|
|
8445
|
+
this.syncActiveTab();
|
|
8446
|
+
}
|
|
8447
|
+
/**
|
|
8448
|
+
* Sets the given tab item as active, invoking deactivate/activate callbacks.
|
|
8449
|
+
* @param item - The tab item to activate.
|
|
8450
|
+
*/
|
|
8451
|
+
setActive(item) {
|
|
8452
|
+
if (this.currentActive === item) {
|
|
8453
|
+
return;
|
|
8440
8454
|
}
|
|
8455
|
+
this.currentActive?.onDeactivate?.();
|
|
8456
|
+
item.onClick?.();
|
|
8457
|
+
this.currentActive = item;
|
|
8458
|
+
this.activeChange.emit(item);
|
|
8441
8459
|
}
|
|
8442
8460
|
/**
|
|
8443
8461
|
* Returns the resolved badge value for a tab item, supporting both plain numbers and Signal<number>.
|
|
@@ -8449,16 +8467,22 @@ class MnTabComponent {
|
|
|
8449
8467
|
return item.badge;
|
|
8450
8468
|
}
|
|
8451
8469
|
/**
|
|
8452
|
-
*
|
|
8453
|
-
*
|
|
8470
|
+
* Ensures {@link currentActive} references a tab that still exists in the data
|
|
8471
|
+
* source, falling back to the configured default tab when the current
|
|
8472
|
+
* selection is missing or stale (e.g. after the items array is replaced).
|
|
8454
8473
|
*/
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
|
|
8459
|
-
|
|
8460
|
-
|
|
8474
|
+
syncActiveTab() {
|
|
8475
|
+
const items = this.dataSource?.items;
|
|
8476
|
+
if (!items || items.length === 0) {
|
|
8477
|
+
this.currentActive = undefined;
|
|
8478
|
+
return;
|
|
8479
|
+
}
|
|
8480
|
+
if (this.currentActive && items.includes(this.currentActive)) {
|
|
8481
|
+
return;
|
|
8461
8482
|
}
|
|
8483
|
+
const defaultIndex = this.dataSource.defaultActive;
|
|
8484
|
+
const index = defaultIndex >= 0 && defaultIndex < items.length ? defaultIndex : 0;
|
|
8485
|
+
this.currentActive = items[index];
|
|
8462
8486
|
}
|
|
8463
8487
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnTabComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
8464
8488
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnTabComponent, isStandalone: true, selector: "mn-tab", inputs: { dataSource: "dataSource", scrollable: "scrollable", justified: "justified" }, outputs: { activeChange: "activeChange" }, ngImport: i0, template: "<div class=\"mb-10\">\n <div\n class=\"flex justify-start scrollbar-hide\"\n [class.overflow-x-auto]=\"scrollable\"\n [class.overflow-y-hidden]=\"scrollable\"\n >\n <div\n role=\"tablist\"\n class=\"tabs flex flex-nowrap -mb-[1px] border-b border-base-300\"\n [class.w-full]=\"justified\"\n >\n @if (dataSource.isDataLoading) {\n @for (i of skeletonTabs; track i) {\n <div\n [class.flex-1]=\"justified\"\n class=\"tab px-4 py-2 border-b-2 border-transparent flex items-center justify-center\"\n >\n <mn-skeleton [data]=\"{ shape: 'rectangle', width: '4.5rem', height: '1rem' }\"></mn-skeleton>\n </div>\n }\n } @else {\n @for (item of dataSource.items; track item.label) {\n <div\n (click)=\"setActive(item)\"\n (keyup.enter)=\"setActive(item)\"\n (keyup.space)=\"setActive(item)\"\n [attr.aria-selected]=\"currentActive === item\"\n [class.border-primary]=\"currentActive === item\"\n [class.border-transparent]=\"currentActive !== item\"\n [class.flex-1]=\"justified\"\n [class.font-bold]=\"currentActive === item\"\n [class.text-base-content]=\"currentActive !== item\"\n [class.text-primary]=\"currentActive === item\"\n class=\"tab px-4 py-2 border-b-2 cursor-pointer select-none transition-colors whitespace-nowrap text-center flex items-center gap-2\"\n role=\"tab\"\n tabindex=\"0\"\n >\n {{ item.label | mnTranslate }}\n @let badge = getBadge(item);\n @if (badge && badge > 0) {\n <span [data]=\"{ size: 'sm', color: 'accent', variant: 'fill' }\" mnBadge>{{ badge }}</span>\n }\n </div>\n }\n }\n </div>\n </div>\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: MnBadge, selector: "span[mnBadge]", inputs: ["data"] }, { kind: "component", type: MnSkeleton, selector: "mn-skeleton", inputs: ["data"] }, { kind: "pipe", type: MnTranslatePipe, name: "mnTranslate" }] });
|