@anglr/select 16.0.3 → 16.0.4-beta.20260511085948
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/angular-developer/SKILL.md +130 -0
- package/.claude/skills/angular-developer/references/angular-animations.md +160 -0
- package/.claude/skills/angular-developer/references/angular-aria.md +410 -0
- package/.claude/skills/angular-developer/references/cli.md +86 -0
- package/.claude/skills/angular-developer/references/component-harnesses.md +59 -0
- package/.claude/skills/angular-developer/references/component-styling.md +91 -0
- package/.claude/skills/angular-developer/references/components.md +117 -0
- package/.claude/skills/angular-developer/references/creating-services.md +97 -0
- package/.claude/skills/angular-developer/references/data-resolvers.md +69 -0
- package/.claude/skills/angular-developer/references/define-routes.md +67 -0
- package/.claude/skills/angular-developer/references/defining-providers.md +72 -0
- package/.claude/skills/angular-developer/references/di-fundamentals.md +120 -0
- package/.claude/skills/angular-developer/references/e2e-testing.md +66 -0
- package/.claude/skills/angular-developer/references/effects.md +83 -0
- package/.claude/skills/angular-developer/references/hierarchical-injectors.md +43 -0
- package/.claude/skills/angular-developer/references/host-elements.md +80 -0
- package/.claude/skills/angular-developer/references/injection-context.md +63 -0
- package/.claude/skills/angular-developer/references/inputs.md +101 -0
- package/.claude/skills/angular-developer/references/linked-signal.md +59 -0
- package/.claude/skills/angular-developer/references/loading-strategies.md +61 -0
- package/.claude/skills/angular-developer/references/mcp.md +106 -0
- package/.claude/skills/angular-developer/references/migrations.md +30 -0
- package/.claude/skills/angular-developer/references/navigate-to-routes.md +69 -0
- package/.claude/skills/angular-developer/references/outputs.md +86 -0
- package/.claude/skills/angular-developer/references/reactive-forms.md +122 -0
- package/.claude/skills/angular-developer/references/rendering-strategies.md +44 -0
- package/.claude/skills/angular-developer/references/resource.md +77 -0
- package/.claude/skills/angular-developer/references/route-animations.md +56 -0
- package/.claude/skills/angular-developer/references/route-guards.md +52 -0
- package/.claude/skills/angular-developer/references/router-lifecycle.md +45 -0
- package/.claude/skills/angular-developer/references/router-testing.md +87 -0
- package/.claude/skills/angular-developer/references/show-routes-with-outlets.md +68 -0
- package/.claude/skills/angular-developer/references/signal-forms.md +897 -0
- package/.claude/skills/angular-developer/references/signals-overview.md +94 -0
- package/.claude/skills/angular-developer/references/tailwind-css.md +69 -0
- package/.claude/skills/angular-developer/references/template-driven-forms.md +114 -0
- package/.claude/skills/angular-developer/references/testing-fundamentals.md +66 -0
- package/.github/instructions/typescript/code-conventions.md +8 -0
- package/.github/instructions/typescript/comments.md +41 -0
- package/.github/instructions/typescript/formatting.md +42 -0
- package/.github/instructions/typescript/naming-conventions.md +7 -0
- package/.github/instructions/typescript.instructions.md +26 -0
- package/package.json +1 -1
- package/readme.md +1288 -99
- package/version.bak +1 -1
- package/.github/copilot-instructions.md +0 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: angular-developer
|
|
3
|
+
description: Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: Copyright 2026 Google LLC
|
|
7
|
+
version: '1.0'
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Angular Developer Guidelines
|
|
11
|
+
|
|
12
|
+
1. Always analyze the project's Angular version before providing guidance, as best practices and available features can vary significantly between versions. If creating a new project with Angular CLI, do not specify a version unless prompted by the user.
|
|
13
|
+
|
|
14
|
+
2. When generating code, follow Angular's style guide and best practices for maintainability and performance. Use the Angular CLI for scaffolding components, services, directives, pipes, and routes to ensure consistency.
|
|
15
|
+
|
|
16
|
+
3. Once you finish generating code, run `ng build` to ensure there are no build errors. If there are errors, analyze the error messages and fix them before proceeding. Do not skip this step, as it is critical for ensuring the generated code is correct and functional.
|
|
17
|
+
|
|
18
|
+
## Creating New Projects
|
|
19
|
+
|
|
20
|
+
If no guidelines are provided by the user, here are same default rules to follow when creating a new Angular project:
|
|
21
|
+
|
|
22
|
+
1. Use the latest stable version of Angular unless the user specifies otherwise.
|
|
23
|
+
2. Use Signals Forms for form management in new projects (available in Angular v21 and newer) [Find out more](references/signal-forms.md).
|
|
24
|
+
|
|
25
|
+
**Execution Rules for `ng new`:**
|
|
26
|
+
When asked to create a new Angular project, you must determine the correct execution command by following these strict steps:
|
|
27
|
+
|
|
28
|
+
**Step 1: Check for an explicit user version.**
|
|
29
|
+
|
|
30
|
+
- **IF** the user requests a specific version (e.g., Angular 15), bypass local installations and strictly use `npx`.
|
|
31
|
+
- **Command:** `npx @angular/cli@<requested_version> new <project-name>`
|
|
32
|
+
|
|
33
|
+
**Step 2: Check for an existing Angular installation.**
|
|
34
|
+
|
|
35
|
+
- **IF** no specific version is requested, run `ng version` in the terminal to check if the Angular CLI is already installed on the system.
|
|
36
|
+
- **IF** the command succeeds and returns an installed version, use the local/global installation directly.
|
|
37
|
+
- **Command:** `ng new <project-name>`
|
|
38
|
+
|
|
39
|
+
**Step 3: Fallback to Latest.**
|
|
40
|
+
|
|
41
|
+
- **IF** no specific version is requested AND the `ng version` command fails (indicating no Angular installation exists), you must use `npx` to fetch the latest version.
|
|
42
|
+
- **Command:** `npx @angular/cli@latest new <project-name>`
|
|
43
|
+
|
|
44
|
+
## Components
|
|
45
|
+
|
|
46
|
+
When working with Angular components, consult the following references based on the task:
|
|
47
|
+
|
|
48
|
+
- **Fundamentals**: Anatomy, metadata, core concepts, and template control flow (@if, @for, @switch). Read [components.md](references/components.md)
|
|
49
|
+
- **Inputs**: Signal-based inputs, transforms, and model inputs. Read [inputs.md](references/inputs.md)
|
|
50
|
+
- **Outputs**: Signal-based outputs and custom event best practices. Read [outputs.md](references/outputs.md)
|
|
51
|
+
- **Host Elements**: Host bindings and attribute injection. Read [host-elements.md](references/host-elements.md)
|
|
52
|
+
|
|
53
|
+
If you require deeper documentation not found in the references above, read the documentation at `https://angular.dev/guide/components`.
|
|
54
|
+
|
|
55
|
+
## Reactivity and Data Management
|
|
56
|
+
|
|
57
|
+
When managing state and data reactivity, use Angular Signals and consult the following references:
|
|
58
|
+
|
|
59
|
+
- **Signals Overview**: Core signal concepts (`signal`, `computed`), reactive contexts, and `untracked`. Read [signals-overview.md](references/signals-overview.md)
|
|
60
|
+
- **Dependent State (`linkedSignal`)**: Creating writable state linked to source signals. Read [linked-signal.md](references/linked-signal.md)
|
|
61
|
+
- **Async Reactivity (`resource`)**: Fetching asynchronous data directly into signal state. Read [resource.md](references/resource.md)
|
|
62
|
+
- **Side Effects (`effect`)**: Logging, third-party DOM manipulation (`afterRenderEffect`), and when NOT to use effects. Read [effects.md](references/effects.md)
|
|
63
|
+
|
|
64
|
+
## Forms
|
|
65
|
+
|
|
66
|
+
In most cases for new apps, **prefer signal forms**. When making a forms decision, analyze the project and consider the following guidelines:
|
|
67
|
+
|
|
68
|
+
- if the application is using v21 or newer and this is a new form, **prefer signal forms**.
|
|
69
|
+
-For older applications or when working with existing forms, use the appropriate form type that matches the applications current form strategy.
|
|
70
|
+
|
|
71
|
+
- **Signal Forms**: Use signals for form state management. Read [signal-forms.md](references/signal-forms.md)
|
|
72
|
+
- **Template-driven forms**: Use for simple forms. Read [template-driven-forms.md](references/template-driven-forms.md)
|
|
73
|
+
- **Reactive forms**: Use for complex forms. Read [reactive-forms.md](references/reactive-forms.md)
|
|
74
|
+
|
|
75
|
+
## Dependency Injection
|
|
76
|
+
|
|
77
|
+
When implementing dependency injection in Angular, follow these guidelines:
|
|
78
|
+
|
|
79
|
+
- **Fundamentals**: Overview of Dependency Injection, services, and the `inject()` function. Read [di-fundamentals.md](references/di-fundamentals.md)
|
|
80
|
+
- **Creating and Using Services**: Creating services, the `providedIn: 'root'` option, and injecting into components or other services. Read [creating-services.md](references/creating-services.md)
|
|
81
|
+
- **Defining Dependency Providers**: Automatic vs manual provision, `InjectionToken`, `useClass`, `useValue`, `useFactory`, and scopes. Read [defining-providers.md](references/defining-providers.md)
|
|
82
|
+
- **Injection Context**: Where `inject()` is allowed, `runInInjectionContext`, and `assertInInjectionContext`. Read [injection-context.md](references/injection-context.md)
|
|
83
|
+
- **Hierarchical Injectors**: The `EnvironmentInjector` vs `ElementInjector`, resolution rules, modifiers (`optional`, `skipSelf`), and `providers` vs `viewProviders`. Read [hierarchical-injectors.md](references/hierarchical-injectors.md)
|
|
84
|
+
|
|
85
|
+
## Angular Aria
|
|
86
|
+
|
|
87
|
+
When building accessible custom components for any of the following patterns: Accordion, Listbox, Combobox, Menu, Tabs, Toolbar, Tree, Grid, consult the following reference:
|
|
88
|
+
|
|
89
|
+
- **Angular Aria Components**: Building headless, accessible components (Accordion, Listbox, Combobox, Menu, Tabs, Toolbar, Tree, Grid) and styling ARIA attributes. Read [angular-aria.md](references/angular-aria.md)
|
|
90
|
+
|
|
91
|
+
## Routing
|
|
92
|
+
|
|
93
|
+
When implementing navigation in Angular, consult the following references:
|
|
94
|
+
|
|
95
|
+
- **Define Routes**: URL paths, static vs dynamic segments, wildcards, and redirects. Read [define-routes.md](references/define-routes.md)
|
|
96
|
+
- **Route Loading Strategies**: Eager vs lazy loading, and context-aware loading. Read [loading-strategies.md](references/loading-strategies.md)
|
|
97
|
+
- **Show Routes with Outlets**: Using `<router-outlet>`, nested outlets, and named outlets. Read [show-routes-with-outlets.md](references/show-routes-with-outlets.md)
|
|
98
|
+
- **Navigate to Routes**: Declarative navigation with `RouterLink` and programmatic navigation with `Router`. Read [navigate-to-routes.md](references/navigate-to-routes.md)
|
|
99
|
+
- **Control Route Access with Guards**: Implementing `CanActivate`, `CanMatch`, and other guards for security. Read [route-guards.md](references/route-guards.md)
|
|
100
|
+
- **Data Resolvers**: Pre-fetching data before route activation with `ResolveFn`. Read [data-resolvers.md](references/data-resolvers.md)
|
|
101
|
+
- **Router Lifecycle and Events**: Chronological order of navigation events and debugging. Read [router-lifecycle.md](references/router-lifecycle.md)
|
|
102
|
+
- **Rendering Strategies**: CSR, SSG (Prerendering), and SSR with hydration. Read [rendering-strategies.md](references/rendering-strategies.md)
|
|
103
|
+
- **Route Transition Animations**: Enabling and customizing the View Transitions API. Read [route-animations.md](references/route-animations.md)
|
|
104
|
+
|
|
105
|
+
If you require deeper documentation or more context, visit the [official Angular Routing guide](https://angular.dev/guide/routing).
|
|
106
|
+
|
|
107
|
+
## Styling and Animations
|
|
108
|
+
|
|
109
|
+
When implementing styling and animations in Angular, consult the following references:
|
|
110
|
+
|
|
111
|
+
- **Using Tailwind CSS with Angular**: Integrating Tailwind CSS into Angular projects. Read [tailwind-css.md](references/tailwind-css.md)
|
|
112
|
+
- **Angular Animations**: Using native CSS (recommended) or the legacy DSL for dynamic effects. Read [angular-animations.md](references/angular-animations.md)
|
|
113
|
+
- **Styling components**: Best practices for component styles and encapsulation. Read [component-styling.md](references/component-styling.md)
|
|
114
|
+
|
|
115
|
+
## Testing
|
|
116
|
+
|
|
117
|
+
When writing or updating tests, consult the following references based on the task:
|
|
118
|
+
|
|
119
|
+
- **Fundamentals**: Best practices for unit testing (Vitest), async patterns, and `TestBed`. Read [testing-fundamentals.md](references/testing-fundamentals.md)
|
|
120
|
+
- **Component Harnesses**: Standard patterns for robust component interaction. Read [component-harnesses.md](references/component-harnesses.md)
|
|
121
|
+
- **Router Testing**: Using `RouterTestingHarness` for reliable navigation tests. Read [router-testing.md](references/router-testing.md)
|
|
122
|
+
- **End-to-End (E2E) Testing**: Best practices for E2E tests with Cypress. Read [e2e-testing.md](references/e2e-testing.md)
|
|
123
|
+
|
|
124
|
+
## Tooling
|
|
125
|
+
|
|
126
|
+
When working with Angular tooling, consult the following references:
|
|
127
|
+
|
|
128
|
+
- **Angular CLI**: Creating applications, generating code (components, routes, services), serving, and building. Read [cli.md](references/cli.md)
|
|
129
|
+
- **Code Modernization**: Automatically refactoring to modern standards using migrations. Read [migrations.md](references/migrations.md)
|
|
130
|
+
- **Angular MCP Server**: Available tools, configuration, and experimental features. Read [mcp.md](references/mcp.md)
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Angular Animations
|
|
2
|
+
|
|
3
|
+
When animating elements in Angular, **first analyze the project's Angular version** in `package.json`.
|
|
4
|
+
For modern applications (**Angular v20.2 and above**), prefer using native CSS with `animate.enter` and `animate.leave`. For older applications, you may need to use the deprecated `@angular/animations` package.
|
|
5
|
+
|
|
6
|
+
## 1. Native CSS Animations (v20.2+ Recommended)
|
|
7
|
+
|
|
8
|
+
Modern Angular provides `animate.enter` and `animate.leave` to animate elements as they enter or leave the DOM. They apply CSS classes at the appropriate times.
|
|
9
|
+
|
|
10
|
+
### `animate.enter` and `animate.leave`
|
|
11
|
+
|
|
12
|
+
Use these directly on elements to apply CSS classes during the enter or leave phase. Angular automatically removes the enter classes when the animation completes. For `animate.leave`, Angular waits for the animation to finish before removing the element from the DOM.
|
|
13
|
+
|
|
14
|
+
`animate.enter` example:
|
|
15
|
+
|
|
16
|
+
```html
|
|
17
|
+
@if (isShown()) {
|
|
18
|
+
<div class="enter-container" animate.enter="enter-animation">
|
|
19
|
+
<p>The box is entering.</p>
|
|
20
|
+
</div>
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```css
|
|
25
|
+
/* Ensure you have a starting style if using transitions instead of keyframes */
|
|
26
|
+
.enter-container {
|
|
27
|
+
border: 1px solid #dddddd;
|
|
28
|
+
margin-top: 1em;
|
|
29
|
+
padding: 20px;
|
|
30
|
+
font-weight: bold;
|
|
31
|
+
font-size: 20px;
|
|
32
|
+
}
|
|
33
|
+
.enter-container p {
|
|
34
|
+
margin: 0;
|
|
35
|
+
}
|
|
36
|
+
.enter-animation {
|
|
37
|
+
animation: slide-fade 1s;
|
|
38
|
+
}
|
|
39
|
+
@keyframes slide-fade {
|
|
40
|
+
from {
|
|
41
|
+
opacity: 0;
|
|
42
|
+
transform: translateY(20px);
|
|
43
|
+
}
|
|
44
|
+
to {
|
|
45
|
+
opacity: 1;
|
|
46
|
+
transform: translateY(0);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
_Note: `animate.leave` may be added to child elements being removed._
|
|
52
|
+
|
|
53
|
+
### Event Bindings and Third-party Libraries
|
|
54
|
+
|
|
55
|
+
You can bind to `(animate.enter)` and `(animate.leave)` to call functions or use JS libraries like GSAP.
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
@if(show()) {
|
|
59
|
+
<div (animate.leave)="onLeave($event)">...</div>
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { AnimationCallbackEvent } from '@angular/core';
|
|
65
|
+
|
|
66
|
+
onLeave(event: AnimationCallbackEvent) {
|
|
67
|
+
// Custom animation logic here
|
|
68
|
+
// CRITICAL: You MUST call animationComplete() when done so Angular removes the element!
|
|
69
|
+
event.animationComplete();
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 2. Advanced CSS Animations
|
|
74
|
+
|
|
75
|
+
CSS offers robust tools for advanced animation sequences.
|
|
76
|
+
|
|
77
|
+
### Animating State and Styles
|
|
78
|
+
|
|
79
|
+
Toggle CSS classes on elements using property binding to trigger transitions.
|
|
80
|
+
|
|
81
|
+
```html
|
|
82
|
+
<div [class.open]="isOpen">...</div>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```css
|
|
86
|
+
div {
|
|
87
|
+
transition: height 0.3s ease-out;
|
|
88
|
+
height: 100px;
|
|
89
|
+
}
|
|
90
|
+
div.open {
|
|
91
|
+
height: 200px;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Animating Auto Height
|
|
96
|
+
|
|
97
|
+
You can use `css-grid` to animate to auto height.
|
|
98
|
+
|
|
99
|
+
```css
|
|
100
|
+
.container {
|
|
101
|
+
display: grid;
|
|
102
|
+
grid-template-rows: 0fr;
|
|
103
|
+
transition: grid-template-rows 0.3s;
|
|
104
|
+
}
|
|
105
|
+
.container.open {
|
|
106
|
+
grid-template-rows: 1fr;
|
|
107
|
+
}
|
|
108
|
+
.container > div {
|
|
109
|
+
overflow: hidden;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Staggering and Parallel Animations
|
|
114
|
+
|
|
115
|
+
- **Staggering**: Use `animation-delay` or `transition-delay` with different values for items in a list.
|
|
116
|
+
- **Parallel**: Apply multiple animations in the `animation` shorthand (e.g., `animation: rotate 3s, fade-in 2s;`).
|
|
117
|
+
|
|
118
|
+
### Programmatic Control
|
|
119
|
+
|
|
120
|
+
Retrieve animations directly using standard Web APIs:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const animations = element.getAnimations();
|
|
124
|
+
animations.forEach((anim) => anim.pause());
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## 3. Legacy Animations DSL (Deprecated)
|
|
128
|
+
|
|
129
|
+
For older projects (pre v20.2 or where `@angular/animations` is already heavily used), you use the component metadata DSL.
|
|
130
|
+
|
|
131
|
+
**Important:** Do not mix legacy animations and `animate.enter`/`leave` in the same component.
|
|
132
|
+
|
|
133
|
+
### Setup
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
bootstrapApplication(App, {
|
|
137
|
+
providers: [provideAnimationsAsync()],
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Defining Transitions
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import {signal} from '@angular/core';
|
|
145
|
+
import {trigger, state, style, animate, transition} from '@angular/animations';
|
|
146
|
+
|
|
147
|
+
@Component({
|
|
148
|
+
animations: [
|
|
149
|
+
trigger('openClose', [
|
|
150
|
+
state('open', style({opacity: 1})),
|
|
151
|
+
state('closed', style({opacity: 0})),
|
|
152
|
+
transition('open <=> closed', [animate('0.5s')]),
|
|
153
|
+
]),
|
|
154
|
+
],
|
|
155
|
+
template: `<div [@openClose]="isOpen() ? 'open' : 'closed'">...</div>`,
|
|
156
|
+
})
|
|
157
|
+
export class OpenClose {
|
|
158
|
+
isOpen = signal(true);
|
|
159
|
+
}
|
|
160
|
+
```
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
# Angular Aria
|
|
2
|
+
|
|
3
|
+
Angular Aria (`@angular/aria`) is a collection of headless, accessible directives that implement common WAI-ARIA patterns. These directives handle keyboard interactions, ARIA attributes, focus management, and screen reader support.
|
|
4
|
+
|
|
5
|
+
**As an AI Agent, your role is to provide the HTML structure and CSS styling**, while the directives handle the complex accessibility logic.
|
|
6
|
+
|
|
7
|
+
## Styling Headless Components
|
|
8
|
+
|
|
9
|
+
Because Angular Aria components are headless, they do not come with default styles. You **must** use CSS to style different states based on the ARIA attributes or structural classes the directives automatically apply.
|
|
10
|
+
|
|
11
|
+
Common ARIA attributes to target in CSS:
|
|
12
|
+
|
|
13
|
+
- `[aria-expanded="true"]` / `[aria-expanded="false"]`
|
|
14
|
+
- `[aria-selected="true"]`
|
|
15
|
+
- `[aria-disabled="true"]`
|
|
16
|
+
- `[aria-current="page"]` (for navigation)
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
**CRITICAL**: Before using this package, it must be installed via the package manager. Confirm that it has been installed in the project. Use `npm install @angular/aria` to install if necessary.
|
|
21
|
+
|
|
22
|
+
## 1. Accordion
|
|
23
|
+
|
|
24
|
+
Organizes related content into expandable/collapsible sections.
|
|
25
|
+
|
|
26
|
+
**Usage:** The Accordion is a layout component designed to organize content into logical groups that users can expand one at a time to reduce scrolling on content-heavy pages. Use it for FAQs, long forms, or progressive disclosure of information, but avoid it for primary navigation or scenarios where users must view multiple sections of content simultaneously.
|
|
27
|
+
|
|
28
|
+
**Imports:** `import { AccordionContent, AccordionGroup, AccordionPanel, AccordionTrigger } from '@angular/aria/accordion';`
|
|
29
|
+
|
|
30
|
+
**Directives:** `ngAccordionGroup`, `ngAccordionTrigger`, `ngAccordionPanel`, `ngAccordionContent` (for lazy loading).
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
@Component({
|
|
34
|
+
selector: 'app-cmp',
|
|
35
|
+
imports: [AccordionContent, AccordionGroup, AccordionPanel, AccordionTrigger],
|
|
36
|
+
template: `...`,
|
|
37
|
+
styles: [],
|
|
38
|
+
})
|
|
39
|
+
export class App {
|
|
40
|
+
protected readonly title = signal('angular-app');
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<div ngAccordionGroup [multiExpandable]="false">
|
|
46
|
+
<div class="accordion-item">
|
|
47
|
+
<button ngAccordionTrigger panelId="panel-1" class="accordion-header">
|
|
48
|
+
Section 1
|
|
49
|
+
<span class="icon">▼</span>
|
|
50
|
+
</button>
|
|
51
|
+
<div ngAccordionPanel panelId="panel-1" class="accordion-panel">
|
|
52
|
+
<ng-template ngAccordionContent>
|
|
53
|
+
<p>Lazy loaded content here.</p>
|
|
54
|
+
</ng-template>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Styling Strategy:**
|
|
61
|
+
Target the `[aria-expanded]` attribute on the trigger to rotate icons, and style the panel visibility.
|
|
62
|
+
|
|
63
|
+
```css
|
|
64
|
+
.accordion-header[aria-expanded='true'] .icon {
|
|
65
|
+
transform: rotate(180deg);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* The panel directive handles DOM removal, but you can style the transition */
|
|
69
|
+
.accordion-panel {
|
|
70
|
+
padding: 1rem;
|
|
71
|
+
border-top: 1px solid #ccc;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 2. Listbox
|
|
78
|
+
|
|
79
|
+
A foundational directive for displaying a list of options. Used for visible selection lists (not dropdowns).
|
|
80
|
+
|
|
81
|
+
**Usage:** Visible selectable lists (single or multi-select).
|
|
82
|
+
|
|
83
|
+
**Imports:** `import {Listbox, Option} from '@angular/aria/listbox';`
|
|
84
|
+
|
|
85
|
+
**Directives:** `ngListbox`, `ngOption`.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
@Component({
|
|
89
|
+
selector: 'app-cmp',
|
|
90
|
+
imports: [Listbox, Option],
|
|
91
|
+
template: `...`,
|
|
92
|
+
styles: [],
|
|
93
|
+
})
|
|
94
|
+
export class App {
|
|
95
|
+
protected readonly title = signal('angular-app');
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```html
|
|
100
|
+
<!-- horizontal or vertical orientation -->
|
|
101
|
+
<ul ngListbox [(values)]="selectedItems" orientation="horizontal" [multi]="true">
|
|
102
|
+
<li ngOption value="apple" class="option">Apple</li>
|
|
103
|
+
<li ngOption value="banana" class="option">Banana</li>
|
|
104
|
+
</ul>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Styling Strategy:**
|
|
108
|
+
Target `[aria-selected="true"]` for selected state and `:focus-visible` or `[data-active]` for the focused item (Angular Aria uses roving tabindex or activedescendant).
|
|
109
|
+
|
|
110
|
+
```css
|
|
111
|
+
.option {
|
|
112
|
+
padding: 8px;
|
|
113
|
+
cursor: pointer;
|
|
114
|
+
}
|
|
115
|
+
.option[aria-selected='true'] {
|
|
116
|
+
background: #e0f7fa;
|
|
117
|
+
font-weight: bold;
|
|
118
|
+
}
|
|
119
|
+
/* Focus state managed by aria */
|
|
120
|
+
.option:focus-visible {
|
|
121
|
+
outline: 2px solid blue;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 3. Combobox, Select, and Multiselect
|
|
128
|
+
|
|
129
|
+
These patterns combine `ngCombobox` with a popup containing an `ngListbox`.
|
|
130
|
+
|
|
131
|
+
- **Combobox**: Text input + popup (used for Autocomplete).
|
|
132
|
+
- **Select**: Readonly Combobox + single-select Listbox.
|
|
133
|
+
- **Multiselect**: Readonly Combobox + multi-select Listbox.
|
|
134
|
+
|
|
135
|
+
**Usage:** The Combobox is a low-level primitive directive that synchronizes a text input with a popup, serving as the foundational logic for autocomplete, select, and multiselect patterns. Use it specifically for building custom filtering, unique selection requirements, or specialized input-to-popup coordination that deviates from standard, documented components.
|
|
136
|
+
|
|
137
|
+
**Imports:**
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
import {Combobox, ComboboxInput, ComboboxPopupContainer} from '@angular/aria/combobox';
|
|
141
|
+
import {Listbox, Option} from '@angular/aria/listbox';
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Directives:** `ngCombobox`, `ngComboboxInput`, `ngComboboxPopupContainer`, `ngListbox`, `ngOption`.
|
|
145
|
+
|
|
146
|
+
```html
|
|
147
|
+
<!-- Example: Standard Select -->
|
|
148
|
+
<div ngCombobox [readonly]="true">
|
|
149
|
+
<button ngComboboxInput class="select-trigger">
|
|
150
|
+
{{ selectedValue() || 'Choose an option' }}
|
|
151
|
+
</button>
|
|
152
|
+
|
|
153
|
+
<ng-template ngComboboxPopupContainer>
|
|
154
|
+
<ul ngListbox [(values)]="selectedValue" class="dropdown-menu">
|
|
155
|
+
<li ngOption value="option1">Option 1</li>
|
|
156
|
+
<li ngOption value="option2">Option 2</li>
|
|
157
|
+
</ul>
|
|
158
|
+
</ng-template>
|
|
159
|
+
</div>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Styling Strategy:**
|
|
163
|
+
Style the popup container to look like a dropdown floating above content (often paired with CDK Overlay).
|
|
164
|
+
|
|
165
|
+
```css
|
|
166
|
+
.select-trigger {
|
|
167
|
+
width: 200px;
|
|
168
|
+
padding: 8px;
|
|
169
|
+
text-align: left;
|
|
170
|
+
}
|
|
171
|
+
.dropdown-menu {
|
|
172
|
+
list-style: none;
|
|
173
|
+
padding: 0;
|
|
174
|
+
margin: 0;
|
|
175
|
+
border: 1px solid #ccc;
|
|
176
|
+
background: white;
|
|
177
|
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## 4. Menu and Menubar
|
|
184
|
+
|
|
185
|
+
For actions, commands, and context menus (not for form selection).
|
|
186
|
+
|
|
187
|
+
**Usage:** The Menubar is a high-level navigation pattern designed for building desktop-style application command bars (e.g., File, Edit, View) that stay persistent across an interface. It is best utilized for organizing complex commands into logical top-level categories with full horizontal keyboard support, but it should be avoided for simple standalone action lists or mobile-first layouts where horizontal space is constrained.
|
|
188
|
+
|
|
189
|
+
**Imports:** `import {MenuBar, Menu, MenuContent, MenuItem} from '@angular/aria/menu';`
|
|
190
|
+
|
|
191
|
+
**Directives:** `ngMenuBar`, `ngMenu`, `ngMenuItem`, `ngMenuTrigger`.
|
|
192
|
+
|
|
193
|
+
```html
|
|
194
|
+
<!-- Menubar Example -->
|
|
195
|
+
<ul ngMenuBar class="menubar">
|
|
196
|
+
<li ngMenuItem value="file">
|
|
197
|
+
<button ngMenuTrigger [menu]="fileMenu">File</button>
|
|
198
|
+
</li>
|
|
199
|
+
</ul>
|
|
200
|
+
|
|
201
|
+
<ul ngMenu #fileMenu="ngMenu" class="menu">
|
|
202
|
+
<li ngMenuItem value="new">New</li>
|
|
203
|
+
<li ngMenuItem value="open">Open</li>
|
|
204
|
+
</ul>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Styling Strategy:**
|
|
208
|
+
Use flexbox for the menubar. Hide/show submenus based on the trigger's state.
|
|
209
|
+
|
|
210
|
+
```css
|
|
211
|
+
.menubar {
|
|
212
|
+
display: flex;
|
|
213
|
+
gap: 10px;
|
|
214
|
+
list-style: none;
|
|
215
|
+
padding: 0;
|
|
216
|
+
}
|
|
217
|
+
.menu {
|
|
218
|
+
background: white;
|
|
219
|
+
border: 1px solid #ccc;
|
|
220
|
+
padding: 5px 0;
|
|
221
|
+
}
|
|
222
|
+
.menu li {
|
|
223
|
+
padding: 5px 15px;
|
|
224
|
+
cursor: pointer;
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## 5. Tabs
|
|
231
|
+
|
|
232
|
+
Layered content sections where only one panel is visible.
|
|
233
|
+
|
|
234
|
+
**Usage:** The Tabs component is used to organize related content into distinct, navigable sections, allowing users to switch between categories or views without leaving the page. It is ideal for settings panels, multi-topic documentation, or dashboards, but should be avoided for sequential workflows (steppers) or when navigation involves more than 7–8 sections.
|
|
235
|
+
|
|
236
|
+
**Imports:** `import {Tab, Tabs, TabList, TabPanel, TabContent} from '@angular/aria/tabs';`
|
|
237
|
+
|
|
238
|
+
**Directives:** `ngTabs`, `ngTabList`, `ngTab`, `ngTabPanel`, `ngTabContent`.
|
|
239
|
+
|
|
240
|
+
```html
|
|
241
|
+
<div ngTabs>
|
|
242
|
+
<ul ngTabList class="tab-list">
|
|
243
|
+
<li ngTab value="profile" class="tab-btn">Profile</li>
|
|
244
|
+
<li ngTab value="security" class="tab-btn">Security</li>
|
|
245
|
+
</ul>
|
|
246
|
+
|
|
247
|
+
<div ngTabPanel value="profile" class="tab-panel">
|
|
248
|
+
<ng-template ngTabContent>Profile Settings</ng-template>
|
|
249
|
+
</div>
|
|
250
|
+
<div ngTabPanel value="security" class="tab-panel">
|
|
251
|
+
<ng-template ngTabContent>Security Settings</ng-template>
|
|
252
|
+
</div>
|
|
253
|
+
</div>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Styling Strategy:**
|
|
257
|
+
Target `[aria-selected="true"]` on the tab buttons.
|
|
258
|
+
|
|
259
|
+
```css
|
|
260
|
+
.tab-list {
|
|
261
|
+
display: flex;
|
|
262
|
+
border-bottom: 2px solid #ccc;
|
|
263
|
+
list-style: none;
|
|
264
|
+
padding: 0;
|
|
265
|
+
}
|
|
266
|
+
.tab-btn {
|
|
267
|
+
padding: 10px 20px;
|
|
268
|
+
cursor: pointer;
|
|
269
|
+
border-bottom: 2px solid transparent;
|
|
270
|
+
}
|
|
271
|
+
.tab-btn[aria-selected='true'] {
|
|
272
|
+
border-bottom-color: blue;
|
|
273
|
+
font-weight: bold;
|
|
274
|
+
}
|
|
275
|
+
.tab-panel {
|
|
276
|
+
padding: 20px;
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## 6. Toolbar
|
|
283
|
+
|
|
284
|
+
Groups related controls (like text formatting).
|
|
285
|
+
|
|
286
|
+
**Usage:** The Toolbar is an organizational component designed to group frequently accessed, related controls into a single logical container. It is best used to enhance keyboard efficiency (via arrow-key navigation) and visual structure for workflows requiring repeated actions, such as text formatting or media controls.
|
|
287
|
+
|
|
288
|
+
**Imports:** `import {Toolbar, ToolbarWidget, ToolbarWidgetGroup} from '@angular/aria/toolbar';`
|
|
289
|
+
|
|
290
|
+
**Directives:** `ngToolbar`, `ngToolbarWidget`, `ngToolbarWidgetGroup`.
|
|
291
|
+
|
|
292
|
+
```html
|
|
293
|
+
<div ngToolbar class="toolbar">
|
|
294
|
+
<div ngToolbarWidgetGroup [multi]="true" role="group" aria-label="Formatting">
|
|
295
|
+
<button ngToolbarWidget value="bold" class="tool-btn">B</button>
|
|
296
|
+
<button ngToolbarWidget value="italic" class="tool-btn">I</button>
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
**Styling Strategy:**
|
|
302
|
+
Target `[aria-pressed="true"]` (for toggle buttons) or `[aria-checked="true"]` (for radio groups) within the toolbar.
|
|
303
|
+
|
|
304
|
+
```css
|
|
305
|
+
.toolbar {
|
|
306
|
+
display: flex;
|
|
307
|
+
gap: 5px;
|
|
308
|
+
padding: 8px;
|
|
309
|
+
background: #f5f5f5;
|
|
310
|
+
}
|
|
311
|
+
.tool-btn {
|
|
312
|
+
padding: 5px 10px;
|
|
313
|
+
border: 1px solid #ccc;
|
|
314
|
+
}
|
|
315
|
+
.tool-btn[aria-pressed='true'],
|
|
316
|
+
.tool-btn[aria-checked='true'] {
|
|
317
|
+
background: #ddd;
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
## 7. Tree
|
|
324
|
+
|
|
325
|
+
Displays hierarchical data (file systems, nested nav).
|
|
326
|
+
|
|
327
|
+
**Usage:** The Tree component is designed for navigating and displaying deeply nested, hierarchical data structures like file systems, organization charts, or complex site architectures. It should be used specifically for multi-level relationships where users need to expand or collapse branches, but it should be avoided for flat lists, data tables, or simple selection menus.
|
|
328
|
+
|
|
329
|
+
**Imports:** `import {Tree, TreeItem, TreeItemGroup} from '@angular/aria/tree';`
|
|
330
|
+
|
|
331
|
+
**Directives:** `ngTree`, `ngTreeItem`, `ngTreeGroup`.
|
|
332
|
+
|
|
333
|
+
```html
|
|
334
|
+
<ul ngTree class="tree">
|
|
335
|
+
<li ngTreeItem value="documents">
|
|
336
|
+
<span class="tree-label">Documents</span>
|
|
337
|
+
<ul ngTreeGroup class="tree-group">
|
|
338
|
+
<li ngTreeItem value="resume">Resume.pdf</li>
|
|
339
|
+
</ul>
|
|
340
|
+
</li>
|
|
341
|
+
</ul>
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**Styling Strategy:**
|
|
345
|
+
Target `[aria-expanded]` to show/hide children or rotate chevron icons. Use `padding-left` on nested groups to show hierarchy.
|
|
346
|
+
|
|
347
|
+
```css
|
|
348
|
+
.tree,
|
|
349
|
+
.tree-group {
|
|
350
|
+
list-style: none;
|
|
351
|
+
padding-left: 20px;
|
|
352
|
+
}
|
|
353
|
+
.tree-label::before {
|
|
354
|
+
content: '▶ ';
|
|
355
|
+
display: inline-block;
|
|
356
|
+
transition: transform 0.2s;
|
|
357
|
+
}
|
|
358
|
+
li[aria-expanded='true'] > .tree-label::before {
|
|
359
|
+
transform: rotate(90deg);
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## 8. Grid
|
|
364
|
+
|
|
365
|
+
A two-dimensional interactive collection of cells enabling navigation via arrow keys.
|
|
366
|
+
|
|
367
|
+
**Usage:** Data tables, calendars, spreadsheets, and layout patterns for interactive elements.
|
|
368
|
+
**Directives:** `ngGrid`, `ngGridRow`, `ngGridCell`, `ngGridCellWidget`.
|
|
369
|
+
|
|
370
|
+
```html
|
|
371
|
+
<table ngGrid [multi]="true" [enableSelection]="true" class="grid-table">
|
|
372
|
+
<tr ngGridRow>
|
|
373
|
+
<th ngGridCell role="columnheader">Name</th>
|
|
374
|
+
<th ngGridCell role="columnheader">Status</th>
|
|
375
|
+
</tr>
|
|
376
|
+
<tr ngGridRow>
|
|
377
|
+
<td ngGridCell>Project A</td>
|
|
378
|
+
<td ngGridCell [(selected)]="isSelected">
|
|
379
|
+
<button ngGridCellWidget (activated)="onActivate()">Active</button>
|
|
380
|
+
</td>
|
|
381
|
+
</tr>
|
|
382
|
+
</table>
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**Styling Strategy:**
|
|
386
|
+
Target `[aria-selected="true"]` for selected cells and `:focus-visible` for the active cell (roving tabindex) or `[aria-activedescendant]` on the container.
|
|
387
|
+
|
|
388
|
+
```css
|
|
389
|
+
.grid-table {
|
|
390
|
+
border-collapse: collapse;
|
|
391
|
+
}
|
|
392
|
+
[ngGridCell] {
|
|
393
|
+
padding: 8px;
|
|
394
|
+
border: 1px solid #ddd;
|
|
395
|
+
}
|
|
396
|
+
[ngGridCell][aria-selected='true'] {
|
|
397
|
+
background: #e3f2fd;
|
|
398
|
+
}
|
|
399
|
+
/* Focus state managed by roving tabindex */
|
|
400
|
+
[ngGridCell]:focus-visible {
|
|
401
|
+
outline: 2px solid #2196f3;
|
|
402
|
+
outline-offset: -2px;
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
## General Rules for Agents
|
|
407
|
+
|
|
408
|
+
1. **Never use native HTML elements like `<select>`** when asked to implement these specific Aria patterns. Use the `ng*` directives.
|
|
409
|
+
2. **Handle CSS manually**: Remember that `Angular Aria` does NOT provide styles. You must write the CSS, targeting the native ARIA attributes (`aria-expanded`, `aria-selected`, etc.) that the directives automatically toggle.
|
|
410
|
+
3. **Lazy Loading**: Always use the provided structural directives (`ngAccordionContent`, `ngTabContent`) inside `ng-template` for heavy content panels to ensure they are lazily rendered.
|