feat(deps): update to Angular 22 and adopt APIs (#2468)

This commit is contained in:
Alex
2026-09-04 07:44:41 +01:00
committed by GitHub
parent a1a4ee167c
commit 3cc29fcc29
41 changed files with 2444 additions and 2499 deletions
+1
View File
@@ -55,4 +55,5 @@ backend/src/main/resources/application-local.yaml
/scratch /scratch
/pnpm-debug.log /pnpm-debug.log
/.pnpm-store/ /.pnpm-store/
/.angular/
.worktrees/ .worktrees/
+1 -1
View File
@@ -15,7 +15,7 @@ production image.
## Stack ## Stack
- Angular 21 - Angular 22
- TypeScript - TypeScript
- Optimus UI + OpenNG Icons - Optimus UI + OpenNG Icons
- Transloco for i18n - Transloco for i18n
+1 -1
View File
@@ -32,7 +32,7 @@ module.exports = tseslint.config(
style: "kebab-case", style: "kebab-case",
}, },
], ],
"@typescript-eslint/no-inferrable-types": "off" "@typescript-eslint/no-inferrable-types": "off",
}, },
}, },
{ {
+20 -20
View File
@@ -21,22 +21,22 @@
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
"@angular/aria": "^21.2.14", "@angular/aria": "^22.1.2",
"@angular/cdk": "^21.2.14", "@angular/cdk": "^22.1.2",
"@angular/common": "^21.2.20", "@angular/common": "^22.1.2",
"@angular/compiler": "^21.2.20", "@angular/compiler": "^22.1.2",
"@angular/core": "^21.2.20", "@angular/core": "^22.1.2",
"@angular/forms": "^21.2.20", "@angular/forms": "^22.1.2",
"@angular/platform-browser": "^21.2.20", "@angular/platform-browser": "^22.1.2",
"@angular/router": "^21.2.20", "@angular/router": "^22.1.2",
"@angular/service-worker": "^21.2.20", "@angular/service-worker": "^22.1.2",
"@embedpdf/pdfium": "2.15.0", "@embedpdf/pdfium": "2.15.0",
"@embedpdf/snippet": "2.15.0", "@embedpdf/snippet": "2.15.0",
"@jsverse/transloco": "^8.4.0", "@jsverse/transloco": "^8.4.0",
"@lucide/angular": "^1.31.0", "@lucide/angular": "^1.31.0",
"@openng/icons": "^1.0.0", "@openng/icons": "^1.0.0",
"@openng/optimus-ui": "^1.0.1", "@openng/optimus-ui": "^2.0.1",
"@openng/optimus-ui-themes": "^1.0.1", "@openng/optimus-ui-themes": "^2.0.1",
"@stomp/rx-stomp": "^2.4.0", "@stomp/rx-stomp": "^2.4.0",
"@stomp/stompjs": "^7.3.0", "@stomp/stompjs": "^7.3.0",
"@tanstack/angular-query-experimental": "5.101.4", "@tanstack/angular-query-experimental": "5.101.4",
@@ -51,7 +51,7 @@
"markdown-it": "^15.0.0", "markdown-it": "^15.0.0",
"ng-lazyload-image": "^9.1.3", "ng-lazyload-image": "^9.1.3",
"ng2-charts": "^10.0.0", "ng2-charts": "^10.0.0",
"ngx-infinite-scroll": "^21.0.0", "ngx-infinite-scroll": "^22.0.0",
"ngx-sse-client": "^21.0.0", "ngx-sse-client": "^21.0.0",
"rxjs": "^7.8.2", "rxjs": "^7.8.2",
"tailwind-merge": "^3.6.0", "tailwind-merge": "^3.6.0",
@@ -60,20 +60,20 @@
}, },
"devDependencies": { "devDependencies": {
"@analogjs/vite-plugin-angular": "^2.6.4", "@analogjs/vite-plugin-angular": "^2.6.4",
"@angular-devkit/architect": "0.2102.20", "@angular-devkit/architect": "^0.2201.4",
"@angular-devkit/schematics": "21.2.20", "@angular-devkit/schematics": "^22.1.4",
"@angular/build": "^21.2.20", "@angular/build": "22.1.4",
"@angular/cli": "^21.2.20", "@angular/cli": "^22.1.4",
"@angular/compiler-cli": "^21.2.20", "@angular/compiler-cli": "^22.1.2",
"@eslint/js": "^10.0.1", "@eslint/js": "^10.0.1",
"@openng/optimus-ui-tailwindcss": "1.0.1", "@openng/optimus-ui-tailwindcss": "^2.0.1",
"@playwright/test": "^1.62.1", "@playwright/test": "^1.62.1",
"@tailwindcss/postcss": "^4.3.3", "@tailwindcss/postcss": "^4.3.3",
"@testing-library/jest-dom": "^7.0.1", "@testing-library/jest-dom": "^7.0.1",
"@types/markdown-it": "^14.1.2", "@types/markdown-it": "^14.1.2",
"@types/node": "^24.13.2", "@types/node": "^24.13.2",
"@vitest/coverage-v8": "^4.1.10", "@vitest/coverage-v8": "^4.1.10",
"angular-eslint": "^21.4.0", "angular-eslint": "^22.1.0",
"eslint": "^10.8.1", "eslint": "^10.8.1",
"jsdom": "^30.0.1", "jsdom": "^30.0.1",
"ng-mocks": "^14.17.0", "ng-mocks": "^14.17.0",
@@ -81,7 +81,7 @@
"stylelint": "^17.14.1", "stylelint": "^17.14.1",
"stylelint-config-standard-scss": "^17.0.0", "stylelint-config-standard-scss": "^17.0.0",
"tailwindcss": "^4.3.3", "tailwindcss": "^4.3.3",
"typescript": "~5.9.3", "typescript": "~6.0.3",
"typescript-eslint": "^8.67.0", "typescript-eslint": "^8.67.0",
"vitest": "^4.1.10", "vitest": "^4.1.10",
"vitest-canvas-mock": "^1.1.4" "vitest-canvas-mock": "^1.1.4"
@@ -43,32 +43,34 @@ export type LibraryShelfMenuTarget =
@if (available()) { @if (available()) {
@switch (currentTarget.type) { @switch (currentTarget.type) {
@case ('library') { @case ('library') {
<app-menu-item (selected)="actions.addPhysicalBook(currentTarget.entity.id)"> <app-menu-item value="add-physical-book" (selected)="actions.addPhysicalBook(currentTarget.entity.id)">
{{ 'book.shelfMenuService.library.addPhysicalBook' | transloco }} {{ 'book.shelfMenuService.library.addPhysicalBook' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-item (selected)="actions.importIsbns(currentTarget.entity.id)"> <app-menu-item value="import-isbns" (selected)="actions.importIsbns(currentTarget.entity.id)">
{{ 'book.shelfMenuService.library.bulkIsbnImport' | transloco }} {{ 'book.shelfMenuService.library.bulkIsbnImport' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-separator /> <app-menu-separator />
<app-menu-item <app-menu-item
value="edit-library"
(selected)="actions.editLibrary(currentTarget.entity.id)"> (selected)="actions.editLibrary(currentTarget.entity.id)">
{{ 'book.shelfMenuService.library.editLibrary' | transloco }} {{ 'book.shelfMenuService.library.editLibrary' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-item (selected)="actions.rescanLibrary(currentTarget.entity)"> <app-menu-item value="rescan-library" (selected)="actions.rescanLibrary(currentTarget.entity)">
{{ 'book.shelfMenuService.library.rescanLibrary' | transloco }} {{ 'book.shelfMenuService.library.rescanLibrary' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-separator /> <app-menu-separator />
<app-menu-item (selected)="actions.customFetchLibraryMetadata(currentTarget.entity.id)"> <app-menu-item value="custom-fetch-metadata" (selected)="actions.customFetchLibraryMetadata(currentTarget.entity.id)">
{{ 'book.shelfMenuService.library.customFetchMetadata' | transloco }} {{ 'book.shelfMenuService.library.customFetchMetadata' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-item (selected)="actions.autoFetchLibraryMetadata(currentTarget.entity.id)"> <app-menu-item value="auto-fetch-metadata" (selected)="actions.autoFetchLibraryMetadata(currentTarget.entity.id)">
{{ 'book.shelfMenuService.library.autoFetchMetadata' | transloco }} {{ 'book.shelfMenuService.library.autoFetchMetadata' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-item (selected)="actions.findLibraryDuplicates(currentTarget.entity.id)"> <app-menu-item value="find-duplicates" (selected)="actions.findLibraryDuplicates(currentTarget.entity.id)">
{{ 'book.shelfMenuService.library.findDuplicates' | transloco }} {{ 'book.shelfMenuService.library.findDuplicates' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-separator /> <app-menu-separator />
<app-menu-item <app-menu-item
value="delete-library"
[icon]="trashIcon" [icon]="trashIcon"
variant="destructive" variant="destructive"
(selected)="actions.deleteLibrary(currentTarget.entity)"> (selected)="actions.deleteLibrary(currentTarget.entity)">
@@ -87,12 +89,14 @@ export type LibraryShelfMenuTarget =
</app-menu-section> </app-menu-section>
} }
<app-menu-item <app-menu-item
value="edit-shelf"
[disabled]="!canManageShelf()" [disabled]="!canManageShelf()"
(selected)="actions.editShelf(currentTarget.entity.id)"> (selected)="actions.editShelf(currentTarget.entity.id)">
{{ 'book.shelfMenuService.shelf.editShelf' | transloco }} {{ 'book.shelfMenuService.shelf.editShelf' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-separator /> <app-menu-separator />
<app-menu-item <app-menu-item
value="delete-shelf"
[icon]="trashIcon" [icon]="trashIcon"
[disabled]="!canManageShelf()" [disabled]="!canManageShelf()"
variant="destructive" variant="destructive"
@@ -102,15 +106,17 @@ export type LibraryShelfMenuTarget =
} }
@case ('magicShelf') { @case ('magicShelf') {
<app-menu-item <app-menu-item
value="edit-magic-shelf"
[disabled]="!canManageMagicShelf()" [disabled]="!canManageMagicShelf()"
(selected)="actions.editMagicShelf(currentTarget.entity.id)"> (selected)="actions.editMagicShelf(currentTarget.entity.id)">
{{ 'book.shelfMenuService.magicShelf.editMagicShelf' | transloco }} {{ 'book.shelfMenuService.magicShelf.editMagicShelf' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-item (selected)="actions.copyMagicShelfJson(currentTarget.entity.filterJson)"> <app-menu-item value="export-magic-shelf" (selected)="actions.copyMagicShelfJson(currentTarget.entity.filterJson)">
{{ 'book.shelfMenuService.magicShelf.exportJson' | transloco }} {{ 'book.shelfMenuService.magicShelf.exportJson' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-separator /> <app-menu-separator />
<app-menu-item <app-menu-item
value="delete-magic-shelf"
[icon]="trashIcon" [icon]="trashIcon"
[disabled]="!canManageMagicShelf()" [disabled]="!canManageMagicShelf()"
variant="destructive" variant="destructive"
@@ -44,23 +44,23 @@
<app-split-button tone="primary" label="Open" (clicked)="logMenu('Open')"> <app-split-button tone="primary" label="Open" (clicked)="logMenu('Open')">
<svg lucideFolderOpen></svg> <svg lucideFolderOpen></svg>
<app-menu ariaLabel="Open options"> <app-menu ariaLabel="Open options">
<app-menu-item [icon]="iconFolderOpen" (selected)="logMenu('Open in place')">Open</app-menu-item> <app-menu-item value="open" [icon]="iconFolderOpen" (selected)="logMenu('Open in place')">Open</app-menu-item>
<app-menu-item [icon]="iconCopy" (selected)="logMenu('Open a copy')">Open a copy</app-menu-item> <app-menu-item value="open-copy" [icon]="iconCopy" (selected)="logMenu('Open a copy')">Open a copy</app-menu-item>
</app-menu> </app-menu>
</app-split-button> </app-split-button>
<app-split-button label="Download" (clicked)="logMenu('Download')"> <app-split-button label="Download" (clicked)="logMenu('Download')">
<svg lucideDownload></svg> <svg lucideDownload></svg>
<app-menu ariaLabel="Download options"> <app-menu ariaLabel="Download options">
<app-menu-item [icon]="iconDownload" shortcut="⌘S" (selected)="logMenu('Download EPUB')">Download EPUB</app-menu-item> <app-menu-item value="download-epub" [icon]="iconDownload" shortcut="⌘S" (selected)="logMenu('Download EPUB')">Download EPUB</app-menu-item>
<app-menu-item [icon]="iconDownload" (selected)="logMenu('Download PDF')">Download PDF</app-menu-item> <app-menu-item value="download-pdf" [icon]="iconDownload" (selected)="logMenu('Download PDF')">Download PDF</app-menu-item>
</app-menu> </app-menu>
</app-split-button> </app-split-button>
<app-split-button tone="danger" variant="soft" label="Delete" (clicked)="logMenu('Delete')"> <app-split-button tone="danger" variant="soft" label="Delete" (clicked)="logMenu('Delete')">
<svg lucideTrash2></svg> <svg lucideTrash2></svg>
<app-menu ariaLabel="Delete options"> <app-menu ariaLabel="Delete options">
<app-menu-item (selected)="logMenu('Delete this')">Delete this</app-menu-item> <app-menu-item value="delete-this" (selected)="logMenu('Delete this')">Delete this</app-menu-item>
<app-menu-separator /> <app-menu-separator />
<app-menu-item variant="destructive" [icon]="iconTrash" (selected)="logMenu('Delete all')">Delete all…</app-menu-item> <app-menu-item value="delete-all" variant="destructive" [icon]="iconTrash" (selected)="logMenu('Delete all')">Delete all…</app-menu-item>
</app-menu> </app-menu>
</app-split-button> </app-split-button>
</div> </div>
@@ -540,15 +540,15 @@
<app-menu #richMenu ariaLabel="Item actions"> <app-menu #richMenu ariaLabel="Item actions">
<ng-template appMenuContent> <ng-template appMenuContent>
<app-menu-section>Actions</app-menu-section> <app-menu-section>Actions</app-menu-section>
<app-menu-item [icon]="iconPencil" shortcut="⌘E" (selected)="logMenu('Rename')">Rename</app-menu-item> <app-menu-item value="rename" [icon]="iconPencil" shortcut="⌘E" (selected)="logMenu('Rename')">Rename</app-menu-item>
<app-menu-item [icon]="iconCopy" shortcut="⌘D" (selected)="logMenu('Duplicate')">Duplicate</app-menu-item> <app-menu-item value="duplicate" [icon]="iconCopy" shortcut="⌘D" (selected)="logMenu('Duplicate')">Duplicate</app-menu-item>
<app-menu-item [icon]="iconShare" [submenu]="shareMenu">Share</app-menu-item> <app-menu-item value="share" [icon]="iconShare" [submenu]="shareMenu">Share</app-menu-item>
<app-menu-separator /> <app-menu-separator />
<app-menu-section>View</app-menu-section> <app-menu-section>View</app-menu-section>
<app-menu-checkbox [(checked)]="menuPinned" (selected)="logMenu('Pinned ' + $event)">Pin to top</app-menu-checkbox> <app-menu-checkbox value="pin" [(checked)]="menuPinned" (selected)="logMenu('Pinned ' + $event)">Pin to top</app-menu-checkbox>
<app-menu-checkbox [(checked)]="menuWrap" (selected)="logMenu('Wrap ' + $event)">Wrap long titles</app-menu-checkbox> <app-menu-checkbox value="wrap" [(checked)]="menuWrap" (selected)="logMenu('Wrap ' + $event)">Wrap long titles</app-menu-checkbox>
<app-menu-separator /> <app-menu-separator />
@@ -568,13 +568,13 @@
<app-menu-separator /> <app-menu-separator />
<app-menu-item variant="destructive" [icon]="iconTrash" (selected)="logMenu('Delete')">Delete…</app-menu-item> <app-menu-item value="delete" variant="destructive" [icon]="iconTrash" (selected)="logMenu('Delete')">Delete…</app-menu-item>
</ng-template> </ng-template>
</app-menu> </app-menu>
<app-menu #shareMenu="ngMenu" ariaLabel="Share targets"> <app-menu #shareMenu="ngMenu" ariaLabel="Share targets">
<app-menu-item [icon]="iconShare" (selected)="logMenu('Share link')">Copy link</app-menu-item> <app-menu-item value="copy-link" [icon]="iconShare" (selected)="logMenu('Share link')">Copy link</app-menu-item>
<app-menu-item [icon]="iconDownload" (selected)="logMenu('Share email')">Send by email…</app-menu-item> <app-menu-item value="send-email" [icon]="iconDownload" (selected)="logMenu('Share email')">Send by email…</app-menu-item>
</app-menu> </app-menu>
</section> </section>
@@ -1,4 +1,4 @@
import {Component, computed, DestroyRef, effect, EffectRef, EventEmitter, inject, Input, OnInit, Output,} from "@angular/core"; import {Component, computed, DestroyRef, effect, EffectRef, EventEmitter, inject, Input, OnInit, Output} from "@angular/core";
import {InputText} from "@openng/optimus-ui/inputtext"; import {InputText} from "@openng/optimus-ui/inputtext";
import {Button} from "@openng/optimus-ui/button"; import {Button} from "@openng/optimus-ui/button";
import {Divider} from "@openng/optimus-ui/divider"; import {Divider} from "@openng/optimus-ui/divider";
@@ -164,13 +164,10 @@ export class EbookReaderComponent implements OnInit {
this.applyStyles(); this.applyStyles();
}); });
effect( effect(() => {
() => { this.sidebarService.bookmarks();
this.sidebarService.bookmarks(); this.updateBookmarkIndicator();
this.updateBookmarkIndicator(); });
},
{allowSignalWrites: true}
);
} }
ngOnInit() { ngOnInit() {
@@ -60,6 +60,7 @@ const FILTER_THRESHOLD = 8;
<div class="max-h-80 overflow-y-auto overscroll-contain"> <div class="max-h-80 overflow-y-auto overscroll-contain">
@for (shelf of filteredShelves(); track shelf.id) { @for (shelf of filteredShelves(); track shelf.id) {
<app-menu-checkbox <app-menu-checkbox
[value]="shelf.id"
[checked]="shelf.checked" [checked]="shelf.checked"
[mixed]="shelf.mixed ?? false" [mixed]="shelf.mixed ?? false"
(selected)="toggleShelf.emit({shelfId: shelf.id, checked: $event})">{{ shelf.name }}</app-menu-checkbox> (selected)="toggleShelf.emit({shelfId: shelf.id, checked: $event})">{{ shelf.name }}</app-menu-checkbox>
@@ -72,7 +73,7 @@ const FILTER_THRESHOLD = 8;
@if (shelves().length > 0) { @if (shelves().length > 0) {
<app-menu-separator /> <app-menu-separator />
} }
<app-menu-item (selected)="createShelf.emit()">{{ 'shared.ui.shelfMenu.newShelf' | transloco }}</app-menu-item> <app-menu-item value="create-shelf" (selected)="createShelf.emit()">{{ 'shared.ui.shelfMenu.newShelf' | transloco }}</app-menu-item>
</ng-template> </ng-template>
</app-menu> </app-menu>
`, `,
@@ -1,4 +1,4 @@
import {Component} from '@angular/core'; import {Component, signal} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing'; import {ComponentFixture, TestBed} from '@angular/core/testing';
import {beforeEach, describe, expect, it} from 'vitest'; import {beforeEach, describe, expect, it} from 'vitest';
@@ -9,26 +9,26 @@ import {TagColor, TagComponent, TagSize, TagVariant} from './tag.component';
imports: [TagComponent], imports: [TagComponent],
template: ` template: `
<app-tag <app-tag
[color]="color" [color]="color()"
[size]="size" [size]="size()"
[variant]="variant" [variant]="variant()"
[rounded]="rounded" [rounded]="rounded()"
[pill]="pill" [pill]="pill()"
[customBgColor]="customBgColor" [customBgColor]="customBgColor()"
[customTextColor]="customTextColor" [customTextColor]="customTextColor()"
> >
Test Test
</app-tag> </app-tag>
`, `,
}) })
class TestHostComponent { class TestHostComponent {
color: TagColor = 'primary'; readonly color = signal<TagColor>('primary');
size: TagSize = 'm'; readonly size = signal<TagSize>('m');
variant: TagVariant = 'label'; readonly variant = signal<TagVariant>('label');
rounded = false; readonly rounded = signal(false);
pill = false; readonly pill = signal(false);
customBgColor = '#112233'; readonly customBgColor = signal('#112233');
customTextColor = '#fefefe'; readonly customTextColor = signal('#fefefe');
} }
describe('TagComponent', () => { describe('TagComponent', () => {
@@ -42,7 +42,7 @@ describe('TagComponent', () => {
fixture = TestBed.createComponent(TestHostComponent); fixture = TestBed.createComponent(TestHostComponent);
host = fixture.componentInstance; host = fixture.componentInstance;
fixture.detectChanges(); await fixture.whenStable();
}); });
it('renders the default color and size classes', () => { it('renders the default color and size classes', () => {
@@ -54,12 +54,11 @@ describe('TagComponent', () => {
expect(tag.textContent?.trim()).toBe('Test'); expect(tag.textContent?.trim()).toBe('Test');
}); });
it('adds pill and rounded classes when those inputs are enabled', () => { it('adds pill and rounded classes when those inputs are enabled', async () => {
host.variant = 'pill'; host.variant.set('pill');
host.rounded = true; host.rounded.set(true);
host.pill = true; host.pill.set(true);
fixture.changeDetectorRef.markForCheck(); await fixture.whenStable();
fixture.detectChanges();
const tag = fixture.nativeElement.querySelector('span') as HTMLSpanElement; const tag = fixture.nativeElement.querySelector('span') as HTMLSpanElement;
expect(tag.className).toContain('app-tag-variant-pill'); expect(tag.className).toContain('app-tag-variant-pill');
@@ -65,14 +65,14 @@
[ariaLabel]="t('add')"> [ariaLabel]="t('add')">
@if (currentUser(); as user) { @if (currentUser(); as user) {
@if (user.permissions.admin || user.permissions.canManageLibrary) { @if (user.permissions.admin || user.permissions.canManageLibrary) {
<app-menu-item (selected)="dialogLauncherService.openLibraryCreateDialog()"> <app-menu-item value="create-library" (selected)="dialogLauncherService.openLibraryCreateDialog()">
{{ t('createLibrary') }} {{ t('createLibrary') }}
</app-menu-item> </app-menu-item>
} }
<app-menu-item (selected)="bookDialogHelperService.openShelfCreatorDialog()"> <app-menu-item value="create-shelf" (selected)="bookDialogHelperService.openShelfCreatorDialog()">
{{ 'book.shelfCreator.title' | transloco }} {{ 'book.shelfCreator.title' | transloco }}
</app-menu-item> </app-menu-item>
<app-menu-item (selected)="dialogLauncherService.openMagicShelfCreateDialog()"> <app-menu-item value="create-magic-shelf" (selected)="dialogLauncherService.openMagicShelfCreateDialog()">
{{ t('createMagicShelf') }} {{ t('createMagicShelf') }}
</app-menu-item> </app-menu-item>
} }
@@ -79,7 +79,7 @@ const COLLAPSE_AFTER_ITEMS = 4;
@if (hiddenBreadcrumbs().length) { @if (hiddenBreadcrumbs().length) {
<app-menu #hiddenBreadcrumbMenu [ariaLabel]="'layout.pageHeader.moreBreadcrumbs' | transloco"> <app-menu #hiddenBreadcrumbMenu [ariaLabel]="'layout.pageHeader.moreBreadcrumbs' | transloco">
@for (breadcrumb of hiddenBreadcrumbs(); track breadcrumbKey(breadcrumb)) { @for (breadcrumb of hiddenBreadcrumbs(); track breadcrumbKey(breadcrumb)) {
<app-menu-item [disabled]="!breadcrumb.commands?.length" (selected)="navigate(breadcrumb)"> <app-menu-item [value]="breadcrumbKey(breadcrumb)" [disabled]="!breadcrumb.commands?.length" (selected)="navigate(breadcrumb)">
{{ breadcrumb.label }} {{ breadcrumb.label }}
</app-menu-item> </app-menu-item>
} }
@@ -63,7 +63,7 @@
</div> </div>
} }
<div class="app-page-header-controls flex min-w-0 grow basis-auto items-center justify-end gap-2 empty:hidden"> <div class="app-page-header-controls flex min-w-0 grow basis-auto items-center justify-end gap-2 empty:hidden">
<ng-content></ng-content> <ng-content select=":not(ng-template[appTabPanel])" />
</div> </div>
</div> </div>
@@ -75,8 +75,9 @@
(selectedTabIdChange)="onSelectedTabChange($event)" (selectedTabIdChange)="onSelectedTabChange($event)"
size="md" size="md"
placement="below" placement="below"
collapse="scroll" collapse="scroll">
/> <ng-content select="ng-template[appTabPanel]" />
</app-tabs>
} }
</div> </div>
} }
@@ -54,7 +54,7 @@ export class CacheStorageService {
this.http.get<ArrayBuffer>(uri, { this.http.get<ArrayBuffer>(uri, {
responseType: "arraybuffer" as "json", responseType: "arraybuffer" as "json",
observe: "response", observe: "response",
cache: "no-store", headers: {"Cache-Control": "no-store"},
}), }),
); );
} }
@@ -5,7 +5,6 @@ import {
Directive, Directive,
inject, inject,
input, input,
model,
output, output,
type ElementRef, type ElementRef,
viewChild, viewChild,
@@ -33,7 +32,8 @@ export abstract class AppAutocompleteBaseDirective {
readonly hasMore = input(false, { transform: booleanAttribute }); readonly hasMore = input(false, { transform: booleanAttribute });
readonly errored = input(false, { transform: booleanAttribute }); readonly errored = input(false, { transform: booleanAttribute });
readonly readonly = input(false, { transform: booleanAttribute }); readonly readonly = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly allowCustom = input(true, { transform: booleanAttribute }); readonly allowCustom = input(true, { transform: booleanAttribute });
@@ -82,8 +82,16 @@ export abstract class AppAutocompleteBaseDirective {
this.opened.emit(); this.opened.emit();
} }
protected markTouchedWhenFocusLeavesControl(event: FocusEvent): void {
if (this.isUnavailable()) return;
const control = event.currentTarget;
const next = event.relatedTarget;
if (control instanceof HTMLElement && next instanceof Node && control.contains(next)) return;
this.touch.emit();
}
protected closePopup(): void { protected closePopup(): void {
this.combobox()?.close(); this.combobox()?.expanded.set(false);
} }
focus(options?: FocusOptions): void { focus(options?: FocusOptions): void {
@@ -14,7 +14,7 @@ import {
type TemplateRef, type TemplateRef,
} from '@angular/core'; } from '@angular/core';
import { NgTemplateOutlet } from '@angular/common'; import { NgTemplateOutlet } from '@angular/common';
import { ComboboxPopupContainer } from '@angular/aria/combobox'; import { Combobox, ComboboxPopup, ComboboxWidget } from '@angular/aria/combobox';
import { Listbox, Option } from '@angular/aria/listbox'; import { Listbox, Option } from '@angular/aria/listbox';
import { import {
CdkConnectedOverlay, CdkConnectedOverlay,
@@ -47,10 +47,10 @@ const LOAD_MORE_PREFETCH_PX = 240;
@Component({ @Component({
selector: 'app-autocomplete-popup', selector: 'app-autocomplete-popup',
standalone: true, standalone: true,
imports: [NgTemplateOutlet, OverlayModule, ComboboxPopupContainer, Listbox, Option, TranslocoPipe, LucideLoaderCircle], imports: [NgTemplateOutlet, OverlayModule, ComboboxPopup, ComboboxWidget, Listbox, Option, TranslocoPipe, LucideLoaderCircle],
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
template: ` template: `
<ng-template ngComboboxPopupContainer> <ng-template ngComboboxPopup [combobox]="combobox()">
<ng-template <ng-template
[cdkConnectedOverlay]="{ [cdkConnectedOverlay]="{
origin: origin(), origin: origin(),
@@ -65,15 +65,17 @@ const LOAD_MORE_PREFETCH_PX = 240;
(attach)="onOverlayAttach()"> (attach)="onOverlayAttach()">
<div [class]="surfaceClass"> <div [class]="surfaceClass">
<ul <ul
ngComboboxWidget
ngListbox ngListbox
#list #list="ngListbox"
tabindex="-1" tabindex="-1"
focusMode="activedescendant" focusMode="activedescendant"
selectionMode="explicit" selectionMode="explicit"
[activeDescendant]="list.activeDescendant()"
[readonly]="readonly()" [readonly]="readonly()"
[disabled]="disabled()" [disabled]="disabled()"
[attr.aria-busy]="isBusy() ? 'true' : null" [attr.aria-busy]="isBusy() ? 'true' : null"
(valuesChange)="onValuesChange($event)" (valueChange)="onValuesChange($event)"
[class]="listClass"> [class]="listClass">
@for (option of options(); track option.value) { @for (option of options(); track option.value) {
<li <li
@@ -115,6 +117,7 @@ const LOAD_MORE_PREFETCH_PX = 240;
`, `,
}) })
export class AppAutocompletePopupComponent { export class AppAutocompletePopupComponent {
readonly combobox = input.required<Combobox>();
readonly origin = input.required<ElementRef<HTMLElement> | HTMLElement>(); readonly origin = input.required<ElementRef<HTMLElement> | HTMLElement>();
readonly open = input(false); readonly open = input(false);
readonly disabled = input(false); readonly disabled = input(false);
@@ -203,7 +206,7 @@ export class AppAutocompletePopupComponent {
} }
clearSelection(): void { clearSelection(): void {
this.listbox()?.values.set([]); this.listbox()?.value.set([]);
} }
protected onOverlayAttach(): void { protected onOverlayAttach(): void {
@@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, computed, input, linkedSignal, model, signal, viewChild } from '@angular/core'; import { ChangeDetectionStrategy, Component, computed, input, linkedSignal, model, signal, viewChild } from '@angular/core';
import { type FormValueControl } from '@angular/forms/signals'; import { type FormValueControl } from '@angular/forms/signals';
import { Combobox, ComboboxInput } from '@angular/aria/combobox'; import { Combobox } from '@angular/aria/combobox';
import { LucideLoaderCircle } from '@lucide/angular'; import { LucideLoaderCircle } from '@lucide/angular';
import { AppControlTransitionDirective } from '../control.styles'; import { AppControlTransitionDirective } from '../control.styles';
@@ -14,21 +14,16 @@ type AppAutocompleteSelectedDisplay = 'text' | 'tag';
@Component({ @Component({
selector: 'app-autocomplete', selector: 'app-autocomplete',
standalone: true, standalone: true,
imports: [Combobox, ComboboxInput, LucideLoaderCircle, AppAutocompletePopupComponent, AppAutocompleteSelectedTagsComponent, AppControlTransitionDirective], imports: [Combobox, LucideLoaderCircle, AppAutocompletePopupComponent, AppAutocompleteSelectedTagsComponent, AppControlTransitionDirective],
host: { class: 'block w-full' }, host: { class: 'block w-full' },
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
template: ` template: `
<div <div class="relative block w-full">
ngCombobox
#cb="ngCombobox"
filterMode="manual"
[readonly]="readonly()"
[disabled]="disabled()"
class="relative block w-full">
<div <div
appControlTransition appControlTransition
#origin #origin
[class]="boxClass()" [class]="boxClass()"
(focusout)="markTouchedWhenFocusLeavesControl($event)"
(pointerdown)="focusInputOnPointerdown($event, input)"> (pointerdown)="focusInputOnPointerdown($event, input)">
@if (selectedTags().length) { @if (selectedTags().length) {
<app-autocomplete-selected-tags <app-autocomplete-selected-tags
@@ -39,12 +34,15 @@ type AppAutocompleteSelectedDisplay = 'text' | 'tag';
(remove)="clearSelectedTag(input)" /> (remove)="clearSelectedTag(input)" />
} }
<input <input
ngComboboxInput ngCombobox
#cb="ngCombobox"
#input #input
type="text" type="text"
autocomplete="off" autocomplete="off"
spellcheck="false" spellcheck="false"
[(value)]="query" [(value)]="query"
[readonly]="inputReadonly()"
[disabled]="disabled()"
[attr.id]="resolvedInputId()" [attr.id]="resolvedInputId()"
[attr.name]="name() || null" [attr.name]="name() || null"
[placeholder]="placeholderText()" [placeholder]="placeholderText()"
@@ -53,9 +51,7 @@ type AppAutocompleteSelectedDisplay = 'text' | 'tag';
[attr.aria-readonly]="inputReadonly() ? 'true' : null" [attr.aria-readonly]="inputReadonly() ? 'true' : null"
[attr.aria-busy]="pending() ? 'true' : null" [attr.aria-busy]="pending() ? 'true' : null"
[attr.aria-describedby]="resolvedDescribedBy()" [attr.aria-describedby]="resolvedDescribedBy()"
[disabled]="disabled()"
[required]="required()" [required]="required()"
[readonly]="inputReadonly()"
(input)="onType(input.value)" (input)="onType(input.value)"
(focus)="onInputFocus()" (focus)="onInputFocus()"
(keydown.enter)="onEnter($event)" (keydown.enter)="onEnter($event)"
@@ -70,6 +66,7 @@ type AppAutocompleteSelectedDisplay = 'text' | 'tag';
</div> </div>
<app-autocomplete-popup <app-autocomplete-popup
[combobox]="cb"
[origin]="origin" [origin]="origin"
[open]="cb.expanded()" [open]="cb.expanded()"
[disabled]="disabled()" [disabled]="disabled()"
@@ -143,8 +140,6 @@ export class AppAutocompleteComponent extends AppAutocompleteBaseDirective imple
} }
protected onInputBlur(): void { protected onInputBlur(): void {
this.touched.set(true);
if (this.allowCustom()) return; if (this.allowCustom()) return;
queueMicrotask(() => { queueMicrotask(() => {
@@ -157,7 +152,6 @@ export class AppAutocompleteComponent extends AppAutocompleteBaseDirective imple
this.committedOption.set(option); this.committedOption.set(option);
this.value.set(option.value); this.value.set(option.value);
this.query.set(this.selectedDisplay() === 'tag' ? '' : option.label); this.query.set(this.selectedDisplay() === 'tag' ? '' : option.label);
this.touched.set(true);
this.closePopup(); this.closePopup();
} }
@@ -166,7 +160,6 @@ export class AppAutocompleteComponent extends AppAutocompleteBaseDirective imple
this.committedOption.set(null); this.committedOption.set(null);
this.value.set(''); this.value.set('');
this.query.set(''); this.query.set('');
this.touched.set(true);
this.complete.emit(''); this.complete.emit('');
queueMicrotask(() => input.focus()); queueMicrotask(() => input.focus());
} }
@@ -8,7 +8,7 @@ import {
viewChild, viewChild,
} from '@angular/core'; } from '@angular/core';
import { type FormValueControl } from '@angular/forms/signals'; import { type FormValueControl } from '@angular/forms/signals';
import { Combobox, ComboboxInput } from '@angular/aria/combobox'; import { Combobox } from '@angular/aria/combobox';
import { LucideLoaderCircle } from '@lucide/angular'; import { LucideLoaderCircle } from '@lucide/angular';
import { AppControlTransitionDirective } from '../control.styles'; import { AppControlTransitionDirective } from '../control.styles';
@@ -20,21 +20,16 @@ import { AppAutocompleteSelectedTagsComponent } from './app-autocomplete-selecte
@Component({ @Component({
selector: 'app-multi-autocomplete', selector: 'app-multi-autocomplete',
standalone: true, standalone: true,
imports: [Combobox, ComboboxInput, LucideLoaderCircle, AppAutocompletePopupComponent, AppAutocompleteSelectedTagsComponent, AppControlTransitionDirective], imports: [Combobox, LucideLoaderCircle, AppAutocompletePopupComponent, AppAutocompleteSelectedTagsComponent, AppControlTransitionDirective],
host: { class: 'block w-full' }, host: { class: 'block w-full' },
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
template: ` template: `
<div <div class="relative block w-full">
ngCombobox
#cb="ngCombobox"
filterMode="manual"
[readonly]="readonly()"
[disabled]="disabled()"
class="relative block w-full">
<div <div
appControlTransition appControlTransition
#origin #origin
[class]="boxClass()" [class]="boxClass()"
(focusout)="markTouchedWhenFocusLeavesControl($event)"
(pointerdown)="focusInputOnPointerdown($event, input)"> (pointerdown)="focusInputOnPointerdown($event, input)">
@if (selectedTags().length) { @if (selectedTags().length) {
<app-autocomplete-selected-tags <app-autocomplete-selected-tags
@@ -45,12 +40,15 @@ import { AppAutocompleteSelectedTagsComponent } from './app-autocomplete-selecte
(remove)="removeChip($event)" /> (remove)="removeChip($event)" />
} }
<input <input
ngComboboxInput ngCombobox
#cb="ngCombobox"
#input #input
type="text" type="text"
autocomplete="off" autocomplete="off"
spellcheck="false" spellcheck="false"
[(value)]="query" [(value)]="query"
[readonly]="readonly()"
[disabled]="disabled()"
[attr.id]="resolvedInputId()" [attr.id]="resolvedInputId()"
[attr.name]="name() || null" [attr.name]="name() || null"
[placeholder]="placeholderText()" [placeholder]="placeholderText()"
@@ -59,14 +57,11 @@ import { AppAutocompleteSelectedTagsComponent } from './app-autocomplete-selecte
[attr.aria-readonly]="readonly() ? 'true' : null" [attr.aria-readonly]="readonly() ? 'true' : null"
[attr.aria-busy]="pending() ? 'true' : null" [attr.aria-busy]="pending() ? 'true' : null"
[attr.aria-describedby]="resolvedDescribedBy()" [attr.aria-describedby]="resolvedDescribedBy()"
[disabled]="disabled()"
[required]="required()" [required]="required()"
[readonly]="readonly()"
(input)="onType(input.value)" (input)="onType(input.value)"
(focus)="onInputFocus()" (focus)="onInputFocus()"
(keydown.enter)="onEnter($event)" (keydown.enter)="onEnter($event)"
(keydown.backspace)="onBackspace()" (keydown.backspace)="onBackspace()"
(blur)="touched.set(true)"
[class]="innerInputClass" /> [class]="innerInputClass" />
<svg <svg
lucideLoaderCircle lucideLoaderCircle
@@ -77,6 +72,7 @@ import { AppAutocompleteSelectedTagsComponent } from './app-autocomplete-selecte
</div> </div>
<app-autocomplete-popup <app-autocomplete-popup
[combobox]="cb"
[origin]="origin" [origin]="origin"
[open]="cb.expanded()" [open]="cb.expanded()"
[disabled]="disabled()" [disabled]="disabled()"
@@ -143,7 +139,6 @@ export class AppMultiAutocompleteComponent extends AppAutocompleteBaseDirective
const current = this.value(); const current = this.value();
if (!current.length) return; if (!current.length) return;
this.value.set(current.slice(0, -1)); this.value.set(current.slice(0, -1));
this.touched.set(true);
} }
protected selectOption(option: AppAutocompleteOption): void { protected selectOption(option: AppAutocompleteOption): void {
@@ -153,7 +148,6 @@ export class AppMultiAutocompleteComponent extends AppAutocompleteBaseDirective
protected removeChip(value: string): void { protected removeChip(value: string): void {
this.chipLabels.delete(value); this.chipLabels.delete(value);
this.value.set(this.value().filter((existing) => existing !== value)); this.value.set(this.value().filter((existing) => existing !== value));
this.touched.set(true);
} }
private addChip(option: AppAutocompleteOption): void { private addChip(option: AppAutocompleteOption): void {
@@ -166,7 +160,6 @@ export class AppMultiAutocompleteComponent extends AppAutocompleteBaseDirective
this.chipLabels.set(option.value, option.label); this.chipLabels.set(option.value, option.label);
this.value.set([...current, option.value]); this.value.set([...current, option.value]);
this.clearTagInput(); this.clearTagInput();
this.touched.set(true);
this.complete.emit(''); this.complete.emit('');
} }
@@ -7,6 +7,7 @@ import {
inject, inject,
input, input,
model, model,
output,
type ElementRef, type ElementRef,
viewChild, viewChild,
} from '@angular/core'; } from '@angular/core';
@@ -45,7 +46,7 @@ import {
[disabled]="isUnavailable()" [disabled]="isUnavailable()"
[required]="required()" [required]="required()"
(change)="onInputChange(checkbox.checked)" (change)="onInputChange(checkbox.checked)"
(blur)="touched.set(true)" /> (blur)="touch.emit()" />
<span appControlTransition [class]="boxClass()" aria-hidden="true"></span> <span appControlTransition [class]="boxClass()" aria-hidden="true"></span>
<svg appControlTransition [class]="checkIndicatorClass()" viewBox="0 0 16 16" fill="none" aria-hidden="true"> <svg appControlTransition [class]="checkIndicatorClass()" viewBox="0 0 16 16" fill="none" aria-hidden="true">
<path <path
@@ -68,7 +69,8 @@ export class AppCheckboxComponent implements FormCheckboxControl {
readonly invalid = input(false, { transform: booleanAttribute }); readonly invalid = input(false, { transform: booleanAttribute });
readonly pending = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute });
readonly readonly = input(false, { transform: booleanAttribute }); readonly readonly = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly indeterminate = model(false); readonly indeterminate = model(false);
@@ -6,7 +6,7 @@ import {
inject, inject,
input, input,
LOCALE_ID, LOCALE_ID,
model, output,
signal, signal,
type ElementRef, type ElementRef,
type Signal, type Signal,
@@ -94,7 +94,7 @@ function currentYearMonth(): YearMonth {
} }
export const DATE_PICKER_TEMPLATE = ` export const DATE_PICKER_TEMPLATE = `
<div #origin class="relative block w-full"> <div #origin class="relative block w-full" (focusout)="markTouchedWhenFocusLeavesControl($event)">
<input <input
appControlTransition appControlTransition
#trigger #trigger
@@ -117,8 +117,7 @@ export const DATE_PICKER_TEMPLATE = `
[disabled]="disabled()" [disabled]="disabled()"
[required]="required()" [required]="required()"
(click)="toggle()" (click)="toggle()"
(keydown)="onTriggerKeydown($event)" (keydown)="onTriggerKeydown($event)" />
(blur)="onTriggerBlur($event)" />
<span <span
class="pointer-events-none absolute inset-y-0 right-0 inline-flex w-10 items-center justify-center text-text-muted"> class="pointer-events-none absolute inset-y-0 right-0 inline-flex w-10 items-center justify-center text-text-muted">
@@ -148,7 +147,7 @@ export const DATE_PICKER_TEMPLATE = `
role="dialog" role="dialog"
[attr.aria-label]="monthYearLabel()" [attr.aria-label]="monthYearLabel()"
[class]="popupClass" [class]="popupClass"
(focusout)="onPopupFocusOut($event)"> (focusout)="closeAndMarkTouchedWhenFocusLeavesPopup($event)">
<div class="mb-2 flex items-center justify-between gap-1"> <div class="mb-2 flex items-center justify-between gap-1">
<button type="button" [class]="navButtonClass" [attr.aria-label]="'shared.ui.datePicker.previousMonth' | transloco" (click)="shiftMonth(-1)"> <button type="button" [class]="navButtonClass" [attr.aria-label]="'shared.ui.datePicker.previousMonth' | transloco" (click)="shiftMonth(-1)">
<svg lucideChevronLeft class="size-4" aria-hidden="true"></svg> <svg lucideChevronLeft class="size-4" aria-hidden="true"></svg>
@@ -221,7 +220,8 @@ export abstract class AppDatePickerBaseDirective {
readonly invalid = input(false, { transform: booleanAttribute }); readonly invalid = input(false, { transform: booleanAttribute });
readonly pending = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute });
readonly readonly = input(false, { transform: booleanAttribute }); readonly readonly = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly size = input<AppDatePickerSize>('md'); readonly size = input<AppDatePickerSize>('md');
@@ -403,10 +403,9 @@ export abstract class AppDatePickerBaseDirective {
} }
} }
protected onTriggerBlur(event: FocusEvent): void { protected markTouchedWhenFocusLeavesControl(event: FocusEvent): void {
if (this.disabled()) return; if (this.isUnavailable() || this.focusRemainsInControl(event.relatedTarget)) return;
if (this.relatedTargetInPopup(event.relatedTarget)) return; this.touch.emit();
this.touched.set(true);
} }
protected onOverlayKeydown(event: KeyboardEvent): void { protected onOverlayKeydown(event: KeyboardEvent): void {
@@ -422,12 +421,11 @@ export abstract class AppDatePickerBaseDirective {
this.close(); this.close();
} }
protected onPopupFocusOut(event: FocusEvent): void { protected closeAndMarkTouchedWhenFocusLeavesPopup(event: FocusEvent): void {
const next = event.relatedTarget; const next = event.relatedTarget;
if (next === null) return; if (this.focusRemainsInControl(next)) return;
if (next instanceof Node && this.originRef()?.nativeElement.contains(next)) return;
if (this.relatedTargetInPopup(next)) return;
this.close(); this.close();
if (!this.isUnavailable()) this.touch.emit();
} }
protected onOverlayAttach(): void { protected onOverlayAttach(): void {
@@ -461,9 +459,11 @@ export abstract class AppDatePickerBaseDirective {
); );
} }
private relatedTargetInPopup(target: EventTarget | null): boolean { private focusRemainsInControl(target: EventTarget | null): boolean {
if (!(target instanceof Node)) return false;
if (this.originRef()?.nativeElement.contains(target)) return true;
const overlayElement = this.overlay()?.overlayRef?.overlayElement; const overlayElement = this.overlay()?.overlayRef?.overlayElement;
return target instanceof Node && overlayElement?.contains(target) === true; return overlayElement?.contains(target) === true;
} }
private focusInitialDay(): void { private focusInitialDay(): void {
@@ -38,7 +38,6 @@ export class AppDatePickerComponent extends AppDatePickerBaseDirective implement
protected override pickDay(day: DayCell): void { protected override pickDay(day: DayCell): void {
this.value.set(day.iso); this.value.set(day.iso);
this.touched.set(true);
this.close(true); this.close(true);
} }
@@ -63,7 +63,6 @@ export class AppDateRangePickerComponent extends AppDatePickerBaseDirective impl
protected override pickDay(day: DayCell): void { protected override pickDay(day: DayCell): void {
const range = this.value(); const range = this.value();
this.touched.set(true);
this.clearPreview(); this.clearPreview();
if (!range.start || range.end || day.iso < range.start) { if (!range.start || range.end || day.iso < range.start) {
this.value.set({ start: day.iso, end: '' }); this.value.set({ start: day.iso, end: '' });
@@ -57,7 +57,7 @@ const REVEAL_TOGGLE_CLASS =
[readonly]="readonly()" [readonly]="readonly()"
[required]="required()" [required]="required()"
(input)="onInput(input)" (input)="onInput(input)"
(blur)="touched.set(true)" (blur)="touch.emit()"
(keydown)="keyedDown.emit($event)" (keydown)="keyedDown.emit($event)"
(keyup.enter)="onEnterKeyup($event)" /> (keyup.enter)="onEnterKeyup($event)" />
@if (pending()) { @if (pending()) {
@@ -88,7 +88,8 @@ export class AppInputComponent implements FormValueControl<string> {
readonly required = input(false, { transform: booleanAttribute }); readonly required = input(false, { transform: booleanAttribute });
readonly invalid = input(false, { transform: booleanAttribute }); readonly invalid = input(false, { transform: booleanAttribute });
readonly pending = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly size = input<AppInputSize>('md'); readonly size = input<AppInputSize>('md');
@@ -28,7 +28,7 @@ import {
selector: 'app-menu-checkbox', selector: 'app-menu-checkbox',
standalone: true, standalone: true,
imports: [LucideCheck, LucideMinus], imports: [LucideCheck, LucideMinus],
hostDirectives: [{ directive: AppMenuAriaItemDirective, inputs: ['disabled'] }], hostDirectives: [{ directive: AppMenuAriaItemDirective, inputs: ['value', 'disabled'] }],
host: { host: {
'[class]': 'rowClass', '[class]': 'rowClass',
'[attr.role]': "'menuitemcheckbox'", '[attr.role]': "'menuitemcheckbox'",
@@ -35,7 +35,7 @@ import {
selector: 'app-menu-item', selector: 'app-menu-item',
standalone: true, standalone: true,
imports: [NgTemplateOutlet, RouterLink, LucideDynamicIcon, LucideChevronRight, LucideLoaderCircle], imports: [NgTemplateOutlet, RouterLink, LucideDynamicIcon, LucideChevronRight, LucideLoaderCircle],
hostDirectives: [{ directive: AppMenuAriaItemDirective, inputs: ['disabled', 'submenu'] }], hostDirectives: [{ directive: AppMenuAriaItemDirective, inputs: ['value', 'disabled', 'submenu'] }],
host: { host: {
'[class]': 'rowClass()', '[class]': 'rowClass()',
'[attr.aria-disabled]': 'inert()', '[attr.aria-disabled]': 'inert()',
@@ -25,7 +25,7 @@ import {
selector: 'app-menu-radio', selector: 'app-menu-radio',
standalone: true, standalone: true,
imports: [LucideCheck], imports: [LucideCheck],
hostDirectives: [{ directive: AppMenuAriaItemDirective, inputs: ['disabled'] }], hostDirectives: [{ directive: AppMenuAriaItemDirective, inputs: ['value', 'disabled'] }],
host: { host: {
'[class]': 'rowClass', '[class]': 'rowClass',
'[attr.role]': "'menuitemradio'", '[attr.role]': "'menuitemradio'",
@@ -47,7 +47,6 @@ import {
`, `,
}) })
export class AppMenuRadioComponent<T> { export class AppMenuRadioComponent<T> {
readonly value = input.required<T>();
readonly shortcut = input(''); readonly shortcut = input('');
readonly closeOnSelect = input(true, { transform: booleanAttribute }); readonly closeOnSelect = input(true, { transform: booleanAttribute });
readonly searchLabel = input(''); readonly searchLabel = input('');
@@ -58,7 +57,7 @@ export class AppMenuRadioComponent<T> {
private readonly menuItem = inject(AppMenuAriaItemDirective); private readonly menuItem = inject(AppMenuAriaItemDirective);
private readonly owner = inject(AppMenuComponent); private readonly owner = inject(AppMenuComponent);
protected readonly checked = computed(() => this.group.isSelected(this.value())); protected readonly checked = computed(() => this.group.isSelected(this.menuValue()));
protected readonly rowClass = appMenuItemRowClass('default'); protected readonly rowClass = appMenuItemRowClass('default');
protected readonly leadingSlotClass = appMenuLeadingSlotClass; protected readonly leadingSlotClass = appMenuLeadingSlotClass;
protected readonly checkClass = appMenuCheckIconClass; protected readonly checkClass = appMenuCheckIconClass;
@@ -78,8 +77,13 @@ export class AppMenuRadioComponent<T> {
} }
private choose(): void { private choose(): void {
this.group.select(this.value()); const value = this.menuValue();
this.selected.emit(this.value()); this.group.select(value);
this.selected.emit(value);
if (this.closeOnSelect()) this.owner.closeChain(); if (this.closeOnSelect()) this.owner.closeChain();
} }
private menuValue(): T {
return this.menuItem.value() as T;
}
} }
@@ -30,30 +30,30 @@ import { AppContextMenuDirective, AppMenuTriggerDirective } from './app-menu-tri
<div class="zone" [appContextMenuFor]="menu">right-click</div> <div class="zone" [appContextMenuFor]="menu">right-click</div>
<app-menu #menu ariaLabel="Actions"> <app-menu #menu ariaLabel="Actions">
<app-menu-item (selected)="onDownload()">Download</app-menu-item> <app-menu-item value="download" (selected)="onDownload()">Download</app-menu-item>
<app-menu-item [disabled]="true" (selected)="onDisabled()">Disabled</app-menu-item> <app-menu-item value="disabled" [disabled]="true" (selected)="onDisabled()">Disabled</app-menu-item>
<app-menu-checkbox [(checked)]="fav" [(mixed)]="favMixed" (selected)="onFav($event)">Favourite</app-menu-checkbox> <app-menu-checkbox value="favourite" [(checked)]="fav" [(mixed)]="favMixed" (selected)="onFav($event)">Favourite</app-menu-checkbox>
<app-menu-radio-group [(value)]="status"> <app-menu-radio-group [(value)]="status">
<app-menu-radio [value]="'read'">Read</app-menu-radio> <app-menu-radio [value]="'read'">Read</app-menu-radio>
<app-menu-radio [value]="'reading'">Reading</app-menu-radio> <app-menu-radio [value]="'reading'">Reading</app-menu-radio>
</app-menu-radio-group> </app-menu-radio-group>
<app-menu-item [submenu]="sub" (selected)="onSend()">Send</app-menu-item> <app-menu-item value="send" [submenu]="sub" (selected)="onSend()">Send</app-menu-item>
<app-menu-item [loading]="busy()" (selected)="onBusy()">Working</app-menu-item> <app-menu-item value="working" [loading]="busy()" (selected)="onBusy()">Working</app-menu-item>
<app-menu-item [closeOnSelect]="false" (selected)="onKeepOpen()">{{ keepOpenLabel() }}</app-menu-item> <app-menu-item value="keep-open" [closeOnSelect]="false" (selected)="onKeepOpen()">{{ keepOpenLabel() }}</app-menu-item>
<app-menu-item [link]="'/books'" (selected)="onLink()">Go to books</app-menu-item> <app-menu-item value="books" [link]="'/books'" (selected)="onLink()">Go to books</app-menu-item>
</app-menu> </app-menu>
<app-menu #sub="ngMenu" ariaLabel="Send options"> <app-menu #sub="ngMenu" ariaLabel="Send options">
<ng-template appMenuContent> <ng-template appMenuContent>
<app-menu-item (selected)="onQuick()">Quick send</app-menu-item> <app-menu-item value="quick-send" (selected)="onQuick()">Quick send</app-menu-item>
</ng-template> </ng-template>
</app-menu> </app-menu>
<button class="lazy-trigger" [appMenuTriggerFor]="lazyMenu">Open lazy menu</button> <button class="lazy-trigger" [appMenuTriggerFor]="lazyMenu">Open lazy menu</button>
<app-menu #lazyMenu ariaLabel="Lazy actions"> <app-menu #lazyMenu ariaLabel="Lazy actions">
<ng-template appMenuContent> <ng-template appMenuContent>
<app-menu-item>Lazy first</app-menu-item> <app-menu-item value="lazy-first">Lazy first</app-menu-item>
<app-menu-item>Lazy last</app-menu-item> <app-menu-item value="lazy-last">Lazy last</app-menu-item>
</ng-template> </ng-template>
</app-menu> </app-menu>
`, `,
@@ -1,4 +1,4 @@
import { Directive, forwardRef, input } from '@angular/core'; import { Directive, forwardRef } from '@angular/core';
import { MenuItem } from '@angular/aria/menu'; import { MenuItem } from '@angular/aria/menu';
import type { AppMenuComponent } from './app-menu.component'; import type { AppMenuComponent } from './app-menu.component';
@@ -9,8 +9,5 @@ import type { AppMenuComponent } from './app-menu.component';
providers: [{ provide: MenuItem, useExisting: forwardRef(() => AppMenuAriaItemDirective) }], providers: [{ provide: MenuItem, useExisting: forwardRef(() => AppMenuAriaItemDirective) }],
}) })
export class AppMenuAriaItemDirective extends MenuItem<unknown> { export class AppMenuAriaItemDirective extends MenuItem<unknown> {
override readonly value = input<unknown>('app-menu-item');
override readonly disabled = input(false);
owner: AppMenuComponent | undefined; owner: AppMenuComponent | undefined;
} }
@@ -7,6 +7,7 @@ import {
input, input,
model, model,
numberAttribute, numberAttribute,
output,
type ElementRef, type ElementRef,
viewChild, viewChild,
} from '@angular/core'; } from '@angular/core';
@@ -46,7 +47,7 @@ import { appInputVariants, type AppInputSize } from '../input/app-input.variants
[readonly]="readonly()" [readonly]="readonly()"
[required]="required()" [required]="required()"
(input)="onInput(input)" (input)="onInput(input)"
(blur)="touched.set(true)" /> (blur)="touch.emit()" />
@if (unit() || !readonly()) { @if (unit() || !readonly()) {
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-stretch"> <div class="pointer-events-none absolute inset-y-0 right-0 flex items-stretch">
@@ -88,7 +89,8 @@ export class AppNumberInputComponent implements FormValueControl<number | null>
readonly required = input(false, { transform: booleanAttribute }); readonly required = input(false, { transform: booleanAttribute });
readonly invalid = input(false, { transform: booleanAttribute }); readonly invalid = input(false, { transform: booleanAttribute });
readonly pending = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly size = input<AppInputSize>('md'); readonly size = input<AppInputSize>('md');
@@ -6,6 +6,7 @@ import {
inject, inject,
input, input,
model, model,
output,
type ElementRef, type ElementRef,
viewChildren, viewChildren,
} from '@angular/core'; } from '@angular/core';
@@ -50,7 +51,8 @@ let nextGroupId = 0;
[attr.aria-describedby]="resolvedDescribedBy()" [attr.aria-describedby]="resolvedDescribedBy()"
[attr.aria-invalid]="showInvalid() ? 'true' : null" [attr.aria-invalid]="showInvalid() ? 'true' : null"
[attr.aria-readonly]="readonly() ? 'true' : null" [attr.aria-readonly]="readonly() ? 'true' : null"
[attr.aria-busy]="pending() ? 'true' : null"> [attr.aria-busy]="pending() ? 'true' : null"
(focusout)="markTouchedWhenFocusLeavesGroup($event)">
@for (option of options(); track option.value; let i = $index) { @for (option of options(); track option.value; let i = $index) {
<label appControlTransition [class]="variant() === 'segmented' ? segmentClass(i) : optionClass()"> <label appControlTransition [class]="variant() === 'segmented' ? segmentClass(i) : optionClass()">
<input <input
@@ -61,8 +63,7 @@ let nextGroupId = 0;
[checked]="isSelected(option)" [checked]="isSelected(option)"
[disabled]="isUnavailable() || option.disabled === true" [disabled]="isUnavailable() || option.disabled === true"
[required]="required()" [required]="required()"
(change)="onSelect(option)" (change)="onSelect(option)" />
(blur)="touched.set(true)" />
@if (variant() === 'segmented') { @if (variant() === 'segmented') {
@if (option.icon; as optionIcon) { @if (option.icon; as optionIcon) {
<svg [lucideIcon]="optionIcon" [class]="segmentIconClass" aria-hidden="true"></svg> <svg [lucideIcon]="optionIcon" [class]="segmentIconClass" aria-hidden="true"></svg>
@@ -89,7 +90,8 @@ export class AppRadioGroupComponent<T> implements FormValueControl<T | null> {
readonly pending = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute });
readonly required = input(false, { transform: booleanAttribute }); readonly required = input(false, { transform: booleanAttribute });
readonly readonly = input(false, { transform: booleanAttribute }); readonly readonly = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly options = input<readonly RadioOption<T>[]>([]); readonly options = input<readonly RadioOption<T>[]>([]);
@@ -155,6 +157,13 @@ export class AppRadioGroupComponent<T> implements FormValueControl<T | null> {
this.value.set(option.value); this.value.set(option.value);
} }
protected markTouchedWhenFocusLeavesGroup(event: FocusEvent): void {
const control = event.currentTarget;
const next = event.relatedTarget;
if (control instanceof HTMLElement && next instanceof Node && control.contains(next)) return;
this.touch.emit();
}
focus(options?: FocusOptions): void { focus(options?: FocusOptions): void {
const optionIndex = this.options().findIndex(option => this.isSelected(option) && !option.disabled); const optionIndex = this.options().findIndex(option => this.isSelected(option) && !option.disabled);
const fallbackIndex = this.options().findIndex(option => !option.disabled); const fallbackIndex = this.options().findIndex(option => !option.disabled);
@@ -7,6 +7,7 @@ import {
input, input,
model, model,
numberAttribute, numberAttribute,
output,
signal, signal,
type ElementRef, type ElementRef,
viewChild, viewChild,
@@ -75,7 +76,8 @@ interface Star {
[style.--star-size-coarse]="starSizeCoarse()" [style.--star-size-coarse]="starSizeCoarse()"
(pointerdown)="onPointerDown($event)" (pointerdown)="onPointerDown($event)"
(pointerenter)="onEnter($event)" (pointerenter)="onEnter($event)"
(pointerleave)="onLeave($event)"> (pointerleave)="onLeave($event)"
(focusout)="markTouchedAndCollapseWhenFocusLeavesControl($event)">
<input <input
#input #input
type="range" type="range"
@@ -93,9 +95,7 @@ interface Star {
[attr.aria-invalid]="showInvalid() ? 'true' : null" [attr.aria-invalid]="showInvalid() ? 'true' : null"
[attr.aria-busy]="pending() ? 'true' : null" [attr.aria-busy]="pending() ? 'true' : null"
[attr.aria-valuetext]="valueText()" [attr.aria-valuetext]="valueText()"
(input)="onRange(input.value)" (input)="onRange(input.value)" />
(change)="touched.set(true)"
(blur)="onRangeBlur()" />
@for (star of starList(); track $index) { @for (star of starList(); track $index) {
<button <button
type="button" type="button"
@@ -227,7 +227,8 @@ export class AppRatingComponent implements FormValueControl<number> {
readonly required = input(false, { transform: booleanAttribute }); readonly required = input(false, { transform: booleanAttribute });
readonly invalid = input(false, { transform: booleanAttribute }); readonly invalid = input(false, { transform: booleanAttribute });
readonly pending = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly inputId = input(''); readonly inputId = input('');
readonly ariaLabel = input(''); readonly ariaLabel = input('');
@@ -305,8 +306,11 @@ export class AppRatingComponent implements FormValueControl<number> {
this.value.set(Math.max(0, Math.min(this.stars(), nextValue))); this.value.set(Math.max(0, Math.min(this.stars(), nextValue)));
} }
protected onRangeBlur(): void { protected markTouchedAndCollapseWhenFocusLeavesControl(event: FocusEvent): void {
this.touched.set(true); const control = event.currentTarget;
const next = event.relatedTarget;
if (control instanceof HTMLElement && next instanceof Node && control.contains(next)) return;
this.touch.emit();
this.collapse(); this.collapse();
} }
@@ -331,7 +335,6 @@ export class AppRatingComponent implements FormValueControl<number> {
protected onStarClick(value: number): void { protected onStarClick(value: number): void {
if (this.disabled()) return; if (this.disabled()) return;
this.touched.set(true);
if (this.expandable() && !this.isExpanded()) { if (this.expandable() && !this.isExpanded()) {
this.expanded.set(true); this.expanded.set(true);
@@ -6,7 +6,7 @@ import {
model, model,
} from '@angular/core'; } from '@angular/core';
import { type FormValueControl } from '@angular/forms/signals'; import { type FormValueControl } from '@angular/forms/signals';
import { Combobox, ComboboxInput, ComboboxPopupContainer } from '@angular/aria/combobox'; import { Combobox, ComboboxPopup, ComboboxWidget } from '@angular/aria/combobox';
import { Listbox, Option } from '@angular/aria/listbox'; import { Listbox, Option } from '@angular/aria/listbox';
import { OverlayModule } from '@angular/cdk/overlay'; import { OverlayModule } from '@angular/cdk/overlay';
import { TranslocoPipe, translateSignal } from '@jsverse/transloco'; import { TranslocoPipe, translateSignal } from '@jsverse/transloco';
@@ -24,8 +24,8 @@ import { type SelectOption } from './app-select.options';
NgTemplateOutlet, NgTemplateOutlet,
OverlayModule, OverlayModule,
Combobox, Combobox,
ComboboxInput, ComboboxPopup,
ComboboxPopupContainer, ComboboxWidget,
Listbox, Listbox,
Option, Option,
TranslocoPipe, TranslocoPipe,
@@ -39,35 +39,26 @@ import { type SelectOption } from './app-select.options';
host: { class: 'block w-full' }, host: { class: 'block w-full' },
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
template: ` template: `
<div ngCombobox #cb="ngCombobox" [readonly]="true" [disabled]="disabled()" class="relative block h-full w-full"> <div #controlRoot class="relative block h-full w-full" (focusout)="markTouchedWhenFocusLeavesControl($event)">
<div <div
ngCombobox
#cb="ngCombobox"
appControlTransition appControlTransition
#origin #origin
[class]="triggerClass()" [class]="triggerClass()"
[attr.data-expanded]="cb.expanded() ? 'true' : null"> [attr.data-expanded]="cb.expanded() ? 'true' : null"
<input [attr.id]="resolvedInputId()"
ngComboboxInput [attr.name]="name() || null"
#input [attr.aria-label]="ariaLabel() || null"
readonly [attr.aria-labelledby]="ariaLabelledBy() || null"
type="text" [attr.aria-invalid]="showInvalid() ? 'true' : null"
autocomplete="off" [attr.aria-busy]="pending() ? 'true' : null"
spellcheck="false" [attr.aria-required]="required() ? 'true' : null"
[value]="triggerLabel()" [attr.aria-describedby]="resolvedDescribedBy()"
[attr.id]="resolvedInputId()" [readonly]="readonly()"
[attr.name]="name() || null" [disabled]="disabled()"
[attr.aria-label]="ariaLabel() || null" (expandedChange)="onExpandedChange($event)">
[attr.aria-labelledby]="ariaLabelledBy() || null" <span [class]="labelClass()" [class.text-text-muted]="!hasSelection()">
[attr.aria-invalid]="showInvalid() ? 'true' : null"
[attr.aria-readonly]="readonly() ? 'true' : null"
[attr.aria-busy]="pending() ? 'true' : null"
[attr.aria-describedby]="resolvedDescribedBy()"
[disabled]="disabled()"
[required]="required()"
(keydown)="onTriggerKeydown($event)"
(blur)="onTriggerBlur($event)"
class="absolute inset-0 z-10 h-full w-full cursor-pointer rounded-md border-0 bg-transparent p-0 text-transparent caret-transparent outline-hidden disabled:cursor-default" />
<span aria-hidden="true" [class]="labelClass()" [class.text-text-muted]="!hasSelection()">
{{ triggerLabel() }} {{ triggerLabel() }}
</span> </span>
@@ -90,7 +81,7 @@ import { type SelectOption } from './app-select.options';
</span> </span>
</div> </div>
<ng-template ngComboboxPopupContainer> <ng-template ngComboboxPopup [combobox]="cb" [popupType]="filter() ? 'dialog' : 'listbox'">
<ng-template <ng-template
[cdkConnectedOverlay]="{ [cdkConnectedOverlay]="{
origin, origin,
@@ -102,64 +93,134 @@ import { type SelectOption } from './app-select.options';
}" }"
[cdkConnectedOverlayOpen]="cb.expanded()" [cdkConnectedOverlayOpen]="cb.expanded()"
[cdkConnectedOverlayScrollStrategy]="overlayScrollStrategy" [cdkConnectedOverlayScrollStrategy]="overlayScrollStrategy"
(overlayOutsideClick)="closePopup()"
(attach)="onOverlayAttach()"> (attach)="onOverlayAttach()">
<div [class]="surfaceClass"> @if (filter()) {
@if (filter()) { <div
ngComboboxWidget
role="dialog"
[attr.aria-label]="filterPlaceholder() || ('shared.ui.select.search' | transloco)"
[class]="surfaceClass"
(keydown.escape)="closePopup()"
(focusout)="markTouchedWhenFocusLeavesControl($event)">
<div [class]="filterRowClass"> <div [class]="filterRowClass">
<input <input
#filterInput ngCombobox
#filterCombobox="ngCombobox"
type="text" type="text"
autocomplete="off"
spellcheck="false"
alwaysExpanded
[value]="filterText()" [value]="filterText()"
(input)="filterText.set(filterInput.value)" (valueChange)="filterText.set($event)"
(keydown)="onFilterKeydown($event)"
[placeholder]="filterPlaceholder() || ('shared.ui.select.search' | transloco)" [placeholder]="filterPlaceholder() || ('shared.ui.select.search' | transloco)"
[readonly]="readonly()" [readonly]="readonly()"
[disabled]="disabled()"
[class]="filterInputClass" /> [class]="filterInputClass" />
<svg lucideSearch class="size-4 shrink-0" aria-hidden="true"></svg> <svg lucideSearch class="size-4 shrink-0" aria-hidden="true"></svg>
</div> </div>
}
<ul <ng-template ngComboboxPopup [combobox]="filterCombobox">
ngListbox <ul
tabindex="-1" ngComboboxWidget
focusMode="activedescendant" ngListbox
selectionMode="explicit" #list="ngListbox"
[multi]="true" tabindex="-1"
[values]="listboxValues()" focusMode="activedescendant"
[readonly]="readonly()" selectionMode="explicit"
[disabled]="disabled()" [multi]="true"
(valuesChange)="onValuesChange($event)" [value]="listboxValues()"
[class]="listClass()"> [activeDescendant]="list.activeDescendant()"
@for (grp of renderedGroups(); track grp.trackKey; let first = $first) { [readonly]="readonly()"
@if (grouped()) { [disabled]="disabled()"
@if (!first) { (valueChange)="onValuesChange($event)"
<li role="separator" [class]="separatorClass"></li> [class]="listClass()">
} @for (grp of renderedGroups(); track grp.trackKey; let first = $first) {
<li role="presentation" [class]="sectionClass">{{ grp.label }}</li> @if (grouped()) {
} @if (!first) {
@for (option of grp.options; track option) { <li role="separator" [class]="separatorClass"></li>
<li }
ngOption <li role="presentation" [class]="sectionClass">{{ grp.label }}</li>
tabindex="-1"
[value]="option.value"
[label]="option.label"
[disabled]="option.disabled === true"
[class]="optionClass">
<span [class]="checkboxClass(isSelected(option))">
@if (isSelected(option)) { <svg lucideCheck class="size-3 text-white" aria-hidden="true"></svg> }
</span>
@if (optionTemplate(); as tpl) {
<ng-container [ngTemplateOutlet]="tpl.template" [ngTemplateOutletContext]="{ $implicit: option }" />
} @else {
<span class="truncate leading-5">{{ option.label }}</span>
} }
</li> @for (option of grp.options; track option) {
<li
ngOption
tabindex="-1"
[value]="option.value"
[label]="option.label"
[disabled]="option.disabled === true"
[class]="optionClass">
<span [class]="checkboxClass(isSelected(option))">
@if (isSelected(option)) {
<svg lucideCheck class="size-3 text-white" aria-hidden="true"></svg>
}
</span>
@if (optionTemplate(); as tpl) {
<ng-container
[ngTemplateOutlet]="tpl.template"
[ngTemplateOutletContext]="{ $implicit: option }" />
} @else {
<span class="truncate leading-5">{{ option.label }}</span>
}
</li>
}
} @empty {
<li [class]="emptyClass">{{ emptyMessage() || ('shared.ui.select.noResults' | transloco) }}</li>
}
</ul>
</ng-template>
</div>
} @else {
<div [class]="surfaceClass" (focusout)="markTouchedWhenFocusLeavesControl($event)">
<ul
ngComboboxWidget
ngListbox
#list="ngListbox"
tabindex="-1"
focusMode="activedescendant"
selectionMode="explicit"
[multi]="true"
[value]="listboxValues()"
[activeDescendant]="list.activeDescendant()"
[readonly]="readonly()"
[disabled]="disabled()"
(valueChange)="onValuesChange($event)"
[class]="listClass()">
@for (grp of renderedGroups(); track grp.trackKey; let first = $first) {
@if (grouped()) {
@if (!first) {
<li role="separator" [class]="separatorClass"></li>
}
<li role="presentation" [class]="sectionClass">{{ grp.label }}</li>
}
@for (option of grp.options; track option) {
<li
ngOption
tabindex="-1"
[value]="option.value"
[label]="option.label"
[disabled]="option.disabled === true"
[class]="optionClass">
<span [class]="checkboxClass(isSelected(option))">
@if (isSelected(option)) {
<svg lucideCheck class="size-3 text-white" aria-hidden="true"></svg>
}
</span>
@if (optionTemplate(); as tpl) {
<ng-container
[ngTemplateOutlet]="tpl.template"
[ngTemplateOutletContext]="{ $implicit: option }" />
} @else {
<span class="truncate leading-5">{{ option.label }}</span>
}
</li>
}
} @empty {
<li [class]="emptyClass">{{ emptyMessage() || ('shared.ui.select.noResults' | transloco) }}</li>
} }
} @empty { </ul>
<li [class]="emptyClass">{{ emptyMessage() || ('shared.ui.select.noResults' | transloco) }}</li> </div>
} }
</ul>
</div>
</ng-template> </ng-template>
</ng-template> </ng-template>
</div> </div>
@@ -186,7 +247,6 @@ export class AppMultiSelectComponent<T> extends AppSelectBaseDirective<T> implem
protected override onValuesChange(values: readonly T[]): void { protected override onValuesChange(values: readonly T[]): void {
if (this.isUnavailable()) return; if (this.isUnavailable()) return;
this.touched.set(true);
const hiddenSelections = this.value().filter((selectedValue) => !this.isVisibleValue(selectedValue)); const hiddenSelections = this.value().filter((selectedValue) => !this.isVisibleValue(selectedValue));
this.value.set([...hiddenSelections, ...values]); this.value.set([...hiddenSelections, ...values]);
} }
@@ -6,7 +6,6 @@ import {
inject, inject,
input, input,
linkedSignal, linkedSignal,
model,
output, output,
type ElementRef, type ElementRef,
type Signal, type Signal,
@@ -40,7 +39,6 @@ import {
import { AppSelectOptionTemplateDirective } from './app-select.templates'; import { AppSelectOptionTemplateDirective } from './app-select.templates';
import { type SelectCompareWith, type SelectOption, type SelectOptionGroup } from './app-select.options'; import { type SelectCompareWith, type SelectOption, type SelectOptionGroup } from './app-select.options';
const FILTER_TEXT_EDITING_KEYS = new Set([' ', 'Spacebar', 'Backspace', 'Delete', 'Home', 'End']);
const defaultCompareWith = <T>(optionValue: T, selectedValue: T): boolean => Object.is(optionValue, selectedValue); const defaultCompareWith = <T>(optionValue: T, selectedValue: T): boolean => Object.is(optionValue, selectedValue);
const UNGROUPED_GROUP_TRACK_KEY = Symbol('app-select-ungrouped'); const UNGROUPED_GROUP_TRACK_KEY = Symbol('app-select-ungrouped');
@@ -55,7 +53,8 @@ export abstract class AppSelectBaseDirective<T> {
readonly invalid = input(false, { transform: booleanAttribute }); readonly invalid = input(false, { transform: booleanAttribute });
readonly pending = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute });
readonly readonly = input(false, { transform: booleanAttribute }); readonly readonly = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly size = input<AppSelectSize>('md'); readonly size = input<AppSelectSize>('md');
@@ -87,7 +86,7 @@ export abstract class AppSelectBaseDirective<T> {
private readonly overlayService = inject(Overlay); private readonly overlayService = inject(Overlay);
private readonly combobox = viewChild(Combobox); private readonly combobox = viewChild(Combobox);
private readonly overlay = viewChild(CdkConnectedOverlay); private readonly overlay = viewChild(CdkConnectedOverlay);
private readonly input = viewChild<ElementRef<HTMLInputElement>>('input'); private readonly controlRoot = viewChild<ElementRef<HTMLElement>>('controlRoot');
protected readonly optionTemplate = contentChild(AppSelectOptionTemplateDirective); protected readonly optionTemplate = contentChild(AppSelectOptionTemplateDirective);
protected readonly resolvedInputId = computed(() => this.inputId() || this.fieldContext?.controlId() || null); protected readonly resolvedInputId = computed(() => this.inputId() || this.fieldContext?.controlId() || null);
@@ -172,37 +171,23 @@ export abstract class AppSelectBaseDirective<T> {
computation: (expanded, previous) => (expanded ? (previous?.value ?? '') : ''), computation: (expanded, previous) => (expanded ? (previous?.value ?? '') : ''),
}); });
protected onTriggerKeydown(event: KeyboardEvent): void { protected closePopup(): void {
const combobox = this.combobox(); this.combobox()?.expanded.set(false);
if (this.isUnavailable() || !combobox || combobox.expanded()) return;
if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp' && event.key !== 'Enter' && event.key !== ' ') return;
event.preventDefault();
event.stopPropagation();
combobox.open();
} }
protected onFilterKeydown(event: KeyboardEvent): void { protected onExpandedChange(expanded: boolean): void {
if (event.key === 'Escape' || event.key === 'Enter' || event.key === 'Tab' || event.key.startsWith('Arrow')) return; if (!expanded) this.filterText.set('');
if (event.key.length === 1 || event.ctrlKey || event.metaKey || FILTER_TEXT_EDITING_KEYS.has(event.key)) {
event.stopPropagation();
}
} }
protected onTriggerBlur(event: FocusEvent): void { protected markTouchedWhenFocusLeavesControl(event: FocusEvent): void {
if (this.isUnavailable()) return; if (this.isUnavailable() || this.focusRemainsInControl(event.relatedTarget)) return;
const relatedTarget = event.relatedTarget; this.touch.emit();
const overlayElement = this.overlay()?.overlayRef?.overlayElement;
if (relatedTarget instanceof Node && overlayElement?.contains(relatedTarget)) return;
this.touched.set(true);
} }
protected clear(event: MouseEvent): void { protected clear(event: MouseEvent): void {
event.stopPropagation(); event.stopPropagation();
if (this.isUnavailable()) return; if (this.isUnavailable()) return;
this.clearValue(); this.clearValue();
this.touched.set(true);
this.cleared.emit(); this.cleared.emit();
} }
@@ -213,6 +198,13 @@ export abstract class AppSelectBaseDirective<T> {
return option.label.toLowerCase().includes(query); return option.label.toLowerCase().includes(query);
} }
private focusRemainsInControl(target: EventTarget | null): boolean {
if (!(target instanceof Node)) return false;
const controlRoot = this.controlRoot()?.nativeElement;
const overlayElement = this.overlay()?.overlayRef?.overlayElement;
return controlRoot?.contains(target) === true || overlayElement?.contains(target) === true;
}
protected valuesMatch(optionValue: T, selectedValue: T): boolean { protected valuesMatch(optionValue: T, selectedValue: T): boolean {
return this.compareWith()(optionValue, selectedValue); return this.compareWith()(optionValue, selectedValue);
} }
@@ -245,6 +237,6 @@ export abstract class AppSelectBaseDirective<T> {
} }
focus(options?: FocusOptions): void { focus(options?: FocusOptions): void {
this.input()?.nativeElement.focus(options); this.combobox()?.element.focus(options);
} }
} }
@@ -7,7 +7,7 @@ import {
model, model,
} from '@angular/core'; } from '@angular/core';
import { type FormValueControl } from '@angular/forms/signals'; import { type FormValueControl } from '@angular/forms/signals';
import { Combobox, ComboboxInput, ComboboxPopupContainer } from '@angular/aria/combobox'; import { Combobox, ComboboxPopup, ComboboxWidget } from '@angular/aria/combobox';
import { Listbox, Option } from '@angular/aria/listbox'; import { Listbox, Option } from '@angular/aria/listbox';
import { OverlayModule } from '@angular/cdk/overlay'; import { OverlayModule } from '@angular/cdk/overlay';
import { TranslocoPipe } from '@jsverse/transloco'; import { TranslocoPipe } from '@jsverse/transloco';
@@ -25,8 +25,8 @@ import { type SelectOption } from './app-select.options';
NgTemplateOutlet, NgTemplateOutlet,
OverlayModule, OverlayModule,
Combobox, Combobox,
ComboboxInput, ComboboxPopup,
ComboboxPopupContainer, ComboboxWidget,
Listbox, Listbox,
Option, Option,
TranslocoPipe, TranslocoPipe,
@@ -40,35 +40,26 @@ import { type SelectOption } from './app-select.options';
host: { class: 'block w-full' }, host: { class: 'block w-full' },
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
template: ` template: `
<div ngCombobox #cb="ngCombobox" [readonly]="true" [disabled]="disabled()" class="relative block h-full w-full"> <div #controlRoot class="relative block h-full w-full" (focusout)="markTouchedWhenFocusLeavesControl($event)">
<div <div
ngCombobox
#cb="ngCombobox"
appControlTransition appControlTransition
#origin #origin
[class]="triggerClass()" [class]="triggerClass()"
[attr.data-expanded]="cb.expanded() ? 'true' : null"> [attr.data-expanded]="cb.expanded() ? 'true' : null"
<input [attr.id]="resolvedInputId()"
ngComboboxInput [attr.name]="name() || null"
#input [attr.aria-label]="ariaLabel() || null"
readonly [attr.aria-labelledby]="ariaLabelledBy() || null"
type="text" [attr.aria-invalid]="showInvalid() ? 'true' : null"
autocomplete="off" [attr.aria-busy]="pending() ? 'true' : null"
spellcheck="false" [attr.aria-required]="required() ? 'true' : null"
[value]="triggerLabel()" [attr.aria-describedby]="resolvedDescribedBy()"
[attr.id]="resolvedInputId()" [readonly]="readonly()"
[attr.name]="name() || null" [disabled]="disabled()"
[attr.aria-label]="ariaLabel() || null" (expandedChange)="onExpandedChange($event)">
[attr.aria-labelledby]="ariaLabelledBy() || null" <span [class]="labelClass()" [class.text-text-muted]="!hasSelection()">
[attr.aria-invalid]="showInvalid() ? 'true' : null"
[attr.aria-readonly]="readonly() ? 'true' : null"
[attr.aria-busy]="pending() ? 'true' : null"
[attr.aria-describedby]="resolvedDescribedBy()"
[disabled]="disabled()"
[required]="required()"
(keydown)="onTriggerKeydown($event)"
(blur)="onTriggerBlur($event)"
class="absolute inset-0 z-10 h-full w-full cursor-pointer rounded-md border-0 bg-transparent p-0 text-transparent caret-transparent outline-hidden disabled:cursor-default" />
<span aria-hidden="true" [class]="labelClass()" [class.text-text-muted]="!hasSelection()">
@if (selectedTemplate(); as tpl) { @if (selectedTemplate(); as tpl) {
@if (selectedOption(); as opt) { @if (selectedOption(); as opt) {
<ng-container [ngTemplateOutlet]="tpl.template" [ngTemplateOutletContext]="{ $implicit: opt }" /> <ng-container [ngTemplateOutlet]="tpl.template" [ngTemplateOutletContext]="{ $implicit: opt }" />
@@ -99,7 +90,7 @@ import { type SelectOption } from './app-select.options';
</span> </span>
</div> </div>
<ng-template ngComboboxPopupContainer> <ng-template ngComboboxPopup [combobox]="cb" [popupType]="filter() ? 'dialog' : 'listbox'">
<ng-template <ng-template
[cdkConnectedOverlay]="{ [cdkConnectedOverlay]="{
origin, origin,
@@ -111,63 +102,128 @@ import { type SelectOption } from './app-select.options';
}" }"
[cdkConnectedOverlayOpen]="cb.expanded()" [cdkConnectedOverlayOpen]="cb.expanded()"
[cdkConnectedOverlayScrollStrategy]="overlayScrollStrategy" [cdkConnectedOverlayScrollStrategy]="overlayScrollStrategy"
(overlayOutsideClick)="closePopup()"
(attach)="onOverlayAttach()"> (attach)="onOverlayAttach()">
<div [class]="surfaceClass"> @if (filter()) {
@if (filter()) { <div
ngComboboxWidget
role="dialog"
[attr.aria-label]="filterPlaceholder() || ('shared.ui.select.search' | transloco)"
[class]="surfaceClass"
(keydown.escape)="closePopup()"
(focusout)="markTouchedWhenFocusLeavesControl($event)">
<div [class]="filterRowClass"> <div [class]="filterRowClass">
<input <input
#filterInput ngCombobox
#filterCombobox="ngCombobox"
type="text" type="text"
autocomplete="off"
spellcheck="false"
alwaysExpanded
[value]="filterText()" [value]="filterText()"
(input)="filterText.set(filterInput.value)" (valueChange)="filterText.set($event)"
(keydown)="onFilterKeydown($event)"
[placeholder]="filterPlaceholder() || ('shared.ui.select.search' | transloco)" [placeholder]="filterPlaceholder() || ('shared.ui.select.search' | transloco)"
[readonly]="readonly()" [readonly]="readonly()"
[disabled]="disabled()"
[class]="filterInputClass" /> [class]="filterInputClass" />
<svg lucideSearch class="size-4 shrink-0" aria-hidden="true"></svg> <svg lucideSearch class="size-4 shrink-0" aria-hidden="true"></svg>
</div> </div>
}
<ul <ng-template ngComboboxPopup [combobox]="filterCombobox">
ngListbox <ul
tabindex="-1" ngComboboxWidget
focusMode="activedescendant" ngListbox
selectionMode="explicit" #list="ngListbox"
[values]="listboxValues()" tabindex="-1"
[readonly]="readonly()" focusMode="activedescendant"
[disabled]="disabled()" selectionMode="explicit"
(valuesChange)="onValuesChange($event)" [value]="listboxValues()"
[class]="listClass()"> [activeDescendant]="list.activeDescendant()"
@for (grp of renderedGroups(); track grp.trackKey; let first = $first) { [readonly]="readonly()"
@if (grouped()) { [disabled]="disabled()"
@if (!first) { (valueChange)="onValuesChange($event)"
<li role="separator" [class]="separatorClass"></li> [class]="listClass()">
@for (grp of renderedGroups(); track grp.trackKey; let first = $first) {
@if (grouped()) {
@if (!first) {
<li role="separator" [class]="separatorClass"></li>
}
<li role="presentation" [class]="sectionClass">{{ grp.label }}</li>
}
@for (option of grp.options; track option) {
<li
ngOption
tabindex="-1"
[value]="option.value"
[label]="option.label"
[disabled]="option.disabled === true"
[class]="optionClass">
@if (optionTemplate(); as tpl) {
<ng-container
[ngTemplateOutlet]="tpl.template"
[ngTemplateOutletContext]="{ $implicit: option }" />
} @else {
<span class="truncate leading-5">{{ option.label }}</span>
}
@if (isSelected(option)) {
<svg lucideCheck class="order-last ml-auto size-4 shrink-0 text-primary" aria-hidden="true"></svg>
}
</li>
}
} @empty {
<li [class]="emptyClass">{{ emptyMessage() || ('shared.ui.select.noResults' | transloco) }}</li>
} }
<li role="presentation" [class]="sectionClass">{{ grp.label }}</li> </ul>
} </ng-template>
@for (option of grp.options; track option) { </div>
<li } @else {
ngOption <div [class]="surfaceClass" (focusout)="markTouchedWhenFocusLeavesControl($event)">
tabindex="-1" <ul
[value]="option.value" ngComboboxWidget
[label]="option.label" ngListbox
[disabled]="option.disabled === true" #list="ngListbox"
[class]="optionClass"> tabindex="-1"
@if (optionTemplate(); as tpl) { focusMode="activedescendant"
<ng-container [ngTemplateOutlet]="tpl.template" [ngTemplateOutletContext]="{ $implicit: option }" /> selectionMode="explicit"
} @else { [value]="listboxValues()"
<span class="truncate leading-5">{{ option.label }}</span> [activeDescendant]="list.activeDescendant()"
[readonly]="readonly()"
[disabled]="disabled()"
(valueChange)="onValuesChange($event)"
[class]="listClass()">
@for (grp of renderedGroups(); track grp.trackKey; let first = $first) {
@if (grouped()) {
@if (!first) {
<li role="separator" [class]="separatorClass"></li>
} }
@if (isSelected(option)) { <li role="presentation" [class]="sectionClass">{{ grp.label }}</li>
<svg lucideCheck class="order-last ml-auto size-4 shrink-0 text-primary" aria-hidden="true"></svg> }
} @for (option of grp.options; track option) {
</li> <li
ngOption
tabindex="-1"
[value]="option.value"
[label]="option.label"
[disabled]="option.disabled === true"
[class]="optionClass">
@if (optionTemplate(); as tpl) {
<ng-container
[ngTemplateOutlet]="tpl.template"
[ngTemplateOutletContext]="{ $implicit: option }" />
} @else {
<span class="truncate leading-5">{{ option.label }}</span>
}
@if (isSelected(option)) {
<svg lucideCheck class="order-last ml-auto size-4 shrink-0 text-primary" aria-hidden="true"></svg>
}
</li>
}
} @empty {
<li [class]="emptyClass">{{ emptyMessage() || ('shared.ui.select.noResults' | transloco) }}</li>
} }
} @empty { </ul>
<li [class]="emptyClass">{{ emptyMessage() || ('shared.ui.select.noResults' | transloco) }}</li> </div>
} }
</ul>
</div>
</ng-template> </ng-template>
</ng-template> </ng-template>
</div> </div>
@@ -196,16 +252,17 @@ export class AppSelectComponent<T> extends AppSelectBaseDirective<T> implements
protected override onValuesChange(values: readonly T[]): void { protected override onValuesChange(values: readonly T[]): void {
if (this.isUnavailable()) return; if (this.isUnavailable()) return;
this.touched.set(true);
if (values.length) { if (values.length) {
this.value.set(values[values.length - 1]); this.value.set(values[values.length - 1]);
this.closePopup();
return; return;
} }
const current = this.value(); const current = this.value();
if (current != null && !this.isVisibleValue(current)) return; if (current != null && !this.isVisibleValue(current)) return;
this.value.set(null); this.value.set(null);
this.closePopup();
} }
protected override clearValue(): void { protected override clearValue(): void {
@@ -6,6 +6,7 @@ import {
inject, inject,
input, input,
model, model,
output,
numberAttribute, numberAttribute,
type ElementRef, type ElementRef,
viewChild, viewChild,
@@ -44,7 +45,7 @@ import { AppControlTransitionDirective, invisibleControlInputClass, neutralContr
[required]="required()" [required]="required()"
[attr.aria-readonly]="readonly() ? 'true' : null" [attr.aria-readonly]="readonly() ? 'true' : null"
(input)="onInput(input.value)" (input)="onInput(input.value)"
(change)="touched.set(true)" /> (blur)="touch.emit()" />
<div class="pointer-events-none absolute inset-x-0 h-1.5 rounded-full bg-border"></div> <div class="pointer-events-none absolute inset-x-0 h-1.5 rounded-full bg-border"></div>
<div class="pointer-events-none absolute left-0 h-1.5 rounded-full bg-primary" [style.width]="thumbPosition"></div> <div class="pointer-events-none absolute left-0 h-1.5 rounded-full bg-primary" [style.width]="thumbPosition"></div>
@@ -62,7 +63,8 @@ export class AppSliderComponent implements FormValueControl<number> {
readonly invalid = input(false, { transform: booleanAttribute }); readonly invalid = input(false, { transform: booleanAttribute });
readonly pending = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute });
readonly readonly = input(false, { transform: booleanAttribute }); readonly readonly = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly min = input<number | undefined>(undefined); readonly min = input<number | undefined>(undefined);
@@ -6,6 +6,7 @@ import {
inject, inject,
input, input,
model, model,
output,
type ElementRef, type ElementRef,
viewChild, viewChild,
} from '@angular/core'; } from '@angular/core';
@@ -45,7 +46,7 @@ import {
[disabled]="isUnavailable()" [disabled]="isUnavailable()"
[required]="required()" [required]="required()"
(change)="onInputChange(control.checked)" (change)="onInputChange(control.checked)"
(blur)="touched.set(true)" /> (blur)="touch.emit()" />
<span appControlTransition [class]="trackClass()" aria-hidden="true"></span> <span appControlTransition [class]="trackClass()" aria-hidden="true"></span>
<span appControlTransition [class]="thumbClass()" aria-hidden="true"></span> <span appControlTransition [class]="thumbClass()" aria-hidden="true"></span>
</span> </span>
@@ -58,7 +59,8 @@ export class AppSwitchComponent implements FormCheckboxControl {
readonly invalid = input(false, { transform: booleanAttribute }); readonly invalid = input(false, { transform: booleanAttribute });
readonly pending = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute });
readonly readonly = input(false, { transform: booleanAttribute }); readonly readonly = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly size = input<AppSwitchSize>('md'); readonly size = input<AppSwitchSize>('md');
@@ -3,17 +3,21 @@ import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
Component, Component,
computed, computed,
contentChildren,
DestroyRef, DestroyRef,
Directive,
ElementRef, ElementRef,
inject, inject,
input, input,
model, model,
signal, signal,
TemplateRef,
untracked, untracked,
viewChild, viewChild,
viewChildren, viewChildren,
} from '@angular/core'; } from '@angular/core';
import { Tab as NgTab, TabList, Tabs } from '@angular/aria/tabs'; import { NgTemplateOutlet } from '@angular/common';
import { Tab as NgTab, TabContent, TabList, TabPanel, Tabs } from '@angular/aria/tabs';
import { LucideDynamicIcon, type LucideIconData } from '@lucide/angular'; import { LucideDynamicIcon, type LucideIconData } from '@lucide/angular';
import { AppSelectComponent } from '../select/app-select.component'; import { AppSelectComponent } from '../select/app-select.component';
import { type SelectOption } from '../select/app-select.options'; import { type SelectOption } from '../select/app-select.options';
@@ -43,10 +47,29 @@ const TAB_ICON_SIZE_CLASS: Record<TabsSize, string> = {
const COLLAPSE_HYSTERESIS = 8; const COLLAPSE_HYSTERESIS = 8;
@Directive({
selector: 'ng-template[appTabPanel]',
standalone: true,
})
export class AppTabPanelDirective {
readonly value = input.required<string>({ alias: 'appTabPanel' });
readonly templateRef = inject<TemplateRef<unknown>>(TemplateRef);
}
@Component({ @Component({
selector: 'app-tabs', selector: 'app-tabs',
standalone: true, standalone: true,
imports: [Tabs, TabList, NgTab, AppSelectComponent, LucideDynamicIcon, AppControlTransitionDirective], imports: [
Tabs,
TabList,
NgTab,
TabPanel,
TabContent,
NgTemplateOutlet,
AppSelectComponent,
LucideDynamicIcon,
AppControlTransitionDirective,
],
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'relative block min-w-0' }, host: { class: 'relative block min-w-0' },
template: ` template: `
@@ -59,34 +82,46 @@ const COLLAPSE_HYSTERESIS = 8;
(valueChange)="selectTab($event)" (valueChange)="selectTab($event)"
[ariaLabel]="ariaLabel()" /> [ariaLabel]="ariaLabel()" />
} }
<div <div ngTabs>
data-tabs-row <div
[class]="rowClass()" data-tabs-row
[attr.aria-hidden]="collapsed() ? 'true' : null" [class]="rowClass()"
[attr.inert]="collapsed() ? '' : null"> [attr.aria-hidden]="collapsed() ? 'true' : null"
<div ngTabs [class]="rootClass()"> [attr.inert]="collapsed() ? '' : null">
<div <div [class]="rootClass()">
#tabList <div
ngTabList #tabList
[class]="listClass()" ngTabList
[selectedTab]="activeTabId()" [class]="listClass()"
(selectedTabChange)="selectTab($event)" [selectedTab]="activeTabId()"
[attr.aria-label]="ariaLabel()"> (selectedTabChange)="selectTab($event)"
<span [attr.aria-label]="ariaLabel()">
aria-hidden="true" <span
[class]="indicatorClass()" aria-hidden="true"
[style.transform]="'translateX(' + indicatorLeft() + 'px)'" [class]="indicatorClass()"
[style.width.px]="indicatorWidth()"></span> [style.transform]="'translateX(' + indicatorLeft() + 'px)'"
@for (tab of tabs(); track tab.id) { [style.width.px]="indicatorWidth()"></span>
<button appControlTransition ngTab type="button" [value]="tab.id" [class]="tabClass()"> @for (tab of tabs(); track tab.id) {
@if (tab.icon; as tabIcon) { <button appControlTransition ngTab type="button" [value]="tab.id" [class]="tabClass()">
<svg [lucideIcon]="tabIcon" [class]="tabIconClass()" aria-hidden="true"></svg> @if (tab.icon; as tabIcon) {
} <svg [lucideIcon]="tabIcon" [class]="tabIconClass()" aria-hidden="true"></svg>
<span class="leading-5">{{ tab.label }}</span> }
</button> <span class="leading-5">{{ tab.label }}</span>
} </button>
}
</div>
</div> </div>
</div> </div>
@for (tab of tabs(); track tab.id) {
<div ngTabPanel [value]="tab.id" class="inert:hidden">
<ng-template ngTabContent>
@if (tabPanelTemplate(tab.id); as template) {
<ng-container [ngTemplateOutlet]="template" />
}
</ng-template>
</div>
}
</div> </div>
} }
`, `,
@@ -100,6 +135,8 @@ export class AppTabsComponent {
readonly ariaLabel = input.required<string>(); readonly ariaLabel = input.required<string>();
readonly selectedTabId = model<string | undefined>(undefined); readonly selectedTabId = model<string | undefined>(undefined);
protected readonly tabPanels = contentChildren(AppTabPanelDirective);
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef); private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
private readonly destroyRef = inject(DestroyRef); private readonly destroyRef = inject(DestroyRef);
private readonly tabDirectives = viewChildren(NgTab); private readonly tabDirectives = viewChildren(NgTab);
@@ -164,6 +201,10 @@ export class AppTabsComponent {
this.selectedTabId.set(this.resolveTabId(value ?? undefined)); this.selectedTabId.set(this.resolveTabId(value ?? undefined));
} }
protected tabPanelTemplate(value: string): TemplateRef<unknown> | undefined {
return this.tabPanels().find((panel) => panel.value() === value)?.templateRef;
}
private measureLayout(): void { private measureLayout(): void {
this.measure(); this.measure();
this.measureFit(); this.measureFit();
@@ -7,6 +7,7 @@ import {
inject, inject,
input, input,
model, model,
output,
type ElementRef, type ElementRef,
viewChild, viewChild,
} from '@angular/core'; } from '@angular/core';
@@ -45,7 +46,7 @@ import { appTextareaVariants } from './app-textarea.variants';
[readonly]="readonly()" [readonly]="readonly()"
[required]="required()" [required]="required()"
(input)="onInput(textarea)" (input)="onInput(textarea)"
(blur)="touched.set(true)"></textarea> (blur)="touch.emit()"></textarea>
@if (pending()) { @if (pending()) {
<span class="pointer-events-none absolute right-3 top-2.5 inline-flex text-text-muted"> <span class="pointer-events-none absolute right-3 top-2.5 inline-flex text-text-muted">
<svg lucideLoaderCircle class="size-4 animate-spin" aria-hidden="true"></svg> <svg lucideLoaderCircle class="size-4 animate-spin" aria-hidden="true"></svg>
@@ -59,7 +60,8 @@ export class AppTextareaComponent implements FormValueControl<string> {
readonly required = input(false, { transform: booleanAttribute }); readonly required = input(false, { transform: booleanAttribute });
readonly invalid = input(false, { transform: booleanAttribute }); readonly invalid = input(false, { transform: booleanAttribute });
readonly pending = input(false, { transform: booleanAttribute }); readonly pending = input(false, { transform: booleanAttribute });
readonly touched = model(false); readonly touched = input(false, { transform: booleanAttribute });
readonly touch = output<void>();
readonly name = input(''); readonly name = input('');
readonly inputId = input(''); readonly inputId = input('');
+2 -2
View File
@@ -1,4 +1,4 @@
import { provideHttpClient, withInterceptors } from '@angular/common/http'; import { provideHttpClient, withInterceptors, withXhr } from '@angular/common/http';
import { ErrorHandler, inject, isDevMode, provideAppInitializer, provideZonelessChangeDetection } from '@angular/core'; import { ErrorHandler, inject, isDevMode, provideAppInitializer, provideZonelessChangeDetection } from '@angular/core';
import { DialogService } from '@openng/optimus-ui/dynamicdialog'; import { DialogService } from '@openng/optimus-ui/dynamicdialog';
import { ConfirmationService, MessageService } from '@openng/optimus-ui/api'; import { ConfirmationService, MessageService } from '@openng/optimus-ui/api';
@@ -43,7 +43,7 @@ bootstrapApplication(AppComponent, {
const startup = inject(StartupService); const startup = inject(StartupService);
return Promise.resolve(initializeAuth()).then(() => startup.load()); return Promise.resolve(initializeAuth()).then(() => startup.load());
}), }),
provideHttpClient(withInterceptors([AuthInterceptorService])), provideHttpClient(withXhr(), withInterceptors([AuthInterceptorService])),
provideRouter(routes), provideRouter(routes),
DialogService, DialogService,
MessageService, MessageService,
+7 -1
View File
@@ -23,6 +23,12 @@
"enableI18nLegacyMessageIdFormat": false, "enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true, "strictInjectionParameters": true,
"strictInputAccessModifiers": true, "strictInputAccessModifiers": true,
"strictTemplates": true "strictTemplates": true,
"extendedDiagnostics": {
"checks": {
"nullishCoalescingNotNullable": "suppress",
"optionalChainNotNullable": "suppress"
}
}
} }
} }
+1873 -2108
View File
File diff suppressed because it is too large Load Diff