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