@creatio-devkit/common 0.832.1 → 0.833.0

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.
@@ -0,0 +1,1002 @@
1
+ # WCAG Accessibility Requirements for AI Agents (v1.0)
2
+
3
+ **ATTENTION AI AGENT:** This is a mandatory directive for generating accessible components. Follow rules exactly.
4
+
5
+ **Audience:** AI assistant generating Creatio Freedom UI components (runtime and design-time).
6
+
7
+ **Scope:** WCAG 2.2 Level AA compliance for component-level development.
8
+
9
+ **Reference:** [Accessibility DoD](https://creatio.atlassian.net/wiki/spaces/TER/pages/3430547647)
10
+
11
+ ---
12
+
13
+ ## 🎯 Core Principle
14
+
15
+ **MANDATORY:** All generated components MUST be accessible to users with disabilities, including those using:
16
+ - Screen readers (NVDA, JAWS, VoiceOver)
17
+ - Keyboard-only navigation
18
+ - Voice control software
19
+ - High contrast modes
20
+ - Screen magnification
21
+
22
+ ---
23
+
24
+ ## 📋 Universal Component Requirements
25
+
26
+ ### ✅ MUST Rules (Apply to ALL Components)
27
+
28
+ ```yaml
29
+ ✅ MUST use semantic HTML elements when possible
30
+ ✅ MUST provide accessible names for all interactive elements
31
+ ✅ MUST support full keyboard navigation
32
+ ✅ MUST maintain logical focus order
33
+ ✅ MUST announce dynamic content changes to assistive technologies
34
+ ✅ MUST have proper ARIA roles, states, and properties
35
+ ✅ MUST associate labels with form controls
36
+ ✅ MUST not trap keyboard focus
37
+ ✅ MUST ensure focus is visible and not obscured
38
+ ```
39
+
40
+ ### ❌ MUST NOT Rules
41
+
42
+ ```yaml
43
+ ❌ NEVER use div/span as buttons without proper role and keyboard handlers
44
+ ❌ NEVER rely on mouse-only interactions
45
+ ❌ NEVER use color as the only means of conveying information
46
+ ❌ NEVER create keyboard traps
47
+ ❌ NEVER hide interactive elements from screen readers without reason
48
+ ❌ NEVER change context automatically without warning
49
+ ❌ NEVER use tabindex > 0 to manipulate focus order
50
+ ```
51
+
52
+ ---
53
+
54
+ ## 🔧 Component-Level WCAG Criteria
55
+
56
+ ### 1. Semantic HTML & Structure
57
+
58
+ **Criterion:** [1.3.1 Info and Relationships](https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships.html)
59
+
60
+ **Rule:** Use native HTML elements according to their semantic meaning.
61
+
62
+ ```typescript
63
+ // ✅ CORRECT: Semantic HTML
64
+ @Component({
65
+ template: `
66
+ <!-- Button -->
67
+ <button (click)="onSave()">Save</button>
68
+
69
+ <!-- Link -->
70
+ <a [href]="profileUrl">View Profile</a>
71
+
72
+ <!-- Form with label -->
73
+ <label for="username">Username</label>
74
+ <input id="username" type="text" [(ngModel)]="username">
75
+
76
+ <!-- Table for tabular data -->
77
+ <table>
78
+ <thead>
79
+ <tr><th>Name</th><th>Age</th></tr>
80
+ </thead>
81
+ <tbody>
82
+ <tr><td>John</td><td>30</td></tr>
83
+ </tbody>
84
+ </table>
85
+
86
+ <!-- List -->
87
+ <ul>
88
+ <li>Item 1</li>
89
+ <li>Item 2</li>
90
+ </ul>
91
+ `
92
+ })
93
+
94
+ // ❌ WRONG: Non-semantic divs
95
+ @Component({
96
+ template: `
97
+ <div class="button" (click)="onSave()">Save</div>
98
+ <div class="link" (click)="navigate()">View Profile</div>
99
+ <div>Username</div>
100
+ <input type="text">
101
+ `
102
+ })
103
+ ```
104
+
105
+ **Key patterns:**
106
+ - `<button>` for buttons, NOT `<div role="button">`
107
+ - `<a href="...">` for links, NOT `<span onclick="...">`
108
+ - `<label for="id">` for form labels
109
+ - `<table>` for tabular data, NOT divs styled as tables
110
+ - `<ul>`/`<ol>` for lists
111
+ - `<h1>` to `<h6>` for headings (in correct hierarchical order)
112
+
113
+ **Auto-check:** ESLint ⚠️ | Axe ✅
114
+
115
+ ---
116
+
117
+ ### 2. Accessible Names
118
+
119
+ **Criterion:** [4.1.2 Name, Role, Value](https://www.w3.org/WAI/WCAG22/Understanding/name-role-value.html)
120
+
121
+ **Rule:** Every interactive element MUST have a programmatically determinable name.
122
+
123
+ ```typescript
124
+ // ✅ CORRECT: Accessible names provided
125
+ @Component({
126
+ template: `
127
+ <!-- Text provides name -->
128
+ <button>Save Changes</button>
129
+
130
+ <!-- aria-label for icon-only buttons -->
131
+ <button aria-label="Close dialog">
132
+ <svg aria-hidden="true">...</svg>
133
+ </button>
134
+
135
+ <!-- aria-labelledby references another element -->
136
+ <h2 id="dialog-title">Confirmation</h2>
137
+ <div role="dialog" aria-labelledby="dialog-title">
138
+ ...
139
+ </div>
140
+
141
+ <!-- Input with label -->
142
+ <label for="email">Email</label>
143
+ <input id="email" type="email">
144
+
145
+ <!-- Input with aria-label when visual label not possible -->
146
+ <input type="search" aria-label="Search products" placeholder="Search...">
147
+ `
148
+ })
149
+
150
+ // ❌ WRONG: No accessible names
151
+ @Component({
152
+ template: `
153
+ <button><mat-icon>delete</mat-icon></button>
154
+ <div role="button" (click)="action()">
155
+ <svg>...</svg>
156
+ </div>
157
+ <input type="text" placeholder="Enter name">
158
+ `
159
+ })
160
+ ```
161
+
162
+ **Accessible name sources (in order of preference):**
163
+ 1. Element text content (`<button>Save</button>`)
164
+ 2. `aria-labelledby` (references another element's ID)
165
+ 3. `aria-label` (inline label)
166
+ 4. `<label>` element (for form controls)
167
+ 5. `title` attribute (last resort)
168
+ 6. `alt` attribute (for images)
169
+
170
+ **Auto-check:** ESLint ✅ | Axe ✅
171
+
172
+ ---
173
+
174
+ ### 3. Keyboard Navigation
175
+
176
+ **Criterion:** [2.1.1 Keyboard](https://www.w3.org/WAI/WCAG22/Understanding/keyboard.html)
177
+
178
+ **Rule:** All functionality MUST be operable via keyboard.
179
+
180
+ ```typescript
181
+ // ✅ CORRECT: Full keyboard support
182
+ @Component({
183
+ template: `
184
+ <!-- Native button - keyboard built-in -->
185
+ <button (click)="onClick()">Action</button>
186
+
187
+ <!-- Custom interactive element -->
188
+ <div
189
+ role="button"
190
+ tabindex="0"
191
+ (click)="onClick()"
192
+ (keydown.enter)="onClick()"
193
+ (keydown.space)="onClick()"
194
+ >
195
+ Custom Button
196
+ </div>
197
+
198
+ <!-- Hover content also on focus -->
199
+ <button
200
+ (mouseenter)="showTooltip = true"
201
+ (mouseleave)="showTooltip = false"
202
+ (focus)="showTooltip = true"
203
+ (blur)="showTooltip = false"
204
+ >
205
+ Help
206
+ </button>
207
+ `
208
+ })
209
+
210
+ // ❌ WRONG: Mouse-only interactions
211
+ @Component({
212
+ template: `
213
+ <!-- No keyboard handler -->
214
+ <div (click)="onClick()">Click me</div>
215
+
216
+ <!-- Hover-only, no focus equivalent -->
217
+ <div (mouseenter)="showMenu()">Menu</div>
218
+
219
+ <!-- Mouse-specific events only -->
220
+ <div (mousedown)="startDrag()" (mouseup)="endDrag()">
221
+ Draggable
222
+ </div>
223
+ `
224
+ })
225
+ ```
226
+
227
+ **Keyboard event patterns:**
228
+
229
+ ```typescript
230
+ // Pattern 1: Native elements (automatic)
231
+ <button (click)="action()">Button</button>
232
+ <a [href]="url">Link</a>
233
+
234
+ // Pattern 2: Custom interactive elements
235
+ <div
236
+ role="button"
237
+ tabindex="0"
238
+ (click)="action()"
239
+ (keydown.enter)="action()"
240
+ (keydown.space)="action(); $event.preventDefault()"
241
+ >
242
+
243
+ // Pattern 3: Scrollable content
244
+ <div tabindex="0" style="overflow: auto;">
245
+ <!-- Scrollable content now keyboard accessible -->
246
+ </div>
247
+
248
+ // Pattern 4: Close on Escape
249
+ <div
250
+ role="dialog"
251
+ (keydown.escape)="closeDialog()"
252
+ >
253
+ ```
254
+
255
+ **Auto-check:** ESLint ✅ | Axe ⚠️
256
+
257
+ ---
258
+
259
+ ### 4. Focus Management
260
+
261
+ **Criterion:** [2.4.3 Focus Order](https://www.w3.org/WAI/WCAG22/Understanding/focus-order.html)
262
+
263
+ **Rule:** Focus order MUST be logical and match visual presentation.
264
+
265
+ ```typescript
266
+ // ✅ CORRECT: DOM order matches visual order
267
+ @Component({
268
+ template: `
269
+ <h1>Sign Up</h1>
270
+ <input type="text" placeholder="Username">
271
+ <input type="email" placeholder="Email">
272
+ <input type="password" placeholder="Password">
273
+ <button>Submit</button>
274
+ `,
275
+ styles: [`
276
+ /* Styling without reordering */
277
+ button {
278
+ background: blue;
279
+ color: white;
280
+ }
281
+ `]
282
+ })
283
+
284
+ // ❌ WRONG: CSS changes visual order
285
+ @Component({
286
+ template: `
287
+ <button class="order-3">Submit</button>
288
+ <input class="order-1" type="text">
289
+ <input class="order-2" type="email">
290
+ `,
291
+ styles: [`
292
+ .order-1 { order: 1; }
293
+ .order-2 { order: 2; }
294
+ .order-3 { order: 3; }
295
+ `]
296
+ })
297
+
298
+ // ❌ WRONG: Manual tabindex manipulation
299
+ @Component({
300
+ template: `
301
+ <input tabindex="2">
302
+ <input tabindex="1">
303
+ <button tabindex="3">
304
+ `
305
+ })
306
+ ```
307
+
308
+ **Focus management for modals/dialogs:**
309
+
310
+ ```typescript
311
+ export class ModalComponent implements OnInit, OnDestroy {
312
+ private previousActiveElement: HTMLElement | null = null;
313
+
314
+ ngOnInit(): void {
315
+ // Save previously focused element
316
+ this.previousActiveElement = document.activeElement as HTMLElement;
317
+
318
+ // Move focus to modal
319
+ setTimeout(() => {
320
+ const firstFocusable = this.element.querySelector('button, input, a');
321
+ (firstFocusable as HTMLElement)?.focus();
322
+ });
323
+
324
+ // Trap focus within modal
325
+ this.trapFocus();
326
+ }
327
+
328
+ ngOnDestroy(): void {
329
+ // Return focus to previous element
330
+ this.previousActiveElement?.focus();
331
+ }
332
+
333
+ private trapFocus(): void {
334
+ // Implementation to keep focus within modal
335
+ }
336
+
337
+ closeModal(): void {
338
+ // Modal closes, focus returns in ngOnDestroy
339
+ }
340
+ }
341
+ ```
342
+
343
+ **Modal requirements:**
344
+ - ✅ Focus moves to modal when opened
345
+ - ✅ Focus trapped within modal (can't tab outside)
346
+ - ✅ Escape key closes modal
347
+ - ✅ Focus returns to trigger element when closed
348
+ - ✅ Background content becomes inert (`aria-hidden="true"`)
349
+
350
+ **Criterion:** [2.1.2 No Keyboard Trap](https://www.w3.org/WAI/WCAG22/Understanding/no-keyboard-trap.html)
351
+
352
+ **Auto-check:** ESLint ⚠️
353
+
354
+ ---
355
+
356
+ ### 5. Dynamic Content Announcements
357
+
358
+ **Criterion:** [4.1.3 Status Messages](https://www.w3.org/WAI/WCAG22/Understanding/status-messages.html)
359
+
360
+ **Rule:** Dynamic content changes MUST be announced to screen readers.
361
+
362
+ ```typescript
363
+ // ✅ CORRECT: aria-live announcements
364
+ @Component({
365
+ template: `
366
+ <!-- Polite announcement (non-critical) -->
367
+ <div role="status" aria-live="polite" aria-atomic="true">
368
+ {{ itemCount }} items in cart
369
+ </div>
370
+
371
+ <!-- Assertive announcement (critical errors) -->
372
+ <div role="alert" aria-live="assertive">
373
+ {{ errorMessage }}
374
+ </div>
375
+
376
+ <!-- Loading state -->
377
+ <div aria-live="polite" [attr.aria-busy]="isLoading">
378
+ @if (isLoading) {
379
+ Loading data...
380
+ } @else {
381
+ {{ data.length }} results found
382
+ }
383
+ </div>
384
+ `
385
+ })
386
+
387
+ // ❌ WRONG: No announcement mechanism
388
+ @Component({
389
+ template: `
390
+ <div class="status">
391
+ {{ statusMessage }}
392
+ </div>
393
+ `
394
+ })
395
+ ```
396
+
397
+ **aria-live regions:**
398
+
399
+ ```typescript
400
+ // Polite (default) - announce when convenient
401
+ <div aria-live="polite">Success! Item added to cart</div>
402
+
403
+ // Assertive - interrupt immediately
404
+ <div aria-live="assertive">Error: Payment failed</div>
405
+
406
+ // Off - don't announce
407
+ <div aria-live="off">Static content</div>
408
+ ```
409
+
410
+ **Dynamic state changes:**
411
+
412
+ ```typescript
413
+ @Component({
414
+ template: `
415
+ <button
416
+ [attr.aria-pressed]="isActive"
417
+ [attr.aria-expanded]="isExpanded"
418
+ [attr.aria-disabled]="isDisabled"
419
+ [attr.aria-checked]="isChecked"
420
+ >
421
+ Toggle
422
+ </button>
423
+ `
424
+ })
425
+ ```
426
+
427
+ **Auto-check:** None ❌ (Manual testing required)
428
+
429
+ ---
430
+
431
+ ### 6. Form Labels & Inputs
432
+
433
+ **Criterion:** [1.3.1 Info and Relationships](https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships.html)
434
+
435
+ **Rule:** Form inputs MUST be programmatically associated with labels.
436
+
437
+ ```typescript
438
+ // ✅ CORRECT: Label associations
439
+ @Component({
440
+ template: `
441
+ <!-- Explicit label (preferred) -->
442
+ <label for="username">Username</label>
443
+ <input id="username" type="text" [(ngModel)]="username">
444
+
445
+ <!-- Implicit label -->
446
+ <label>
447
+ Email Address
448
+ <input type="email" [(ngModel)]="email">
449
+ </label>
450
+
451
+ <!-- aria-label when visual label not wanted -->
452
+ <input
453
+ type="search"
454
+ aria-label="Search products"
455
+ placeholder="Search..."
456
+ [(ngModel)]="searchQuery"
457
+ >
458
+
459
+ <!-- aria-labelledby references another element -->
460
+ <span id="phone-label">Phone Number</span>
461
+ <input type="tel" aria-labelledby="phone-label">
462
+
463
+ <!-- Required field indication -->
464
+ <label for="required-field">
465
+ Name <span aria-label="required">*</span>
466
+ </label>
467
+ <input id="required-field" type="text" required>
468
+
469
+ <!-- Error messages -->
470
+ <label for="email-field">Email</label>
471
+ <input
472
+ id="email-field"
473
+ type="email"
474
+ [attr.aria-invalid]="emailInvalid"
475
+ [attr.aria-describedby]="emailInvalid ? 'email-error' : null"
476
+ >
477
+ @if (emailInvalid) {
478
+ <div id="email-error" role="alert">
479
+ Please enter a valid email address
480
+ </div>
481
+ }
482
+ `
483
+ })
484
+
485
+ // ❌ WRONG: No label association
486
+ @Component({
487
+ template: `
488
+ <p>Enter your name</p>
489
+ <input type="text">
490
+
491
+ <div>Email</div>
492
+ <input type="email">
493
+ `
494
+ })
495
+ ```
496
+
497
+ **Input purpose identification:**
498
+
499
+ **Criterion:** [1.3.5 Identify Input Purpose](https://www.w3.org/WAI/WCAG22/Understanding/identify-input-purpose.html)
500
+
501
+ ```typescript
502
+ // ✅ CORRECT: autocomplete for user data
503
+ <input type="text" name="name" autocomplete="name">
504
+ <input type="email" name="email" autocomplete="email">
505
+ <input type="tel" name="phone" autocomplete="tel">
506
+ <input type="text" name="address" autocomplete="street-address">
507
+
508
+ // ⚠️ NOTE: Most Creatio inputs don't collect personal user data,
509
+ // so autocomplete is often not applicable
510
+ ```
511
+
512
+ **Auto-check:** ESLint ✅ | Axe ✅
513
+
514
+ ---
515
+
516
+ ### 7. Images & Icons
517
+
518
+ **Criterion:** [1.1.1 Non-text Content](https://www.w3.org/WAI/WCAG22/Understanding/non-text-content.html)
519
+
520
+ **Rule:** Images MUST have text alternatives.
521
+
522
+ ```typescript
523
+ // ✅ CORRECT: Alt text provided
524
+ @Component({
525
+ template: `
526
+ <!-- Informative image -->
527
+ <img [src]="logoUrl" alt="Acme Corporation Logo">
528
+
529
+ <!-- Decorative image (empty alt) -->
530
+ <img [src]="decorativeUrl" alt="">
531
+
532
+ <!-- Icon with text -->
533
+ <button>
534
+ <svg aria-hidden="true">...</svg>
535
+ Save
536
+ </button>
537
+
538
+ <!-- Icon without text -->
539
+ <button aria-label="Delete item">
540
+ <svg aria-hidden="true">...</svg>
541
+ </button>
542
+
543
+ <!-- Complex image with description -->
544
+ <img
545
+ [src]="chartUrl"
546
+ alt="Sales chart showing 25% growth in Q4"
547
+ aria-describedby="chart-desc"
548
+ >
549
+ <div id="chart-desc">
550
+ Detailed description of chart data...
551
+ </div>
552
+ `
553
+ })
554
+
555
+ // ❌ WRONG: Missing alt text
556
+ @Component({
557
+ template: `
558
+ <img [src]="logoUrl">
559
+ <img [src]="iconUrl" alt="icon">
560
+ `
561
+ })
562
+ ```
563
+
564
+ **Icon patterns:**
565
+
566
+ ```typescript
567
+ // Decorative icon (hidden from screen readers)
568
+ <mat-icon aria-hidden="true">star</mat-icon>
569
+
570
+ // Informative icon (needs label)
571
+ <mat-icon aria-label="Favorite">star</mat-icon>
572
+
573
+ // Icon button (button has label)
574
+ <button aria-label="Add to favorites">
575
+ <mat-icon aria-hidden="true">star</mat-icon>
576
+ </button>
577
+ ```
578
+
579
+ **Auto-check:** ESLint ✅ | Axe ✅
580
+
581
+ ---
582
+
583
+ ### 8. Color & Contrast
584
+
585
+ **Criterion:** [1.4.3 Contrast (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html)
586
+
587
+ **Rule:** Text MUST have sufficient contrast ratio.
588
+
589
+ ```typescript
590
+ // ✅ CORRECT: Sufficient contrast
591
+ @Component({
592
+ styles: [`
593
+ /* Normal text: 4.5:1 minimum */
594
+ .text {
595
+ color: #333; /* Dark gray */
596
+ background: #fff; /* White */
597
+ /* Ratio: ~12.6:1 ✓ */
598
+ }
599
+
600
+ /* Large text (18pt+): 3:1 minimum */
601
+ h1 {
602
+ color: #666;
603
+ background: #fff;
604
+ font-size: 24px;
605
+ /* Ratio: ~5.7:1 ✓ */
606
+ }
607
+ `]
608
+ })
609
+
610
+ // ❌ WRONG: Insufficient contrast
611
+ @Component({
612
+ styles: [`
613
+ .text {
614
+ color: #ccc; /* Light gray */
615
+ background: #fff; /* White */
616
+ /* Ratio: 1.6:1 ✗ */
617
+ }
618
+ `]
619
+ })
620
+ ```
621
+
622
+ **Do not rely on color alone:**
623
+
624
+ ```typescript
625
+ // ✅ CORRECT: Color + icon/text
626
+ @Component({
627
+ template: `
628
+ <span class="error">
629
+ <mat-icon aria-hidden="true">error</mat-icon>
630
+ Error: Invalid input
631
+ </span>
632
+
633
+ <button [disabled]="isDisabled" [attr.aria-disabled]="isDisabled">
634
+ Submit
635
+ </button>
636
+ `
637
+ })
638
+
639
+ // ❌ WRONG: Color only
640
+ @Component({
641
+ template: `
642
+ <span style="color: red;">Invalid</span>
643
+ `
644
+ })
645
+ ```
646
+
647
+ **Auto-check:** Axe ✅ (partial)
648
+
649
+ ---
650
+
651
+ ### 9. Focus Visibility
652
+
653
+ **Criterion:** [2.4.11 Focus Not Obscured (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/focus-not-obscured-minimum.html)
654
+
655
+ **Rule:** Focused elements MUST be visible and not obscured.
656
+
657
+ ```typescript
658
+ // ✅ CORRECT: Focus visible
659
+ @Component({
660
+ styles: [`
661
+ button:focus {
662
+ outline: 2px solid blue;
663
+ outline-offset: 2px;
664
+ }
665
+
666
+ /* Ensure sticky headers don't hide focus */
667
+ .sticky-header {
668
+ position: sticky;
669
+ top: 0;
670
+ z-index: 10;
671
+ }
672
+
673
+ .content {
674
+ /* Add scroll-padding to prevent focus being hidden */
675
+ scroll-padding-top: 80px;
676
+ }
677
+ `]
678
+ })
679
+
680
+ // ❌ WRONG: Focus outline removed
681
+ @Component({
682
+ styles: [`
683
+ button:focus {
684
+ outline: none; /* Never do this without alternative! */
685
+ }
686
+ `]
687
+ })
688
+ ```
689
+
690
+ **Auto-check:** None ❌
691
+
692
+ ---
693
+
694
+ ### 10. Tooltips & Popovers
695
+
696
+ **Criterion:** [1.4.13 Content on Hover or Focus](https://www.w3.org/WAI/WCAG22/Understanding/content-on-hover-or-focus.html)
697
+
698
+ **Rule:** Hover/focus content MUST be dismissible, hoverable, and persistent.
699
+
700
+ ```typescript
701
+ // ✅ CORRECT: Accessible tooltip
702
+ @Component({
703
+ template: `
704
+ <button
705
+ [attr.aria-describedby]="showTooltip ? 'tooltip-1' : null"
706
+ (mouseenter)="showTooltip = true"
707
+ (mouseleave)="showTooltip = false"
708
+ (focus)="showTooltip = true"
709
+ (blur)="showTooltip = false"
710
+ (keydown.escape)="showTooltip = false"
711
+ >
712
+ Help
713
+ </button>
714
+
715
+ @if (showTooltip) {
716
+ <div
717
+ id="tooltip-1"
718
+ role="tooltip"
719
+ (mouseenter)="keepTooltipOpen()"
720
+ (mouseleave)="showTooltip = false"
721
+ >
722
+ Additional help information
723
+ </div>
724
+ }
725
+ `
726
+ })
727
+
728
+ // ❌ WRONG: Tooltip not keyboard accessible
729
+ @Component({
730
+ template: `
731
+ <span (mouseenter)="showTooltip = true">
732
+ Help
733
+ </span>
734
+ `
735
+ })
736
+ ```
737
+
738
+ **Requirements:**
739
+ - ✅ **Dismissible:** Escape key closes it
740
+ - ✅ **Hoverable:** Can move mouse over tooltip without it disappearing
741
+ - ✅ **Persistent:** Stays visible until dismissed or focus/hover removed
742
+
743
+ **Auto-check:** None ❌
744
+
745
+ ---
746
+
747
+ ## 🧪 Accessibility Testing Patterns
748
+
749
+ ### Test Template for .spec.ts
750
+
751
+ ```typescript
752
+ describe('Accessibility', () => {
753
+ describe('semantic structure', () => {
754
+ it('should use semantic HTML elements', () => {
755
+ const element = getNativeElement();
756
+ const button = element.shadowRoot?.querySelector('button');
757
+ expect(button?.tagName).toBe('BUTTON');
758
+ });
759
+ });
760
+
761
+ describe('accessible names', () => {
762
+ it('should have accessible name for interactive elements', () => {
763
+ const button = element.shadowRoot?.querySelector('button');
764
+ const accessibleName =
765
+ button?.getAttribute('aria-label') ||
766
+ button?.textContent?.trim();
767
+
768
+ expect(accessibleName).toBeTruthy();
769
+ expect(accessibleName.length).toBeGreaterThan(0);
770
+ });
771
+ });
772
+
773
+ describe('keyboard navigation', () => {
774
+ it('should be focusable', () => {
775
+ const button = element.shadowRoot?.querySelector('button');
776
+ expect(button?.tabIndex).toBeGreaterThanOrEqual(0);
777
+ });
778
+
779
+ it('should handle Enter key', () => {
780
+ const button = element.shadowRoot?.querySelector('button');
781
+ const clickSpy = jest.fn();
782
+ component.myEvent.subscribe(clickSpy);
783
+
784
+ const event = new KeyboardEvent('keydown', { key: 'Enter' });
785
+ button?.dispatchEvent(event);
786
+
787
+ expect(clickSpy).toHaveBeenCalled();
788
+ });
789
+
790
+ it('should handle Space key', () => {
791
+ const button = element.shadowRoot?.querySelector('[role="button"]');
792
+ const clickSpy = jest.fn();
793
+ component.myEvent.subscribe(clickSpy);
794
+
795
+ const event = new KeyboardEvent('keydown', { key: ' ' });
796
+ button?.dispatchEvent(event);
797
+
798
+ expect(clickSpy).toHaveBeenCalled();
799
+ });
800
+ });
801
+
802
+ describe('ARIA attributes', () => {
803
+ it('should have proper ARIA role', () => {
804
+ const element = getNativeElement();
805
+ const customElement = element.shadowRoot?.querySelector('[role]');
806
+ expect(customElement?.getAttribute('role')).toBeTruthy();
807
+ });
808
+
809
+ it('should update aria-expanded when state changes', () => {
810
+ component.isExpanded = false;
811
+ fixture.detectChanges();
812
+
813
+ const button = element.shadowRoot?.querySelector('button');
814
+ expect(button?.getAttribute('aria-expanded')).toBe('false');
815
+
816
+ component.isExpanded = true;
817
+ fixture.detectChanges();
818
+ expect(button?.getAttribute('aria-expanded')).toBe('true');
819
+ });
820
+ });
821
+
822
+ describe('live regions', () => {
823
+ it('should announce status changes', () => {
824
+ const liveRegion = element.shadowRoot?.querySelector('[aria-live]');
825
+ expect(liveRegion).not.toBeNull();
826
+ expect(liveRegion?.getAttribute('aria-live')).toBe('polite');
827
+ });
828
+ });
829
+
830
+ describe('form labels', () => {
831
+ it('should associate label with input', () => {
832
+ const label = element.shadowRoot?.querySelector('label');
833
+ const input = element.shadowRoot?.querySelector('input');
834
+
835
+ const labelFor = label?.getAttribute('for');
836
+ const inputId = input?.getAttribute('id');
837
+
838
+ expect(labelFor).toBe(inputId);
839
+ expect(inputId).toBeTruthy();
840
+ });
841
+ });
842
+
843
+ describe('images', () => {
844
+ it('should have alt text for informative images', () => {
845
+ const img = element.shadowRoot?.querySelector('img:not([alt=""])');
846
+ if (img) {
847
+ const alt = img.getAttribute('alt');
848
+ expect(alt).toBeTruthy();
849
+ expect(alt.length).toBeGreaterThan(0);
850
+ }
851
+ });
852
+
853
+ it('should have empty alt for decorative images', () => {
854
+ const decorativeImg = element.shadowRoot?.querySelector('img[alt=""]');
855
+ if (decorativeImg) {
856
+ expect(decorativeImg.getAttribute('alt')).toBe('');
857
+ }
858
+ });
859
+ });
860
+ });
861
+ ```
862
+
863
+ ---
864
+
865
+ ## 📋 Pre-Generation Accessibility Checklist
866
+
867
+ **Add to component generation checklist:**
868
+
869
+ ```markdown
870
+ Accessibility (WCAG 2.2 Level AA):
871
+ - [ ] Semantic HTML used (button, input, label, a, table, etc.)
872
+ - [ ] All interactive elements have accessible names
873
+ - [ ] Keyboard navigation fully supported (Tab, Enter, Space, Escape)
874
+ - [ ] Focus order is logical and matches visual order
875
+ - [ ] No keyboard traps
876
+ - [ ] Dynamic content changes announced (aria-live)
877
+ - [ ] Proper ARIA roles, states, and properties
878
+ - [ ] Form inputs have associated labels
879
+ - [ ] Images have alt text (or alt="" if decorative)
880
+ - [ ] Sufficient color contrast (4.5:1 for text)
881
+ - [ ] Color not the only indicator
882
+ - [ ] Focus indicators visible
883
+ - [ ] Tooltips dismissible with Escape
884
+ - [ ] Modal focus management implemented
885
+ - [ ] Accessibility tests added to .spec.ts
886
+ ```
887
+
888
+ ---
889
+
890
+ ## 🎯 Quick Reference: Common Patterns
891
+
892
+ ### Pattern 1: Accessible Button
893
+ ```typescript
894
+ <button (click)="action()">
895
+ Save Changes
896
+ </button>
897
+ ```
898
+
899
+ ### Pattern 2: Icon Button
900
+ ```typescript
901
+ <button aria-label="Delete item">
902
+ <mat-icon aria-hidden="true">delete</mat-icon>
903
+ </button>
904
+ ```
905
+
906
+ ### Pattern 3: Custom Interactive Element
907
+ ```typescript
908
+ <div
909
+ role="button"
910
+ tabindex="0"
911
+ (click)="action()"
912
+ (keydown.enter)="action()"
913
+ (keydown.space)="action(); $event.preventDefault()"
914
+ >
915
+ Custom Button
916
+ </div>
917
+ ```
918
+
919
+ ### Pattern 4: Form Input with Label
920
+ ```typescript
921
+ <label for="email">Email Address</label>
922
+ <input id="email" type="email" [(ngModel)]="email">
923
+ ```
924
+
925
+ ### Pattern 5: Live Announcement
926
+ ```typescript
927
+ <div role="status" aria-live="polite">
928
+ {{ statusMessage }}
929
+ </div>
930
+ ```
931
+
932
+ ### Pattern 6: Modal Dialog
933
+ ```typescript
934
+ <div
935
+ role="dialog"
936
+ aria-labelledby="dialog-title"
937
+ aria-modal="true"
938
+ (keydown.escape)="closeDialog()"
939
+ >
940
+ <h2 id="dialog-title">Confirmation</h2>
941
+ <button (click)="closeDialog()">Close</button>
942
+ </div>
943
+ ```
944
+
945
+ ### Pattern 7: Expandable Section
946
+ ```typescript
947
+ <button
948
+ [attr.aria-expanded]="isExpanded"
949
+ (click)="isExpanded = !isExpanded"
950
+ >
951
+ {{ isExpanded ? 'Collapse' : 'Expand' }}
952
+ </button>
953
+
954
+ @if (isExpanded) {
955
+ <div>Content here</div>
956
+ }
957
+ ```
958
+
959
+ ### Pattern 8: Tooltip
960
+ ```typescript
961
+ <button
962
+ [attr.aria-describedby]="showTooltip ? 'tip-1' : null"
963
+ (mouseenter)="showTooltip = true"
964
+ (focus)="showTooltip = true"
965
+ (mouseleave)="showTooltip = false"
966
+ (blur)="showTooltip = false"
967
+ (keydown.escape)="showTooltip = false"
968
+ >
969
+ Help
970
+ </button>
971
+
972
+ @if (showTooltip) {
973
+ <div id="tip-1" role="tooltip">
974
+ Helpful information
975
+ </div>
976
+ }
977
+ ```
978
+
979
+ ---
980
+
981
+ ## 📚 Resources
982
+
983
+ **Must read:**
984
+ - [W3C WCAG 2.2](https://www.w3.org/TR/WCAG22/)
985
+ - [ARIA Authoring Practices](https://www.w3.org/WAI/ARIA/apg/patterns/)
986
+ - [Deque Accessibility Checklist](https://dequeuniversity.com/checklists/web/)
987
+
988
+ ---
989
+
990
+ ## ⚠️ Important Notes
991
+
992
+ 1. **Automatic checks are insufficient:** ESLint and Axe catch some issues, but manual testing with keyboard and screen readers is essential.
993
+
994
+ 2. **Design-time vs Runtime:** These rules apply to **runtime components** shown to end users. Design-time tools and admin interfaces have different requirements.
995
+
996
+ 3. **When in doubt:** Use native HTML elements. They have accessibility built-in.
997
+
998
+ 4. **Test early:** Add accessibility tests to .spec.ts from the start, not as an afterthought.
999
+
1000
+ ---
1001
+
1002
+ Last updated: 2026-02-13 (v1.0)