@cngx/common 0.1.0-rc.9 → 0.3.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.
- package/a11y/README.md +15 -2
- package/button/README.md +258 -0
- package/command/README.md +19 -8
- package/data/README.md +10 -10
- package/fesm2022/cngx-common-a11y.mjs +701 -263
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-audio.mjs +83 -64
- package/fesm2022/cngx-common-audio.mjs.map +1 -1
- package/fesm2022/cngx-common-button.mjs +1084 -0
- package/fesm2022/cngx-common-button.mjs.map +1 -0
- package/fesm2022/cngx-common-card.mjs +135 -76
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-chart.mjs +749 -296
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-command.mjs +51 -29
- package/fesm2022/cngx-common-command.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +695 -405
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-dialog.mjs +112 -112
- package/fesm2022/cngx-common-dialog.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +668 -308
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +7066 -2739
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +2121 -492
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-menu-button.mjs +557 -0
- package/fesm2022/cngx-common-menu-button.mjs.map +1 -0
- package/fesm2022/cngx-common-popover.mjs +1207 -569
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common-stepper.mjs +256 -261
- package/fesm2022/cngx-common-stepper.mjs.map +1 -1
- package/fesm2022/cngx-common-tabs.mjs +202 -262
- package/fesm2022/cngx-common-tabs.mjs.map +1 -1
- package/fesm2022/cngx-common-timeline.mjs +28 -61
- package/fesm2022/cngx-common-timeline.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +10 -10
- package/fesm2022/cngx-common.mjs.map +1 -1
- package/interactive/README.md +30 -19
- package/layout/README.md +1 -1
- package/menu-button/README.md +234 -0
- package/package.json +14 -4
- package/popover/README.md +42 -5
- package/popover/tooltip-indicator.scss +52 -0
- package/schematics/ng-add/index.js +7 -7
- package/schematics/ng-add/schema.json +5 -0
- package/stepper/README.md +0 -1
- package/theming/components/cngx-accordion.css +36 -7
- package/theming/components/cngx-async.css +185 -37
- package/theming/components/cngx-backdrop.css +3 -1
- package/theming/components/cngx-badge.css +20 -5
- package/theming/components/cngx-bottom-sheet.css +2 -0
- package/theming/components/cngx-breadcrumb.css +3 -1
- package/theming/components/cngx-button-group.css +325 -0
- package/theming/components/cngx-button-toggle.css +55 -23
- package/theming/components/cngx-button.css +975 -0
- package/theming/components/cngx-data-grid.css +2 -0
- package/theming/components/cngx-dialog.css +3 -1
- package/theming/components/cngx-divider.css +24 -9
- package/theming/components/cngx-drawer.css +153 -0
- package/theming/components/cngx-icon-glyph.css +76 -0
- package/theming/components/cngx-listbox.css +79 -25
- package/theming/components/cngx-menu.css +112 -52
- package/theming/components/cngx-nav.css +1220 -0
- package/theming/components/cngx-popover-sheet.css +43 -11
- package/theming/components/cngx-popover.css +37 -13
- package/theming/components/cngx-recycler-placeholder.css +2 -0
- package/theming/components/cngx-ripple.css +74 -16
- package/theming/components/cngx-sidebar.css +71 -0
- package/theming/components/cngx-slider.css +3 -1
- package/theming/components/cngx-tooltip.css +2 -0
- package/timeline/README.md +2 -2
- package/types/cngx-common-a11y.d.ts +343 -120
- package/types/cngx-common-audio.d.ts +60 -88
- package/types/cngx-common-button.d.ts +698 -0
- package/types/cngx-common-card.d.ts +104 -78
- package/types/cngx-common-chart.d.ts +671 -384
- package/types/cngx-common-command.d.ts +44 -47
- package/types/cngx-common-data.d.ts +350 -342
- package/types/cngx-common-dialog.d.ts +91 -120
- package/types/cngx-common-display.d.ts +475 -300
- package/types/cngx-common-interactive.d.ts +4350 -1723
- package/types/cngx-common-layout.d.ts +1365 -286
- package/types/cngx-common-menu-button.d.ts +382 -0
- package/types/cngx-common-popover.d.ts +671 -289
- package/types/cngx-common-stepper.d.ts +217 -347
- package/types/cngx-common-tabs.d.ts +173 -386
- package/types/cngx-common-timeline.d.ts +25 -104
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input,
|
|
2
|
+
import { InjectionToken, input, booleanAttribute, inject, Injector, computed, Directive, PLATFORM_ID, Injectable, DestroyRef, ElementRef, afterNextRender, effect, untracked, signal, model, contentChildren, output, linkedSignal } from '@angular/core';
|
|
3
3
|
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
|
|
4
|
+
import { createTransitionTracker, isComposingKeydown, isTextEntryTarget, injectLocale, createTypeaheadWalker, CNGX_NESTED_INTERACTIVE_SELECTOR, createMediaQuerySignal } from '@cngx/core/utils';
|
|
4
5
|
import { FocusTrapFactory } from '@angular/cdk/a11y';
|
|
5
6
|
import { injectDirection, resolveInlineStep, resolveStepFrom, resolveBoundaryStep } from '@cngx/core';
|
|
6
|
-
import { injectLocale, createTypeaheadMatcher, createMediaQuerySignal } from '@cngx/core/utils';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Injection token for a {@link CngxAriaExpandedDriver}. A composer provides it
|
|
10
|
+
* on its own element (`useExisting`) to override `[cngxAriaExpanded]` of its
|
|
11
|
+
* `CngxAriaExpanded` host directive; `aria-controls` still follows
|
|
12
|
+
* `[controls]`. Used by `CngxExpandable`.
|
|
13
|
+
*
|
|
14
|
+
* @relatedTo CngxAriaExpanded
|
|
15
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/aria-expanded.directive.ts
|
|
16
|
+
* @since 0.3.0
|
|
17
|
+
*/
|
|
18
|
+
const CNGX_ARIA_EXPANDED_DRIVER = new InjectionToken('CngxAriaExpandedDriver');
|
|
8
19
|
/**
|
|
9
20
|
* Manages `aria-expanded` and optionally `aria-controls` on the host element.
|
|
10
21
|
*
|
|
@@ -36,21 +47,35 @@ import { injectLocale, createTypeaheadMatcher, createMediaQuerySignal } from '@c
|
|
|
36
47
|
* }
|
|
37
48
|
* ```
|
|
38
49
|
*
|
|
39
|
-
* @category common/a11y
|
|
40
50
|
* @wcag AA
|
|
41
51
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/aria-expanded.directive.ts
|
|
42
|
-
* @since 0.
|
|
52
|
+
* @since 0.3.0
|
|
43
53
|
* @relatedTo CngxLiveRegion, CngxExpandable, CngxDisclosure
|
|
44
|
-
* <example-url
|
|
45
|
-
* <example-url
|
|
54
|
+
* <example-url>/#/common/a11y/aria-expanded/accordion-multiple-panels</example-url>
|
|
55
|
+
* <example-url>/#/common/a11y/aria-expanded/disclosure-pattern</example-url>
|
|
56
|
+
* @axis level atom
|
|
46
57
|
*/
|
|
47
58
|
class CngxAriaExpanded {
|
|
48
59
|
/** Whether the controlled element is currently expanded. Sets `aria-expanded`. */
|
|
49
|
-
expanded = input(false, { ...(ngDevMode ? { debugName: "expanded" } : /* istanbul ignore next */ {}), alias: 'cngxAriaExpanded'
|
|
60
|
+
expanded = input(false, { ...(ngDevMode ? { debugName: "expanded" } : /* istanbul ignore next */ {}), alias: 'cngxAriaExpanded',
|
|
61
|
+
transform: booleanAttribute });
|
|
50
62
|
/** The `id` of the controlled element. Sets `aria-controls`. */
|
|
51
63
|
controls = input(undefined, ...(ngDevMode ? [{ debugName: "controls" }] : /* istanbul ignore next */ []));
|
|
64
|
+
injector = inject(Injector);
|
|
65
|
+
resolvedDriver = undefined;
|
|
66
|
+
driver() {
|
|
67
|
+
if (this.resolvedDriver === undefined) {
|
|
68
|
+
this.resolvedDriver = this.injector.get(CNGX_ARIA_EXPANDED_DRIVER, null, { self: true });
|
|
69
|
+
}
|
|
70
|
+
return this.resolvedDriver;
|
|
71
|
+
}
|
|
72
|
+
/** @internal The written attribute value: the driver's when composed, else the input. */
|
|
73
|
+
ariaExpanded = computed(() => {
|
|
74
|
+
const driver = this.driver();
|
|
75
|
+
return driver ? driver.ariaExpanded() : this.expanded();
|
|
76
|
+
}, ...(ngDevMode ? [{ debugName: "ariaExpanded" }] : /* istanbul ignore next */ []));
|
|
52
77
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxAriaExpanded, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
53
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxAriaExpanded, isStandalone: true, selector: "[cngxAriaExpanded]", inputs: { expanded: { classPropertyName: "expanded", publicName: "cngxAriaExpanded", isSignal: true, isRequired: false, transformFunction: null }, controls: { classPropertyName: "controls", publicName: "controls", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.aria-expanded": "
|
|
78
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxAriaExpanded, isStandalone: true, selector: "[cngxAriaExpanded]", inputs: { expanded: { classPropertyName: "expanded", publicName: "cngxAriaExpanded", isSignal: true, isRequired: false, transformFunction: null }, controls: { classPropertyName: "controls", publicName: "controls", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.aria-expanded": "ariaExpanded()", "attr.aria-controls": "controls() ?? null" } }, exportAs: ["cngxAriaExpanded"], ngImport: i0 });
|
|
54
79
|
}
|
|
55
80
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxAriaExpanded, decorators: [{
|
|
56
81
|
type: Directive,
|
|
@@ -59,7 +84,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
59
84
|
exportAs: 'cngxAriaExpanded',
|
|
60
85
|
standalone: true,
|
|
61
86
|
host: {
|
|
62
|
-
'[attr.aria-expanded]': '
|
|
87
|
+
'[attr.aria-expanded]': 'ariaExpanded()',
|
|
63
88
|
'[attr.aria-controls]': 'controls() ?? null',
|
|
64
89
|
},
|
|
65
90
|
}]
|
|
@@ -75,9 +100,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
75
100
|
* Sets `role="alert"` for assertive regions and `role="status"` for polite regions
|
|
76
101
|
* via a host binding - no manual attribute wiring needed.
|
|
77
102
|
*
|
|
78
|
-
* Unlike
|
|
79
|
-
*
|
|
80
|
-
*
|
|
103
|
+
* Unlike `CngxLiveAnnouncer` (hidden regions it owns, imperative
|
|
104
|
+
* `announce()` calls), this directive decorates your own element
|
|
105
|
+
* declaratively - the content you render IS the announcement.
|
|
81
106
|
*
|
|
82
107
|
* ### Status message
|
|
83
108
|
* ```html
|
|
@@ -94,13 +119,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
94
119
|
* </div>
|
|
95
120
|
* ```
|
|
96
121
|
*
|
|
97
|
-
* @category common/a11y
|
|
98
122
|
* @wcag AA
|
|
99
123
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/live-region.directive.ts
|
|
100
|
-
* @since 0.
|
|
101
|
-
* @relatedTo
|
|
102
|
-
* <example-url
|
|
103
|
-
* <example-url
|
|
124
|
+
* @since 0.3.0
|
|
125
|
+
* @relatedTo CngxLiveAnnouncer
|
|
126
|
+
* <example-url>/#/common/a11y/live-region/form-validation-assertive-error-announcements</example-url>
|
|
127
|
+
* <example-url>/#/common/a11y/live-region/polite-vs-assertive</example-url>
|
|
128
|
+
* @axis level atom
|
|
104
129
|
*/
|
|
105
130
|
class CngxLiveRegion {
|
|
106
131
|
/**
|
|
@@ -135,12 +160,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
135
160
|
// One frame. Clear the region this long before writing so an intentionally
|
|
136
161
|
// repeated identical string still registers as a content change for the SR.
|
|
137
162
|
const CLEAR_DELAY_MS = 16;
|
|
163
|
+
// How long a written message stays in its region before it is cleared. A
|
|
164
|
+
// screen reader takes the text when the change event fires, so the clear is
|
|
165
|
+
// silent; it stops a stale message from being read by browsing to the end
|
|
166
|
+
// of the document, or after a route change.
|
|
167
|
+
const HOLD_MS = 7000;
|
|
138
168
|
const POLITENESS = ['polite', 'assertive'];
|
|
139
169
|
/**
|
|
140
170
|
* @internal Browser only: callers guard the server path. Each region is a
|
|
141
171
|
* visually hidden `aria-live` + `aria-atomic="true"` span (the attribute
|
|
142
172
|
* contract of `CngxLiveRegion`), created lazily on the first announce of its
|
|
143
|
-
* politeness or by `ensure()`.
|
|
173
|
+
* politeness or by `ensure()`. A written message is cleared again after a
|
|
174
|
+
* hold, so the region never keeps stale text.
|
|
144
175
|
*
|
|
145
176
|
* `redirect` is asked when a write is due: returning `true` means the caller
|
|
146
177
|
* took the message elsewhere (its container stopped being readable while the
|
|
@@ -155,6 +186,17 @@ function createLiveRegionPair(container, doc, redirect) {
|
|
|
155
186
|
polite: null,
|
|
156
187
|
assertive: null,
|
|
157
188
|
};
|
|
189
|
+
const holds = {
|
|
190
|
+
polite: null,
|
|
191
|
+
assertive: null,
|
|
192
|
+
};
|
|
193
|
+
const cancelHold = (politeness) => {
|
|
194
|
+
const hold = holds[politeness];
|
|
195
|
+
if (hold !== null) {
|
|
196
|
+
clearTimeout(hold);
|
|
197
|
+
holds[politeness] = null;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
158
200
|
const ensureRegion = (politeness) => {
|
|
159
201
|
const existing = regions[politeness];
|
|
160
202
|
if (existing) {
|
|
@@ -193,6 +235,7 @@ function createLiveRegionPair(container, doc, redirect) {
|
|
|
193
235
|
// keep independent timers so one politeness never cancels the other.
|
|
194
236
|
region.textContent = '';
|
|
195
237
|
cancel(politeness);
|
|
238
|
+
cancelHold(politeness);
|
|
196
239
|
pending[politeness] = {
|
|
197
240
|
message,
|
|
198
241
|
timer: setTimeout(() => {
|
|
@@ -201,6 +244,10 @@ function createLiveRegionPair(container, doc, redirect) {
|
|
|
201
244
|
return;
|
|
202
245
|
}
|
|
203
246
|
region.textContent = message;
|
|
247
|
+
holds[politeness] = setTimeout(() => {
|
|
248
|
+
holds[politeness] = null;
|
|
249
|
+
region.textContent = '';
|
|
250
|
+
}, HOLD_MS);
|
|
204
251
|
}, delayMs),
|
|
205
252
|
};
|
|
206
253
|
},
|
|
@@ -222,6 +269,7 @@ function createLiveRegionPair(container, doc, redirect) {
|
|
|
222
269
|
destroy() {
|
|
223
270
|
for (const politeness of POLITENESS) {
|
|
224
271
|
cancel(politeness);
|
|
272
|
+
cancelHold(politeness);
|
|
225
273
|
regions[politeness]?.remove();
|
|
226
274
|
regions[politeness] = null;
|
|
227
275
|
}
|
|
@@ -259,11 +307,14 @@ function topmostOpenModal(doc) {
|
|
|
259
307
|
* directives and event handlers (e.g. `CngxCopyValue` copy success,
|
|
260
308
|
* `CngxOtpInput` completion).
|
|
261
309
|
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* polite
|
|
266
|
-
*
|
|
310
|
+
* Both body regions are created when the service is created, so they are in
|
|
311
|
+
* the DOM before the first announcement (a screen reader commonly misses a
|
|
312
|
+
* change to a region inserted a frame earlier), and reused thereafter.
|
|
313
|
+
* Because polite and assertive live in separate fixed-politeness nodes, an
|
|
314
|
+
* assertive announcement never clobbers a concurrent polite one. Per region,
|
|
315
|
+
* the text is cleared and re-set one frame later so an identical consecutive
|
|
316
|
+
* message is still re-read by the screen reader. A written message is cleared
|
|
317
|
+
* again after 7 s, so no stale text stays in the region.
|
|
267
318
|
*
|
|
268
319
|
* A modal dialog hides everything outside it from assistive technology, so a
|
|
269
320
|
* body region is silent while one is open. Pass the announcing element as the
|
|
@@ -293,16 +344,22 @@ function topmostOpenModal(doc) {
|
|
|
293
344
|
* announcer.announce('Alert dismissed', 'polite', hostElement); // inside a modal
|
|
294
345
|
* ```
|
|
295
346
|
*
|
|
296
|
-
* @category common/a11y
|
|
297
347
|
* @wcag AA
|
|
298
348
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/live-announcer.ts
|
|
299
|
-
* @since 0.
|
|
349
|
+
* @since 0.3.0
|
|
300
350
|
* @relatedTo CngxLiveRegion
|
|
351
|
+
* <example-url>/#/common/a11y/live-announcer/polite-vs-assertive</example-url>
|
|
301
352
|
*/
|
|
302
353
|
class CngxLiveAnnouncer {
|
|
303
354
|
doc = inject(DOCUMENT);
|
|
304
355
|
isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
305
356
|
regions = null;
|
|
357
|
+
constructor() {
|
|
358
|
+
if (this.isBrowser) {
|
|
359
|
+
this.regions = createLiveRegionPair(this.doc.body, this.doc);
|
|
360
|
+
this.regions.ensure();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
306
363
|
/**
|
|
307
364
|
* One pair per open `aria-modal` container, released once it closes.
|
|
308
365
|
* `outer` is the container's parent at creation, the route for its unwritten
|
|
@@ -420,7 +477,7 @@ class CngxLiveAnnouncer {
|
|
|
420
477
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxLiveAnnouncer, decorators: [{
|
|
421
478
|
type: Injectable,
|
|
422
479
|
args: [{ providedIn: 'root' }]
|
|
423
|
-
}] });
|
|
480
|
+
}], ctorParameters: () => [] });
|
|
424
481
|
|
|
425
482
|
/**
|
|
426
483
|
* Create a polite + assertive live-region pair inside `host`.
|
|
@@ -434,7 +491,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
434
491
|
* clobbers a polite status.
|
|
435
492
|
*
|
|
436
493
|
* Must run in an injection context; the regions are removed when that context
|
|
437
|
-
* is destroyed. No-op on the server.
|
|
494
|
+
* is destroyed, and later calls are no-ops. No-op on the server.
|
|
438
495
|
*
|
|
439
496
|
* ```typescript
|
|
440
497
|
* private readonly region = injectScopedLiveRegion(inject(ElementRef).nativeElement);
|
|
@@ -446,29 +503,33 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
446
503
|
*
|
|
447
504
|
* @param host - Element that receives the two visually hidden regions.
|
|
448
505
|
*
|
|
449
|
-
* @category common/a11y
|
|
450
506
|
* @wcag AA
|
|
451
507
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/scoped-live-region.ts
|
|
452
|
-
* @since 0.
|
|
508
|
+
* @since 0.3.0
|
|
453
509
|
* @relatedTo CngxLiveAnnouncer, CngxLiveRegion
|
|
510
|
+
* <example-url>/#/common/a11y/live-announcer/scoped-announcing-in-a-modal</example-url>
|
|
454
511
|
*/
|
|
455
512
|
function injectScopedLiveRegion(host) {
|
|
456
513
|
const doc = inject(DOCUMENT);
|
|
457
514
|
const isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
458
515
|
let pair = null;
|
|
516
|
+
// A manual destroy() may be followed by a new ensure() (an overlay that
|
|
517
|
+
// reopens); a destroyed host never takes regions again.
|
|
518
|
+
let hostDestroyed = false;
|
|
519
|
+
const usable = () => isBrowser && !hostDestroyed;
|
|
459
520
|
const ensurePair = () => {
|
|
460
521
|
pair ??= createLiveRegionPair(host, doc);
|
|
461
522
|
return pair;
|
|
462
523
|
};
|
|
463
524
|
const region = {
|
|
464
525
|
announce(message, politeness = 'polite') {
|
|
465
|
-
if (!
|
|
526
|
+
if (!usable()) {
|
|
466
527
|
return;
|
|
467
528
|
}
|
|
468
529
|
ensurePair().announce(message, politeness);
|
|
469
530
|
},
|
|
470
531
|
ensure() {
|
|
471
|
-
if (!
|
|
532
|
+
if (!usable()) {
|
|
472
533
|
return;
|
|
473
534
|
}
|
|
474
535
|
ensurePair().ensure();
|
|
@@ -481,7 +542,10 @@ function injectScopedLiveRegion(host) {
|
|
|
481
542
|
pair = null;
|
|
482
543
|
},
|
|
483
544
|
};
|
|
484
|
-
inject(DestroyRef).onDestroy(() =>
|
|
545
|
+
inject(DestroyRef).onDestroy(() => {
|
|
546
|
+
hostDestroyed = true;
|
|
547
|
+
region.destroy();
|
|
548
|
+
});
|
|
485
549
|
return region;
|
|
486
550
|
}
|
|
487
551
|
|
|
@@ -512,17 +576,18 @@ function injectScopedLiveRegion(host) {
|
|
|
512
576
|
* <input cngxAutofocus [autofocusDelay]="200" />
|
|
513
577
|
* ```
|
|
514
578
|
*
|
|
515
|
-
* @category common/a11y
|
|
516
579
|
* @wcag AA
|
|
517
580
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/autofocus.directive.ts
|
|
518
|
-
* @since 0.
|
|
581
|
+
* @since 0.3.0
|
|
519
582
|
* @relatedTo CngxFocusRestore, CngxFocusTrap, CngxFocusVisible
|
|
520
|
-
* <example-url
|
|
521
|
-
* <example-url
|
|
583
|
+
* <example-url>/#/common/a11y/autofocus/conditional-focus</example-url>
|
|
584
|
+
* <example-url>/#/common/a11y/autofocus/focus-on-insert</example-url>
|
|
585
|
+
* @axis level atom
|
|
522
586
|
*/
|
|
523
587
|
class CngxAutofocus {
|
|
524
588
|
/** Whether to focus the element. Defaults to `true` (always focus on render). */
|
|
525
|
-
when = input(true, { ...(ngDevMode ? { debugName: "when" } : /* istanbul ignore next */ {}), alias: 'cngxAutofocus'
|
|
589
|
+
when = input(true, { ...(ngDevMode ? { debugName: "when" } : /* istanbul ignore next */ {}), alias: 'cngxAutofocus',
|
|
590
|
+
transform: booleanAttribute });
|
|
526
591
|
/** Delay in ms before focusing - useful when the element appears during a transition. */
|
|
527
592
|
delay = input(0, { ...(ngDevMode ? { debugName: "delay" } : /* istanbul ignore next */ {}), alias: 'autofocusDelay' });
|
|
528
593
|
/** `FocusOptions` passed to `element.focus()`. */
|
|
@@ -590,27 +655,40 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
590
655
|
|
|
591
656
|
/**
|
|
592
657
|
* CSS selector matching natively-focusable elements: links with an
|
|
593
|
-
* `href`, the enabled form controls,
|
|
594
|
-
* non-negative `tabindex`.
|
|
595
|
-
* a disabled control is not in
|
|
596
|
-
*
|
|
597
|
-
* could land on an unfocusable element.
|
|
598
|
-
* this focusable" - the element-level
|
|
599
|
-
* matches against it, and descendant probes
|
|
600
|
-
* contain a focusable child?") query against it.
|
|
601
|
-
* stops the two uses from drifting apart.
|
|
602
|
-
*
|
|
603
|
-
* @
|
|
604
|
-
|
|
658
|
+
* `href`, the enabled form controls, the summary of a `<details>`,
|
|
659
|
+
* editable content, and anything with an explicit non-negative `tabindex`.
|
|
660
|
+
* Form controls carry `:not(:disabled)` because a disabled control is not in
|
|
661
|
+
* the tab order - without it a descendant probe would count a disabled button
|
|
662
|
+
* as focusable and a restore target could land on an unfocusable element.
|
|
663
|
+
* Single source of truth for "is this focusable" - the element-level
|
|
664
|
+
* {@link CngxFocusRestore} predicate matches against it, and descendant probes
|
|
665
|
+
* (e.g. "does this panel contain a focusable child?") query against it.
|
|
666
|
+
* Keeping one selector stops the two uses from drifting apart.
|
|
667
|
+
*
|
|
668
|
+
* @since 0.3.0
|
|
669
|
+
*/
|
|
670
|
+
const CNGX_FOCUSABLE_SELECTOR = 'a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), details > summary:first-of-type, [contenteditable]:not([contenteditable="false"]), [tabindex]:not([tabindex="-1"])';
|
|
671
|
+
/**
|
|
672
|
+
* Injection token for a {@link CngxFocusRestoreDriver}. A composer provides it
|
|
673
|
+
* on its own element (`useExisting`) to override `[cngxFocusRestoreWhile]`
|
|
674
|
+
* and `[fallback]` of its `CngxFocusRestore` host directive. Used by
|
|
675
|
+
* `CngxDrawerSurface`.
|
|
676
|
+
*
|
|
677
|
+
* @relatedTo CngxFocusRestore
|
|
678
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/focus-restore.directive.ts
|
|
679
|
+
* @since 0.3.0
|
|
605
680
|
*/
|
|
606
|
-
const
|
|
681
|
+
const CNGX_FOCUS_RESTORE_DRIVER = new InjectionToken('CngxFocusRestoreDriver');
|
|
607
682
|
/**
|
|
608
|
-
* Stores the previously focused element and restores focus on destroy
|
|
683
|
+
* Stores the previously focused element and restores focus on destroy, or on
|
|
684
|
+
* the falling edge of `[cngxFocusRestoreWhile]` for a surface that stays in
|
|
685
|
+
* the DOM while closed.
|
|
609
686
|
*
|
|
610
687
|
* Prevents focus from falling to `<body>` when dynamic content is removed
|
|
611
688
|
* (dialogs closing, panels collapsing, tabs switching). The directive captures
|
|
612
689
|
* `document.activeElement` at initialization time and restores it when the
|
|
613
|
-
* host element is destroyed
|
|
690
|
+
* host element is destroyed while focus is inside it or has dropped to
|
|
691
|
+
* `<body>`. Focus the user moved elsewhere before the destroy stays put.
|
|
614
692
|
*
|
|
615
693
|
* Fallback chain: stored element → provided fallback → nearest focusable ancestor.
|
|
616
694
|
* When none resolves, focus is left where the browser put it - `<body>` is
|
|
@@ -626,50 +704,102 @@ const CNGX_FOCUSABLE_SELECTOR = 'a[href], button:not(:disabled), input:not(:disa
|
|
|
626
704
|
* }
|
|
627
705
|
* ```
|
|
628
706
|
*
|
|
707
|
+
* ### Persistent surface (drawer, sidebar overlay)
|
|
708
|
+
* ```html
|
|
709
|
+
* <aside cngxFocusRestore [cngxFocusRestoreWhile]="open()">…</aside>
|
|
710
|
+
* ```
|
|
711
|
+
* `true` captures the focused element, `false` restores it when focus is
|
|
712
|
+
* still inside the host or has dropped to `<body>`. Focus the user moved
|
|
713
|
+
* elsewhere in the meantime stays where it is. A target that is still
|
|
714
|
+
* `inert` at the falling edge (a backdrop released in the same pass) is
|
|
715
|
+
* focused after the next render instead.
|
|
716
|
+
*
|
|
629
717
|
* ### With explicit fallback
|
|
630
718
|
* ```html
|
|
631
|
-
* <div cngxFocusRestore [
|
|
719
|
+
* <div cngxFocusRestore [fallback]="fallbackBtn">
|
|
632
720
|
* Dynamic content…
|
|
633
721
|
* </div>
|
|
634
722
|
* <button #fallbackBtn>Fallback target</button>
|
|
635
723
|
* ```
|
|
636
724
|
*
|
|
637
|
-
* @category common/a11y
|
|
638
725
|
* @wcag AA
|
|
639
726
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/focus-restore.directive.ts
|
|
640
|
-
* @since 0.
|
|
727
|
+
* @since 0.3.0
|
|
641
728
|
* @relatedTo CngxAutofocus, CngxFocusTrap, CngxFocusVisible
|
|
642
|
-
* <example-url
|
|
643
|
-
* <example-url
|
|
729
|
+
* <example-url>/#/common/a11y/focus-restore/inline-details</example-url>
|
|
730
|
+
* <example-url>/#/common/a11y/focus-restore/panel-with-automatic-restore</example-url>
|
|
731
|
+
* <example-url>/#/common/a11y/focus-restore/persistent-panel-restore-while-open</example-url>
|
|
732
|
+
* @axis level atom
|
|
644
733
|
*/
|
|
645
734
|
class CngxFocusRestore {
|
|
646
|
-
/**
|
|
735
|
+
/**
|
|
736
|
+
* Whether to restore focus when the host element is destroyed. Applies only
|
|
737
|
+
* when focus is inside the host or on `<body>` at that moment.
|
|
738
|
+
*/
|
|
647
739
|
restoreOnDestroy = input(true, ...(ngDevMode ? [{ debugName: "restoreOnDestroy" }] : /* istanbul ignore next */ []));
|
|
648
740
|
/** Explicit fallback element if the stored element is no longer in the DOM. */
|
|
649
741
|
fallback = input(null, ...(ngDevMode ? [{ debugName: "fallback" }] : /* istanbul ignore next */ []));
|
|
742
|
+
/**
|
|
743
|
+
* Bind to the open state of a surface that stays in the DOM while closed.
|
|
744
|
+
* The `false -> true` edge captures the focused element, the
|
|
745
|
+
* `true -> false` edge restores it when focus is inside the host or on
|
|
746
|
+
* `<body>`. While bound, destroying the host restores only when it is
|
|
747
|
+
* engaged. Unbound (`undefined`), only destroy and the manual
|
|
748
|
+
* `capture()` / `restore()` apply.
|
|
749
|
+
*/
|
|
750
|
+
whileActive = input(undefined, { ...(ngDevMode ? { debugName: "whileActive" } : /* istanbul ignore next */ {}), alias: 'cngxFocusRestoreWhile' });
|
|
650
751
|
doc = inject(DOCUMENT);
|
|
651
752
|
el = inject((ElementRef));
|
|
652
|
-
|
|
753
|
+
injector = inject(Injector);
|
|
754
|
+
// Read only inside the restore paths (untracked edge, destroy, manual
|
|
755
|
+
// restore()); nothing derives from it, so it is not a signal.
|
|
756
|
+
storedElement = null;
|
|
757
|
+
// The host is already detached when DestroyRef fires, so the ancestor
|
|
758
|
+
// walk starts from the parent recorded while it was still attached.
|
|
759
|
+
lastParent = null;
|
|
760
|
+
resolvedDriver = undefined;
|
|
761
|
+
driver() {
|
|
762
|
+
if (this.resolvedDriver === undefined) {
|
|
763
|
+
this.resolvedDriver = this.injector.get(CNGX_FOCUS_RESTORE_DRIVER, null, { self: true });
|
|
764
|
+
}
|
|
765
|
+
return this.resolvedDriver;
|
|
766
|
+
}
|
|
767
|
+
engaged = computed(() => this.driver()?.focusRestoreActive() ?? this.whileActive() === true, ...(ngDevMode ? [{ debugName: "engaged" }] : /* istanbul ignore next */ []));
|
|
768
|
+
engagement = createTransitionTracker(() => this.engaged());
|
|
653
769
|
constructor() {
|
|
654
770
|
const activeEl = this.doc.activeElement;
|
|
655
771
|
if (activeEl instanceof HTMLElement) {
|
|
656
|
-
this.storedElement
|
|
772
|
+
this.storedElement = activeEl;
|
|
657
773
|
}
|
|
774
|
+
afterNextRender({ read: () => (this.lastParent = this.host().parentElement) });
|
|
775
|
+
effect(() => {
|
|
776
|
+
const current = this.engagement.current();
|
|
777
|
+
if (current === this.engagement.previous()) {
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
untracked(() => (current ? this.captureOutside() : this.restoreIfFocusInside()));
|
|
781
|
+
});
|
|
658
782
|
inject(DestroyRef).onDestroy(() => {
|
|
659
783
|
if (!this.restoreOnDestroy()) {
|
|
660
784
|
return;
|
|
661
785
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
786
|
+
// A closed edge-driven surface already restored (or never captured);
|
|
787
|
+
// tearing it down must not pull focus from wherever the user is.
|
|
788
|
+
if (this.edgeDriven() && !untracked(this.engaged)) {
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
// Focus the user moved elsewhere in the meantime stays where it is.
|
|
792
|
+
if (!this.focusLost()) {
|
|
793
|
+
return;
|
|
665
794
|
}
|
|
795
|
+
this.resolveTarget()?.focus();
|
|
666
796
|
});
|
|
667
797
|
}
|
|
668
798
|
/** Manually store the current focus target for later restoration. */
|
|
669
799
|
capture() {
|
|
670
800
|
const activeEl = this.doc.activeElement;
|
|
671
801
|
if (activeEl instanceof HTMLElement) {
|
|
672
|
-
this.storedElement
|
|
802
|
+
this.storedElement = activeEl;
|
|
673
803
|
}
|
|
674
804
|
}
|
|
675
805
|
/** Manually restore focus to the stored element. */
|
|
@@ -679,22 +809,66 @@ class CngxFocusRestore {
|
|
|
679
809
|
target.focus();
|
|
680
810
|
}
|
|
681
811
|
}
|
|
812
|
+
edgeDriven() {
|
|
813
|
+
return this.driver() !== null || untracked(this.whileActive) !== undefined;
|
|
814
|
+
}
|
|
815
|
+
// A composer's trap can move focus inside before this edge runs; the
|
|
816
|
+
// element inside is never the one to return to.
|
|
817
|
+
captureOutside() {
|
|
818
|
+
const activeEl = this.doc.activeElement;
|
|
819
|
+
if (activeEl instanceof HTMLElement && !this.host().contains(activeEl)) {
|
|
820
|
+
this.storedElement = activeEl;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
restoreIfFocusInside() {
|
|
824
|
+
if (!this.focusLost()) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
const target = this.resolveTarget();
|
|
828
|
+
if (!target) {
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
if (!target.closest('[inert]')) {
|
|
832
|
+
target.focus();
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
// Another owner (a backdrop) can still hold `inert` on the target in
|
|
836
|
+
// this pass; focus() on an inert element is a no-op. Its release runs in
|
|
837
|
+
// the same change detection, so retry once after the render.
|
|
838
|
+
afterNextRender(() => {
|
|
839
|
+
if (this.focusLost() && !target.closest('[inert]')) {
|
|
840
|
+
target.focus();
|
|
841
|
+
}
|
|
842
|
+
}, { injector: this.injector });
|
|
843
|
+
}
|
|
844
|
+
// A detached host still contains the element that had focus in it, so the
|
|
845
|
+
// check also holds on destroy, where the browser may report either that
|
|
846
|
+
// element or `<body>`.
|
|
847
|
+
focusLost() {
|
|
848
|
+
const activeEl = this.doc.activeElement;
|
|
849
|
+
return !activeEl || activeEl === this.doc.body || this.host().contains(activeEl);
|
|
850
|
+
}
|
|
851
|
+
host() {
|
|
852
|
+
return this.el.nativeElement;
|
|
853
|
+
}
|
|
682
854
|
/**
|
|
683
855
|
* Walks the fallback chain:
|
|
684
856
|
* 1. Stored element (if still in DOM and not body/self)
|
|
685
|
-
* 2.
|
|
857
|
+
* 2. The driver's fallback, else the explicit fallback input
|
|
686
858
|
* 3. Nearest focusable ancestor
|
|
687
859
|
*/
|
|
688
860
|
resolveTarget() {
|
|
689
|
-
const stored = this.storedElement
|
|
690
|
-
// Skip body - it signals "nothing meaningful was focused", not a real
|
|
861
|
+
const stored = this.storedElement;
|
|
862
|
+
// Skip body - it signals "nothing meaningful was focused", not a real
|
|
863
|
+
// restore target - and anything inside the host, which is the focus
|
|
864
|
+
// being restored away from (engaged while focus was already inside).
|
|
691
865
|
if (stored &&
|
|
692
866
|
stored !== this.doc.body &&
|
|
693
867
|
this.doc.contains(stored) &&
|
|
694
|
-
|
|
868
|
+
!this.host().contains(stored)) {
|
|
695
869
|
return stored;
|
|
696
870
|
}
|
|
697
|
-
const fallback = this.fallback();
|
|
871
|
+
const fallback = this.driver()?.focusRestoreFallback?.() ?? this.fallback();
|
|
698
872
|
if (fallback && this.doc.contains(fallback)) {
|
|
699
873
|
return fallback;
|
|
700
874
|
}
|
|
@@ -702,7 +876,7 @@ class CngxFocusRestore {
|
|
|
702
876
|
}
|
|
703
877
|
/** Traverses up the DOM tree looking for the first natively focusable element. */
|
|
704
878
|
findFocusableAncestor() {
|
|
705
|
-
let current = this.
|
|
879
|
+
let current = this.host().parentElement ?? this.lastParent;
|
|
706
880
|
while (current) {
|
|
707
881
|
if (this.isFocusable(current)) {
|
|
708
882
|
return current;
|
|
@@ -721,7 +895,7 @@ class CngxFocusRestore {
|
|
|
721
895
|
return el.matches(CNGX_FOCUSABLE_SELECTOR);
|
|
722
896
|
}
|
|
723
897
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxFocusRestore, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
724
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxFocusRestore, isStandalone: true, selector: "[cngxFocusRestore]", inputs: { restoreOnDestroy: { classPropertyName: "restoreOnDestroy", publicName: "restoreOnDestroy", isSignal: true, isRequired: false, transformFunction: null }, fallback: { classPropertyName: "fallback", publicName: "fallback", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxFocusRestore"], ngImport: i0 });
|
|
898
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxFocusRestore, isStandalone: true, selector: "[cngxFocusRestore]", inputs: { restoreOnDestroy: { classPropertyName: "restoreOnDestroy", publicName: "restoreOnDestroy", isSignal: true, isRequired: false, transformFunction: null }, fallback: { classPropertyName: "fallback", publicName: "fallback", isSignal: true, isRequired: false, transformFunction: null }, whileActive: { classPropertyName: "whileActive", publicName: "cngxFocusRestoreWhile", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxFocusRestore"], ngImport: i0 });
|
|
725
899
|
}
|
|
726
900
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxFocusRestore, decorators: [{
|
|
727
901
|
type: Directive,
|
|
@@ -730,9 +904,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
730
904
|
exportAs: 'cngxFocusRestore',
|
|
731
905
|
standalone: true,
|
|
732
906
|
}]
|
|
733
|
-
}], ctorParameters: () => [], propDecorators: { restoreOnDestroy: [{ type: i0.Input, args: [{ isSignal: true, alias: "restoreOnDestroy", required: false }] }], fallback: [{ type: i0.Input, args: [{ isSignal: true, alias: "fallback", required: false }] }] } });
|
|
907
|
+
}], ctorParameters: () => [], propDecorators: { restoreOnDestroy: [{ type: i0.Input, args: [{ isSignal: true, alias: "restoreOnDestroy", required: false }] }], fallback: [{ type: i0.Input, args: [{ isSignal: true, alias: "fallback", required: false }] }], whileActive: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxFocusRestoreWhile", required: false }] }] } });
|
|
734
908
|
|
|
735
|
-
/**
|
|
909
|
+
/**
|
|
910
|
+
* Injection token for a {@link CngxFocusTrapDriver}. A composer provides it on
|
|
911
|
+
* its own element (`useExisting`) to override `[enabled]` and `[autoFocus]` of
|
|
912
|
+
* its `CngxFocusTrap` host directive. Used by `CngxDrawerSurface` and
|
|
913
|
+
* `CngxPopoverSheet`.
|
|
914
|
+
*
|
|
915
|
+
* @relatedTo CngxFocusTrap
|
|
916
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/focus-trap.directive.ts
|
|
917
|
+
* @since 0.3.0
|
|
918
|
+
*/
|
|
736
919
|
const CNGX_FOCUS_TRAP_DRIVER = new InjectionToken('CngxFocusTrapDriver');
|
|
737
920
|
/**
|
|
738
921
|
* Traps keyboard focus within the host element using the CDK `FocusTrap`.
|
|
@@ -768,14 +951,13 @@ const CNGX_FOCUS_TRAP_DRIVER = new InjectionToken('CngxFocusTrapDriver');
|
|
|
768
951
|
* </nav>
|
|
769
952
|
* ```
|
|
770
953
|
*
|
|
771
|
-
* @category common/a11y
|
|
772
|
-
* @docsKind primary
|
|
773
954
|
* @wcag AA
|
|
774
955
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/focus-trap.directive.ts
|
|
775
|
-
* @since 0.
|
|
956
|
+
* @since 0.3.0
|
|
776
957
|
* @relatedTo CngxAutofocus, CngxFocusRestore, CngxDialog
|
|
777
|
-
* <example-url
|
|
778
|
-
* <example-url
|
|
958
|
+
* <example-url>/#/common/a11y/focus-trap/modal-dialog</example-url>
|
|
959
|
+
* <example-url>/#/common/a11y/focus-trap/slide-out-drawer</example-url>
|
|
960
|
+
* @axis level atom
|
|
779
961
|
*/
|
|
780
962
|
class CngxFocusTrap {
|
|
781
963
|
/** Whether the focus trap is active. When `false`, Tab navigates normally. */
|
|
@@ -874,13 +1056,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
874
1056
|
* </button>
|
|
875
1057
|
* ```
|
|
876
1058
|
*
|
|
877
|
-
* @category common/a11y
|
|
878
1059
|
* @wcag AA
|
|
879
1060
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/focus-visible.directive.ts
|
|
880
|
-
* @since 0.
|
|
1061
|
+
* @since 0.3.0
|
|
881
1062
|
* @relatedTo CngxAutofocus, CngxFocusRestore, CngxFocusTrap
|
|
882
|
-
* <example-url
|
|
883
|
-
* <example-url
|
|
1063
|
+
* <example-url>/#/common/a11y/focus-visible/form-fields-custom-focus-ring</example-url>
|
|
1064
|
+
* <example-url>/#/common/a11y/focus-visible/keyboard-vs-pointer</example-url>
|
|
1065
|
+
* @axis level atom
|
|
884
1066
|
*/
|
|
885
1067
|
class CngxFocusVisible {
|
|
886
1068
|
doc = inject(DOCUMENT);
|
|
@@ -889,6 +1071,12 @@ class CngxFocusVisible {
|
|
|
889
1071
|
focusVisible = this.focusVisibleState.asReadonly();
|
|
890
1072
|
pointerActive = false;
|
|
891
1073
|
pointerClearTimer = null;
|
|
1074
|
+
// pointercancel (touch scroll start, OS gesture) ends a press without a
|
|
1075
|
+
// pointerup; either release clears the flag and drops both listeners.
|
|
1076
|
+
releasePointer = () => {
|
|
1077
|
+
this.removeReleaseListeners();
|
|
1078
|
+
this.schedulePointerClear();
|
|
1079
|
+
};
|
|
892
1080
|
schedulePointerClear = () => {
|
|
893
1081
|
// One macrotask of grace: on touch, the compat mousedown and the focusin
|
|
894
1082
|
// fire AFTER pointerup, so a synchronous clear here would misread a tap
|
|
@@ -904,7 +1092,7 @@ class CngxFocusVisible {
|
|
|
904
1092
|
};
|
|
905
1093
|
constructor() {
|
|
906
1094
|
inject(DestroyRef).onDestroy(() => {
|
|
907
|
-
this.
|
|
1095
|
+
this.removeReleaseListeners();
|
|
908
1096
|
if (this.pointerClearTimer !== null) {
|
|
909
1097
|
clearTimeout(this.pointerClearTimer);
|
|
910
1098
|
}
|
|
@@ -922,10 +1110,12 @@ class CngxFocusVisible {
|
|
|
922
1110
|
// (disabled child, text selection, drag released off-host) would
|
|
923
1111
|
// otherwise suppress the ring on the NEXT keyboard Tab-in. Document-level
|
|
924
1112
|
// capture catches the release wherever it lands.
|
|
925
|
-
this.doc.addEventListener('pointerup', this.
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
1113
|
+
this.doc.addEventListener('pointerup', this.releasePointer, true);
|
|
1114
|
+
this.doc.addEventListener('pointercancel', this.releasePointer, true);
|
|
1115
|
+
}
|
|
1116
|
+
removeReleaseListeners() {
|
|
1117
|
+
this.doc.removeEventListener('pointerup', this.releasePointer, true);
|
|
1118
|
+
this.doc.removeEventListener('pointercancel', this.releasePointer, true);
|
|
929
1119
|
}
|
|
930
1120
|
/** @internal Sets focus-visible state; clears pointer flag. */
|
|
931
1121
|
handleFocus() {
|
|
@@ -954,6 +1144,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
954
1144
|
}]
|
|
955
1145
|
}], ctorParameters: () => [] });
|
|
956
1146
|
|
|
1147
|
+
/**
|
|
1148
|
+
* Widgets whose arrow keys are their own. A key from inside one that sits in
|
|
1149
|
+
* the roving group (a slider in a toolbar item, a nested listbox) belongs to
|
|
1150
|
+
* it, not to the group.
|
|
1151
|
+
*/
|
|
1152
|
+
const ARROW_KEY_WIDGETS = [
|
|
1153
|
+
'input[type="range"]',
|
|
1154
|
+
'[role="slider"]',
|
|
1155
|
+
'[role="spinbutton"]',
|
|
1156
|
+
'[role="scrollbar"]',
|
|
1157
|
+
'[role="combobox"]',
|
|
1158
|
+
'[role="listbox"]',
|
|
1159
|
+
'[role="tree"]',
|
|
1160
|
+
'[role="treegrid"]',
|
|
1161
|
+
'[role="grid"]',
|
|
1162
|
+
'[role="menu"]',
|
|
1163
|
+
'[role="menubar"]',
|
|
1164
|
+
'[role="tablist"]',
|
|
1165
|
+
'[role="radiogroup"]',
|
|
1166
|
+
'[role="toolbar"]',
|
|
1167
|
+
].join(', ');
|
|
957
1168
|
/**
|
|
958
1169
|
* Marker directive for items managed by `CngxRovingTabindex`.
|
|
959
1170
|
*
|
|
@@ -969,13 +1180,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
969
1180
|
* </div>
|
|
970
1181
|
* ```
|
|
971
1182
|
*
|
|
972
|
-
* @category common/a11y
|
|
973
1183
|
* @wcag AA
|
|
974
1184
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/roving/roving-tabindex.directive.ts
|
|
975
|
-
* @since 0.
|
|
1185
|
+
* @since 0.3.0
|
|
976
1186
|
* @relatedTo CngxRovingTabindex, CngxButtonToggle
|
|
977
|
-
* <example-url
|
|
978
|
-
* <example-url
|
|
1187
|
+
* <example-url>/#/common/a11y/roving-tabindex/horizontal-toolbar</example-url>
|
|
1188
|
+
* <example-url>/#/common/a11y/roving-tabindex/vertical-menu</example-url>
|
|
979
1189
|
*/
|
|
980
1190
|
class CngxRovingItem {
|
|
981
1191
|
/** @internal Reference used by the parent `CngxRovingTabindex` to set `tabindex`. */
|
|
@@ -1007,6 +1217,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1007
1217
|
* Works for toolbars, tab lists, card grids, menu bars, and any composite
|
|
1008
1218
|
* widget where only one item should be in the tab order at a time.
|
|
1009
1219
|
*
|
|
1220
|
+
* ### Keys the group leaves alone
|
|
1221
|
+
*
|
|
1222
|
+
* A key from a text field (an `<input>` item, a field inside an item), a key
|
|
1223
|
+
* of an IME composition, and an arrow from inside a nested widget that owns
|
|
1224
|
+
* its arrows (a range input or an element with a slider, spinbutton,
|
|
1225
|
+
* scrollbar, combobox, listbox, tree, treegrid, grid, menu, menubar,
|
|
1226
|
+
* tablist, radiogroup or toolbar role)
|
|
1227
|
+
* stays with that element. A custom widget without one of those roles keeps
|
|
1228
|
+
* its arrows by calling `preventDefault()` on the keys it handles: the group
|
|
1229
|
+
* skips every key that arrives already handled.
|
|
1230
|
+
*
|
|
1010
1231
|
* ### Virtual mode
|
|
1011
1232
|
*
|
|
1012
1233
|
* When `virtualCount` is set, `activeIndex` ranges from 0 to `virtualCount - 1`
|
|
@@ -1044,14 +1265,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1044
1265
|
* </div>
|
|
1045
1266
|
* ```
|
|
1046
1267
|
*
|
|
1047
|
-
* @category common/a11y
|
|
1048
|
-
* @docsKind primary
|
|
1049
1268
|
* @wcag AA
|
|
1050
1269
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/roving/roving-tabindex.directive.ts
|
|
1051
|
-
* @since 0.
|
|
1270
|
+
* @since 0.3.0
|
|
1052
1271
|
* @relatedTo CngxRovingItem, CngxActiveDescendant
|
|
1053
|
-
* <example-url
|
|
1054
|
-
* <example-url
|
|
1272
|
+
* <example-url>/#/common/a11y/roving-tabindex/horizontal-toolbar</example-url>
|
|
1273
|
+
* <example-url>/#/common/a11y/roving-tabindex/vertical-menu</example-url>
|
|
1274
|
+
* @axis level atom
|
|
1055
1275
|
*/
|
|
1056
1276
|
class CngxRovingTabindex {
|
|
1057
1277
|
/**
|
|
@@ -1074,8 +1294,15 @@ class CngxRovingTabindex {
|
|
|
1074
1294
|
virtualCount = input(undefined, ...(ngDevMode ? [{ debugName: "virtualCount" }] : /* istanbul ignore next */ []));
|
|
1075
1295
|
/** All `CngxRovingItem` children discovered via `contentChildren`. */
|
|
1076
1296
|
items = contentChildren(CngxRovingItem, ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
|
|
1077
|
-
/**
|
|
1078
|
-
|
|
1297
|
+
/**
|
|
1298
|
+
* Flips after the first browser render. Virtual mode waits for it: it reads
|
|
1299
|
+
* the `data-cngx-recycle-index` attributes, which the item bindings write
|
|
1300
|
+
* during that render. Standard mode writes before it (so a server render
|
|
1301
|
+
* carries the tab stops) and once more after it, because an item's own
|
|
1302
|
+
* `[attr.tabindex]` binding (null under a roving parent) clears the
|
|
1303
|
+
* attribute during that render.
|
|
1304
|
+
*/
|
|
1305
|
+
rendered = signal(false, ...(ngDevMode ? [{ debugName: "rendered" }] : /* istanbul ignore next */ []));
|
|
1079
1306
|
/** Host element for `data-cngx-recycle-index` queries in virtual mode. */
|
|
1080
1307
|
hostEl = inject((ElementRef));
|
|
1081
1308
|
pendingFocusState = signal(null, ...(ngDevMode ? [{ debugName: "pendingFocusState" }] : /* istanbul ignore next */ []));
|
|
@@ -1095,15 +1322,20 @@ class CngxRovingTabindex {
|
|
|
1095
1322
|
*/
|
|
1096
1323
|
pendingFocus = this.pendingFocusState.asReadonly();
|
|
1097
1324
|
constructor() {
|
|
1098
|
-
|
|
1325
|
+
// The item list and the index the last run settled on: a list change with
|
|
1326
|
+
// an unchanged index re-finds the item that held the tab stop.
|
|
1327
|
+
let previousItems = [];
|
|
1328
|
+
let previousActive = -1;
|
|
1329
|
+
afterNextRender(() => this.rendered.set(true));
|
|
1099
1330
|
effect(() => {
|
|
1100
|
-
|
|
1101
|
-
return;
|
|
1102
|
-
}
|
|
1331
|
+
const rendered = this.rendered();
|
|
1103
1332
|
const items = this.items();
|
|
1104
1333
|
const active = this.activeIndex();
|
|
1105
1334
|
const vc = this.virtualCount();
|
|
1106
1335
|
if (vc != null) {
|
|
1336
|
+
if (!rendered) {
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1107
1339
|
// Virtual mode: match by data-cngx-recycle-index attribute. Clamp the
|
|
1108
1340
|
// model itself when the virtual space shrinks below it - a ghost
|
|
1109
1341
|
// index would otherwise anchor the next arrow press. An empty space
|
|
@@ -1112,31 +1344,38 @@ class CngxRovingTabindex {
|
|
|
1112
1344
|
if (clamped !== active) {
|
|
1113
1345
|
untracked(() => this.activeIndex.set(clamped));
|
|
1114
1346
|
}
|
|
1115
|
-
items
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
el.setAttribute('tabindex', idx != null && Number(idx) === clamped ? '0' : '-1');
|
|
1119
|
-
});
|
|
1347
|
+
const stop = virtualTabStop(items, clamped);
|
|
1348
|
+
items.forEach((item) => item.elementRef.nativeElement.setAttribute('tabindex', item === stop ? '0' : '-1'));
|
|
1349
|
+
return;
|
|
1120
1350
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
if (items[target]?.disabled()) {
|
|
1133
|
-
target = this.findFirst(items) ?? target;
|
|
1134
|
-
}
|
|
1135
|
-
if (target !== active) {
|
|
1136
|
-
untracked(() => this.activeIndex.set(target));
|
|
1137
|
-
}
|
|
1138
|
-
items.forEach((item, i) => item.elementRef.nativeElement.setAttribute('tabindex', i === target ? '0' : '-1'));
|
|
1351
|
+
// Standard mode: match by array index. When the list changed under an
|
|
1352
|
+
// unchanged index, the item that held the tab stop is looked up again,
|
|
1353
|
+
// so a removal or reorder before it does not hand the stop to another
|
|
1354
|
+
// item. The tab stop must land on an enabled item - fall back to the
|
|
1355
|
+
// first enabled one when the target is disabled (initial index into a
|
|
1356
|
+
// disabled leaf, or the active item got disabled). The model is written
|
|
1357
|
+
// back so keyboard navigation anchors where the tab stop actually sits.
|
|
1358
|
+
// An empty list keeps the model untouched so a repopulated list
|
|
1359
|
+
// restores it.
|
|
1360
|
+
if (items.length === 0) {
|
|
1361
|
+
return;
|
|
1139
1362
|
}
|
|
1363
|
+
let anchor = active;
|
|
1364
|
+
if (items !== previousItems && active === previousActive) {
|
|
1365
|
+
const held = previousItems[active];
|
|
1366
|
+
const moved = held ? items.indexOf(held) : -1;
|
|
1367
|
+
anchor = moved >= 0 ? moved : active;
|
|
1368
|
+
}
|
|
1369
|
+
let target = Math.max(0, Math.min(anchor, items.length - 1));
|
|
1370
|
+
if (items[target]?.disabled()) {
|
|
1371
|
+
target = this.findFirst(items) ?? target;
|
|
1372
|
+
}
|
|
1373
|
+
previousItems = items;
|
|
1374
|
+
previousActive = target;
|
|
1375
|
+
if (target !== active) {
|
|
1376
|
+
untracked(() => this.activeIndex.set(target));
|
|
1377
|
+
}
|
|
1378
|
+
items.forEach((item, i) => item.elementRef.nativeElement.setAttribute('tabindex', i === target ? '0' : '-1'));
|
|
1140
1379
|
});
|
|
1141
1380
|
}
|
|
1142
1381
|
/**
|
|
@@ -1172,6 +1411,9 @@ class CngxRovingTabindex {
|
|
|
1172
1411
|
if (event.ctrlKey || event.metaKey || event.altKey) {
|
|
1173
1412
|
return;
|
|
1174
1413
|
}
|
|
1414
|
+
if (!this.ownsKey(event)) {
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1175
1417
|
const vc = this.virtualCount();
|
|
1176
1418
|
const allItems = this.items();
|
|
1177
1419
|
const isVirtual = vc != null;
|
|
@@ -1224,6 +1466,24 @@ class CngxRovingTabindex {
|
|
|
1224
1466
|
event.preventDefault();
|
|
1225
1467
|
}
|
|
1226
1468
|
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Whether the group may take the key: not one a nested widget already
|
|
1471
|
+
* handled, not part of an IME composition, not from a text field (an
|
|
1472
|
+
* `<input>` item or one inside an item keeps its caret keys) and not from
|
|
1473
|
+
* inside a nested widget that owns its arrows.
|
|
1474
|
+
*/
|
|
1475
|
+
ownsKey(event) {
|
|
1476
|
+
if (event.defaultPrevented || isComposingKeydown(event)) {
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1479
|
+
const target = event.target;
|
|
1480
|
+
if (isTextEntryTarget(target)) {
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
const host = this.hostEl.nativeElement;
|
|
1484
|
+
const widget = target?.closest(ARROW_KEY_WIDGETS) ?? null;
|
|
1485
|
+
return widget === null || widget === host || !host.contains(widget);
|
|
1486
|
+
}
|
|
1227
1487
|
/**
|
|
1228
1488
|
* Keeps `activeIndex` in sync with real focus (APG): when an item gains
|
|
1229
1489
|
* focus by any means - pointer click, script focus, assistive tech - the
|
|
@@ -1324,6 +1584,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1324
1584
|
},
|
|
1325
1585
|
}]
|
|
1326
1586
|
}], ctorParameters: () => [], propDecorators: { orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }, { type: i0.Output, args: ["orientationChange"] }], loop: [{ type: i0.Input, args: [{ isSignal: true, alias: "loop", required: false }] }], activeIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeIndex", required: false }] }, { type: i0.Output, args: ["activeIndexChange"] }], virtualCount: [{ type: i0.Input, args: [{ isSignal: true, alias: "virtualCount", required: false }] }], items: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => CngxRovingItem), { isSignal: true }] }] } });
|
|
1587
|
+
/**
|
|
1588
|
+
* @internal The rendered item that holds the tab stop in virtual mode: the
|
|
1589
|
+
* one at the active index, or, while that index is outside the rendered
|
|
1590
|
+
* window, the rendered item nearest to it, so the group never drops out of
|
|
1591
|
+
* the Tab order. Focusing it moves the active index there (`focusin`).
|
|
1592
|
+
*/
|
|
1593
|
+
function virtualTabStop(items, active) {
|
|
1594
|
+
let nearest = null;
|
|
1595
|
+
let distance = Infinity;
|
|
1596
|
+
for (const item of items) {
|
|
1597
|
+
const raw = item.elementRef.nativeElement.dataset['cngxRecycleIndex'];
|
|
1598
|
+
if (raw == null) {
|
|
1599
|
+
continue;
|
|
1600
|
+
}
|
|
1601
|
+
const gap = Math.abs(Number(raw) - active);
|
|
1602
|
+
if (gap < distance) {
|
|
1603
|
+
nearest = item;
|
|
1604
|
+
distance = gap;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
return nearest;
|
|
1608
|
+
}
|
|
1327
1609
|
|
|
1328
1610
|
/**
|
|
1329
1611
|
* DI token for content-projected items that should register with the
|
|
@@ -1338,10 +1620,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1338
1620
|
* The contained directive must expose `id`, `value`, `label`, and optionally
|
|
1339
1621
|
* `disabled` as signals - the AD reads them reactively.
|
|
1340
1622
|
*
|
|
1341
|
-
* @category common/a11y
|
|
1342
1623
|
* @wcag AA
|
|
1343
1624
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/active-descendant/ad-item.token.ts
|
|
1344
|
-
* @since 0.
|
|
1625
|
+
* @since 0.3.0
|
|
1345
1626
|
*/
|
|
1346
1627
|
const CNGX_AD_ITEM = new InjectionToken('CNGX_AD_ITEM');
|
|
1347
1628
|
|
|
@@ -1372,21 +1653,22 @@ const CNGX_AD_ITEM = new InjectionToken('CNGX_AD_ITEM');
|
|
|
1372
1653
|
* checks, typeahead labels) map absolute indices onto the rendered subset.
|
|
1373
1654
|
* Targets outside the window surface as `pendingHighlight`; the consumer
|
|
1374
1655
|
* scrolls them into view (`connectRecyclerToActiveDescendant`) and the
|
|
1375
|
-
* directive clears the pending state once the target renders
|
|
1656
|
+
* directive clears the pending state once the target renders; no
|
|
1657
|
+
* `clearPendingHighlight()` call is needed.
|
|
1376
1658
|
*
|
|
1377
1659
|
* ### Material/CDK equivalent
|
|
1378
1660
|
*
|
|
1379
1661
|
* Same model as `cdk-listbox` and `mat-select`, without the visual shell and
|
|
1380
1662
|
* driven by signals instead of `ListKeyManager`.
|
|
1381
1663
|
*
|
|
1382
|
-
* @category common/a11y
|
|
1383
|
-
* @docsKind primary
|
|
1384
1664
|
* @wcag AA
|
|
1385
1665
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/active-descendant/active-descendant.directive.ts
|
|
1386
|
-
* @since 0.
|
|
1666
|
+
* @since 0.3.0
|
|
1387
1667
|
* @relatedTo CngxRovingTabindex, CngxListbox, CngxMenu
|
|
1388
|
-
* <example-url
|
|
1389
|
-
* <example-url
|
|
1668
|
+
* <example-url>/#/common/a11y/active-descendant/listbox-with-items-input</example-url>
|
|
1669
|
+
* <example-url>/#/common/a11y/active-descendant/typeahead</example-url>
|
|
1670
|
+
* <example-url>/#/common/a11y/active-descendant/horizontal-option-row</example-url>
|
|
1671
|
+
* @axis level atom
|
|
1390
1672
|
*/
|
|
1391
1673
|
class CngxActiveDescendant {
|
|
1392
1674
|
/**
|
|
@@ -1422,6 +1704,14 @@ class CngxActiveDescendant {
|
|
|
1422
1704
|
* Ignored when `virtualCount` is unset.
|
|
1423
1705
|
*/
|
|
1424
1706
|
windowStart = input(0, ...(ngDevMode ? [{ debugName: "windowStart" }] : /* istanbul ignore next */ []));
|
|
1707
|
+
/**
|
|
1708
|
+
* The full list in absolute index space, for a windowed list whose rendered
|
|
1709
|
+
* rows are only part of it. When bound, typeahead searches this list and a
|
|
1710
|
+
* match anywhere in it becomes the highlight; `typeaheadMissed` then means no
|
|
1711
|
+
* match in the whole list. Unbound, the rendered window stays the search
|
|
1712
|
+
* space. Items are read for `label` and `disabled` only, so `id` may be empty.
|
|
1713
|
+
*/
|
|
1714
|
+
typeaheadItems = input(undefined, ...(ngDevMode ? [{ debugName: "typeaheadItems" }] : /* istanbul ignore next */ []));
|
|
1425
1715
|
/**
|
|
1426
1716
|
* Equality used to find the previously active value again after the item
|
|
1427
1717
|
* list changes. Defaults to `Object.is`; pass the same comparator as the
|
|
@@ -1449,11 +1739,18 @@ class CngxActiveDescendant {
|
|
|
1449
1739
|
registered = contentChildren(CNGX_AD_ITEM, { ...(ngDevMode ? { debugName: "registered" } : /* istanbul ignore next */ {}), descendants: true });
|
|
1450
1740
|
/** Document writing direction - flips the horizontal-arrow steps under `rtl` (APG). */
|
|
1451
1741
|
direction = injectDirection();
|
|
1452
|
-
/**
|
|
1742
|
+
/** Holds `autoHighlightFirst` back until after first render. */
|
|
1453
1743
|
initialized = signal(false, ...(ngDevMode ? [{ debugName: "initialized" }] : /* istanbul ignore next */ []));
|
|
1454
|
-
/**
|
|
1455
|
-
|
|
1456
|
-
|
|
1744
|
+
/**
|
|
1745
|
+
* A highlight gesture that fired while the option rows were not in the DOM
|
|
1746
|
+
* (a deferred-render panel just opened, OD5): the id space does not exist
|
|
1747
|
+
* yet, so the gesture is kept as INTENT - not a resolved index, which an
|
|
1748
|
+
* empty item space resolves to nothing. It is a source of
|
|
1749
|
+
* `activeIndexState` and resolves there once the rows render. Written only
|
|
1750
|
+
* by the imperative highlight methods; every index write clears it.
|
|
1751
|
+
* Non-virtual path only; the virtual path uses `pendingHighlight`.
|
|
1752
|
+
*/
|
|
1753
|
+
pendingIntentState = signal(null, ...(ngDevMode ? [{ debugName: "pendingIntentState" }] : /* istanbul ignore next */ []));
|
|
1457
1754
|
/**
|
|
1458
1755
|
* Resolved item list. Input `items` wins; otherwise the contentChildren
|
|
1459
1756
|
* handles are projected into `ActiveDescendantItem` shape.
|
|
@@ -1469,24 +1766,38 @@ class CngxActiveDescendant {
|
|
|
1469
1766
|
* -1 means "no active item". Range is `[0, totalCount())`.
|
|
1470
1767
|
*
|
|
1471
1768
|
* Navigation writes the index; a change of the item space re-derives it.
|
|
1472
|
-
*
|
|
1473
|
-
* changes, the previously active value is looked up again with
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1476
|
-
*
|
|
1769
|
+
* In a plain list the highlight follows its value: after the item list
|
|
1770
|
+
* changes, the previously active value is looked up again with `compareWith`,
|
|
1771
|
+
* and gone means no highlight. In a virtual window it holds its absolute
|
|
1772
|
+
* index, because the rendered rows trail `windowStart` and cannot say where a
|
|
1773
|
+
* value sits; a window turning plain drops it. The result is clamped to the
|
|
1774
|
+
* new item space, so the next arrow press never starts from a ghost index.
|
|
1775
|
+
*
|
|
1776
|
+
* A pending open gesture (`pendingIntentState`) resolves here against every
|
|
1777
|
+
* populated item space until an index write clears it, so rows that arrive
|
|
1778
|
+
* in several passes settle on the gesture's target.
|
|
1477
1779
|
*/
|
|
1478
1780
|
activeIndexState = linkedSignal({ ...(ngDevMode ? { debugName: "activeIndexState" } : /* istanbul ignore next */ {}), source: () => ({
|
|
1479
1781
|
items: this.resolvedItems(),
|
|
1480
1782
|
total: this.totalCount(),
|
|
1481
|
-
offset: this.windowOffset(),
|
|
1482
1783
|
virtual: this.virtualCount() != null,
|
|
1784
|
+
offset: this.windowOffset(),
|
|
1483
1785
|
compareWith: this.compareWith(),
|
|
1786
|
+
skipDisabled: this.skipDisabled(),
|
|
1787
|
+
intent: this.pendingIntentState(),
|
|
1484
1788
|
}),
|
|
1485
1789
|
computation: (source, previous) => {
|
|
1790
|
+
const { intent } = source;
|
|
1791
|
+
if (intent !== null && source.items.length > 0) {
|
|
1792
|
+
return resolveIntent({ ...source, intent });
|
|
1793
|
+
}
|
|
1486
1794
|
if (!previous) {
|
|
1487
1795
|
return -1;
|
|
1488
1796
|
}
|
|
1489
|
-
|
|
1797
|
+
const index = clampIndex(reResolveIndex(source, previous.source, previous.value), source.total);
|
|
1798
|
+
// An item that turned disabled cannot hold a highlight navigation skips.
|
|
1799
|
+
const disabled = source.skipDisabled && !!source.items[index - source.offset]?.disabled;
|
|
1800
|
+
return disabled ? -1 : index;
|
|
1490
1801
|
} });
|
|
1491
1802
|
/** Current active index. `-1` when no item is highlighted. */
|
|
1492
1803
|
activeIndex = computed(() => {
|
|
@@ -1497,6 +1808,33 @@ class CngxActiveDescendant {
|
|
|
1497
1808
|
}
|
|
1498
1809
|
return idx;
|
|
1499
1810
|
}, ...(ngDevMode ? [{ debugName: "activeIndex" }] : /* istanbul ignore next */ []));
|
|
1811
|
+
/**
|
|
1812
|
+
* The highlight plus whether its row is rendered. Structural equal: a window
|
|
1813
|
+
* move that leaves both unchanged notifies nobody.
|
|
1814
|
+
*/
|
|
1815
|
+
highlightPlacement = computed(() => {
|
|
1816
|
+
const index = this.activeIndex();
|
|
1817
|
+
return {
|
|
1818
|
+
index,
|
|
1819
|
+
rendered: index >= 0 && this.isRendered(index),
|
|
1820
|
+
virtual: this.virtualCount() != null,
|
|
1821
|
+
};
|
|
1822
|
+
}, { ...(ngDevMode ? { debugName: "highlightPlacement" } : /* istanbul ignore next */ {}), equal: (a, b) => a.index === b.index && a.rendered === b.rendered && a.virtual === b.virtual });
|
|
1823
|
+
/**
|
|
1824
|
+
* Index the highlight moved to while its row is not rendered. Armed by the
|
|
1825
|
+
* highlight change alone and cleared when the row renders; the same highlight
|
|
1826
|
+
* leaving the window later stays cleared, so scrolling a virtual list away
|
|
1827
|
+
* never asks to be scrolled back.
|
|
1828
|
+
*/
|
|
1829
|
+
pendingHighlightState = linkedSignal({ ...(ngDevMode ? { debugName: "pendingHighlightState" } : /* istanbul ignore next */ {}), source: this.highlightPlacement,
|
|
1830
|
+
computation: (placement, previous) => {
|
|
1831
|
+
if (!placement.virtual || placement.index < 0 || placement.rendered) {
|
|
1832
|
+
return null;
|
|
1833
|
+
}
|
|
1834
|
+
return previous?.source.index === placement.index ? previous.value : placement.index;
|
|
1835
|
+
} });
|
|
1836
|
+
/** Index of an item that should be highlighted but is not in the DOM. */
|
|
1837
|
+
pendingHighlight = this.pendingHighlightState.asReadonly();
|
|
1500
1838
|
/**
|
|
1501
1839
|
* `activeIndex` always mapped back to an item. `null` when no active index
|
|
1502
1840
|
* or the item is out of rendered range (virtual mode).
|
|
@@ -1517,8 +1855,17 @@ class CngxActiveDescendant {
|
|
|
1517
1855
|
highlightedItem = computed(() => this.activeItem(), { ...(ngDevMode ? { debugName: "highlightedItem" } : /* istanbul ignore next */ {}), equal: (a, b) => a === b || (a !== null && b !== null && a.id === b.id) });
|
|
1518
1856
|
activeId = computed(() => this.activeItem()?.id ?? null, ...(ngDevMode ? [{ debugName: "activeId" }] : /* istanbul ignore next */ []));
|
|
1519
1857
|
activeValue = computed(() => this.activeItem()?.value ?? null, ...(ngDevMode ? [{ debugName: "activeValue" }] : /* istanbul ignore next */ []));
|
|
1520
|
-
|
|
1521
|
-
|
|
1858
|
+
typeaheadWalker = createTypeaheadWalker({
|
|
1859
|
+
debounceMs: this.typeaheadDebounce,
|
|
1860
|
+
locale: this.locale,
|
|
1861
|
+
});
|
|
1862
|
+
/**
|
|
1863
|
+
* `true` while a typeahead term is being typed (the buffer has not reset
|
|
1864
|
+
* yet). A space typed then belongs to the term ("new y" reaches "New
|
|
1865
|
+
* York") instead of activating the highlight. External keyboard hosts read
|
|
1866
|
+
* it to route Space through {@link typeaheadChar}.
|
|
1867
|
+
*/
|
|
1868
|
+
typeaheadActive = computed(() => this.typeaheadWalker.buffer() !== '', ...(ngDevMode ? [{ debugName: "typeaheadActive" }] : /* istanbul ignore next */ []));
|
|
1522
1869
|
constructor() {
|
|
1523
1870
|
afterNextRender(() => this.initialized.set(true));
|
|
1524
1871
|
effect(() => {
|
|
@@ -1540,48 +1887,95 @@ class CngxActiveDescendant {
|
|
|
1540
1887
|
hadHighlight = true;
|
|
1541
1888
|
this.highlighted.emit(item);
|
|
1542
1889
|
});
|
|
1890
|
+
// One DOM scroll per highlight change, delayed until the row renders. A
|
|
1891
|
+
// window move alone never scrolls: the row of an unchanged highlight
|
|
1892
|
+
// re-entering the window must not pull the list back to it.
|
|
1893
|
+
let lastIndex = -1;
|
|
1894
|
+
let scrollDue = false;
|
|
1543
1895
|
effect(() => {
|
|
1544
|
-
const
|
|
1545
|
-
if (
|
|
1546
|
-
|
|
1896
|
+
const { index, rendered } = this.highlightPlacement();
|
|
1897
|
+
if (index !== lastIndex) {
|
|
1898
|
+
lastIndex = index;
|
|
1899
|
+
scrollDue = index >= 0;
|
|
1547
1900
|
}
|
|
1548
|
-
if (
|
|
1549
|
-
|
|
1550
|
-
this.pendingHighlightState.set(idx);
|
|
1551
|
-
return;
|
|
1552
|
-
}
|
|
1553
|
-
this.pendingHighlightState.set(null);
|
|
1901
|
+
if (!scrollDue || !rendered) {
|
|
1902
|
+
return;
|
|
1554
1903
|
}
|
|
1904
|
+
scrollDue = false;
|
|
1555
1905
|
queueMicrotask(() => this.scrollActiveIntoView());
|
|
1556
1906
|
});
|
|
1557
|
-
inject(DestroyRef).onDestroy(() =>
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1907
|
+
inject(DestroyRef).onDestroy(() => this.typeaheadWalker.clear());
|
|
1908
|
+
}
|
|
1909
|
+
/**
|
|
1910
|
+
* Non-virtual path with no rendered rows yet (a deferred-render panel just
|
|
1911
|
+
* opened, OD5): the option id space does not exist, so a highlight resolves
|
|
1912
|
+
* against nothing and is lost. Remember the gesture as intent -
|
|
1913
|
+
* `activeIndexState` resolves it once the rows render - and report that it
|
|
1914
|
+
* was deferred. The virtual path never defers here; its out-of-window
|
|
1915
|
+
* targets surface through `pendingHighlight` instead.
|
|
1916
|
+
*/
|
|
1917
|
+
deferIfUnrendered(intent) {
|
|
1918
|
+
if (this.virtualCount() == null && this.resolvedItems().length === 0) {
|
|
1919
|
+
this.pendingIntentState.set(intent);
|
|
1920
|
+
return true;
|
|
1921
|
+
}
|
|
1922
|
+
return false;
|
|
1923
|
+
}
|
|
1924
|
+
/** Index write of a navigation step; a resolved intent never re-applies after it. */
|
|
1925
|
+
writeIndex(index) {
|
|
1926
|
+
this.pendingIntentState.set(null);
|
|
1927
|
+
this.activeIndexState.set(index);
|
|
1562
1928
|
}
|
|
1929
|
+
/**
|
|
1930
|
+
* Moves the highlight to the next item after the active one. Disabled items
|
|
1931
|
+
* are skipped while `skipDisabled` is true; past the last item it wraps to the
|
|
1932
|
+
* first when `loop` is true and stays put otherwise. With no rows it does
|
|
1933
|
+
* nothing: a step inside an empty list is not an open gesture to keep.
|
|
1934
|
+
*/
|
|
1563
1935
|
highlightNext() {
|
|
1564
1936
|
const next = this.findFrom(this.activeIndexState(), 1);
|
|
1565
1937
|
if (next !== null) {
|
|
1566
|
-
this.
|
|
1938
|
+
this.writeIndex(next);
|
|
1567
1939
|
}
|
|
1568
1940
|
}
|
|
1941
|
+
/**
|
|
1942
|
+
* Moves the highlight to the item before the active one. Disabled items are
|
|
1943
|
+
* skipped while `skipDisabled` is true; before the first item it wraps to the
|
|
1944
|
+
* last when `loop` is true and stays put otherwise. With no rows it does
|
|
1945
|
+
* nothing.
|
|
1946
|
+
*/
|
|
1569
1947
|
highlightPrev() {
|
|
1570
1948
|
const next = this.findFrom(this.activeIndexState(), -1);
|
|
1571
1949
|
if (next !== null) {
|
|
1572
|
-
this.
|
|
1950
|
+
this.writeIndex(next);
|
|
1573
1951
|
}
|
|
1574
1952
|
}
|
|
1953
|
+
/**
|
|
1954
|
+
* Moves the highlight to the first enabled item (the first item when
|
|
1955
|
+
* `skipDisabled` is false). Does nothing when no item qualifies.
|
|
1956
|
+
*/
|
|
1575
1957
|
highlightFirst() {
|
|
1958
|
+
if (this.deferIfUnrendered({ kind: 'first' })) {
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1576
1961
|
const first = this.findBoundary(1);
|
|
1577
1962
|
if (first !== null) {
|
|
1578
|
-
this.
|
|
1963
|
+
this.writeIndex(first);
|
|
1579
1964
|
}
|
|
1580
1965
|
}
|
|
1966
|
+
/**
|
|
1967
|
+
* Moves the highlight to the last enabled item (the last item when
|
|
1968
|
+
* `skipDisabled` is false). With a virtual count it targets the last absolute
|
|
1969
|
+
* index even when that item is not rendered yet. Does nothing when no item
|
|
1970
|
+
* qualifies.
|
|
1971
|
+
*/
|
|
1581
1972
|
highlightLast() {
|
|
1973
|
+
if (this.deferIfUnrendered({ kind: 'last' })) {
|
|
1974
|
+
return;
|
|
1975
|
+
}
|
|
1582
1976
|
const last = this.findBoundary(-1);
|
|
1583
1977
|
if (last !== null) {
|
|
1584
|
-
this.
|
|
1978
|
+
this.writeIndex(last);
|
|
1585
1979
|
}
|
|
1586
1980
|
}
|
|
1587
1981
|
/**
|
|
@@ -1589,6 +1983,9 @@ class CngxActiveDescendant {
|
|
|
1589
1983
|
* Disabled items are rejected when `skipDisabled()` is true.
|
|
1590
1984
|
*/
|
|
1591
1985
|
highlightByIndex(index) {
|
|
1986
|
+
if (this.deferIfUnrendered({ kind: 'byIndex', index })) {
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1592
1989
|
const total = this.totalCount();
|
|
1593
1990
|
if (index < 0 || index >= total) {
|
|
1594
1991
|
return;
|
|
@@ -1596,27 +1993,32 @@ class CngxActiveDescendant {
|
|
|
1596
1993
|
if (this.skipDisabled() && this.isDisabledAt(index)) {
|
|
1597
1994
|
return;
|
|
1598
1995
|
}
|
|
1599
|
-
this.
|
|
1996
|
+
this.writeIndex(index);
|
|
1600
1997
|
}
|
|
1601
1998
|
/**
|
|
1602
|
-
* Highlight the first rendered item whose value matches (via `
|
|
1999
|
+
* Highlight the first rendered item whose value matches (via `compareWith`).
|
|
1603
2000
|
* No-op if no match. Disabled items are rejected when `skipDisabled()` is
|
|
1604
2001
|
* true. In virtual mode only the rendered window is searched; the resolved
|
|
1605
2002
|
* index is absolute.
|
|
1606
2003
|
*/
|
|
1607
2004
|
highlightByValue(value) {
|
|
2005
|
+
if (this.deferIfUnrendered({ kind: 'byValue', value })) {
|
|
2006
|
+
return;
|
|
2007
|
+
}
|
|
1608
2008
|
const items = this.resolvedItems();
|
|
1609
|
-
const
|
|
2009
|
+
const compare = this.compareWith();
|
|
2010
|
+
const idx = items.findIndex((it) => compare(it.value, value));
|
|
1610
2011
|
if (idx < 0) {
|
|
1611
2012
|
return;
|
|
1612
2013
|
}
|
|
1613
2014
|
if (this.skipDisabled() && items[idx].disabled) {
|
|
1614
2015
|
return;
|
|
1615
2016
|
}
|
|
1616
|
-
this.
|
|
2017
|
+
this.writeIndex(idx + this.windowOffset());
|
|
1617
2018
|
}
|
|
1618
|
-
/** Clear the highlight. */
|
|
2019
|
+
/** Clear the highlight, including a gesture still pending a deferred render. */
|
|
1619
2020
|
resetHighlight() {
|
|
2021
|
+
this.pendingIntentState.set(null);
|
|
1620
2022
|
this.activeIndexState.set(-1);
|
|
1621
2023
|
}
|
|
1622
2024
|
/** Emit `activated` with the current item's value. No-op if nothing active. */
|
|
@@ -1626,7 +2028,11 @@ class CngxActiveDescendant {
|
|
|
1626
2028
|
this.activated.emit(item.value);
|
|
1627
2029
|
}
|
|
1628
2030
|
}
|
|
1629
|
-
/**
|
|
2031
|
+
/**
|
|
2032
|
+
* Drops `pendingHighlight` without waiting for the row to render. Optional:
|
|
2033
|
+
* the directive clears it on its own once the target row renders, and
|
|
2034
|
+
* `connectRecyclerToActiveDescendant` never calls this.
|
|
2035
|
+
*/
|
|
1630
2036
|
clearPendingHighlight() {
|
|
1631
2037
|
this.pendingHighlightState.set(null);
|
|
1632
2038
|
}
|
|
@@ -1634,30 +2040,49 @@ class CngxActiveDescendant {
|
|
|
1634
2040
|
// Never hijack browser/app shortcuts: Ctrl/Cmd/Alt combos pass through
|
|
1635
2041
|
// untouched (Ctrl+C would otherwise hit the typeahead branch and get
|
|
1636
2042
|
// preventDefault'd). Shift stays allowed - it produces printable chars.
|
|
2043
|
+
// A key a nested widget already handled, and every key of an IME
|
|
2044
|
+
// composition (the commit Enter included), is not ours either.
|
|
1637
2045
|
if (event.ctrlKey || event.metaKey || event.altKey) {
|
|
1638
2046
|
return;
|
|
1639
2047
|
}
|
|
2048
|
+
if (event.defaultPrevented || isComposingKeydown(event)) {
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
1640
2051
|
// Skip events from editable descendants. Without this, every
|
|
1641
2052
|
// printable key typed into a descendant <input> hits AD's typeahead
|
|
1642
2053
|
// branch, gets preventDefault'd, and never reaches the input.
|
|
1643
2054
|
const target = event.target;
|
|
1644
|
-
if (target
|
|
2055
|
+
if (target !== event.currentTarget && isTextEntryTarget(target)) {
|
|
1645
2056
|
return;
|
|
1646
2057
|
}
|
|
2058
|
+
// A text host (combobox input, textarea) keeps the caret keys and the
|
|
2059
|
+
// characters it types: only the arrows and Enter drive the list.
|
|
2060
|
+
const textHost = isTextEntryTarget(this.hostEl.nativeElement);
|
|
1647
2061
|
const key = event.key;
|
|
1648
2062
|
if (this.isNavKey(key)) {
|
|
2063
|
+
if (textHost && (key === 'Home' || key === 'End')) {
|
|
2064
|
+
return;
|
|
2065
|
+
}
|
|
1649
2066
|
const before = this.activeIndexState();
|
|
2067
|
+
const intentBefore = this.pendingIntentState();
|
|
1650
2068
|
this.dispatchNav(key);
|
|
1651
|
-
|
|
2069
|
+
const moved = this.activeIndexState() !== before;
|
|
2070
|
+
const deferred = this.pendingIntentState() !== intentBefore;
|
|
2071
|
+
if (moved || deferred) {
|
|
1652
2072
|
event.preventDefault();
|
|
1653
2073
|
}
|
|
1654
2074
|
return;
|
|
1655
2075
|
}
|
|
2076
|
+
if (textHost && (key === ' ' || isPrintableChar(key))) {
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
if (key === ' ' && this.typeahead() && this.typeaheadActive()) {
|
|
2080
|
+
event.preventDefault();
|
|
2081
|
+
this.handleTypeahead(key);
|
|
2082
|
+
return;
|
|
2083
|
+
}
|
|
1656
2084
|
if (key === 'Enter' || key === ' ') {
|
|
1657
|
-
|
|
1658
|
-
event.preventDefault();
|
|
1659
|
-
this.activateCurrent();
|
|
1660
|
-
}
|
|
2085
|
+
this.handleActivationKey(event, key);
|
|
1661
2086
|
return;
|
|
1662
2087
|
}
|
|
1663
2088
|
if (this.typeahead() && isPrintableChar(key)) {
|
|
@@ -1665,6 +2090,41 @@ class CngxActiveDescendant {
|
|
|
1665
2090
|
this.handleTypeahead(key);
|
|
1666
2091
|
}
|
|
1667
2092
|
}
|
|
2093
|
+
/** @internal True when `el` renders one of the host's own items. */
|
|
2094
|
+
isOwnItemElement(el) {
|
|
2095
|
+
const id = el.id;
|
|
2096
|
+
return id !== '' && this.resolvedItems().some((item) => item.id === id);
|
|
2097
|
+
}
|
|
2098
|
+
/** Descendants that own Enter / Space; `CNGX_NESTED_INTERACTIVE_SELECTOR`. */
|
|
2099
|
+
nestedInteractive = inject(CNGX_NESTED_INTERACTIVE_SELECTOR);
|
|
2100
|
+
handleActivationKey(event, key) {
|
|
2101
|
+
const host = this.hostEl.nativeElement;
|
|
2102
|
+
// A focused control inside the host (a Retry button in an error banner)
|
|
2103
|
+
// owns its Enter / Space: no preventDefault, so its native activation runs,
|
|
2104
|
+
// and the active item stays untouched. The host's own item elements
|
|
2105
|
+
// (a role="menuitem" row that took focus from a click) are not such a
|
|
2106
|
+
// control: their keys still activate through the directive.
|
|
2107
|
+
const target = event.target;
|
|
2108
|
+
const interactive = target?.closest(this.nestedInteractive);
|
|
2109
|
+
if (interactive &&
|
|
2110
|
+
interactive !== host &&
|
|
2111
|
+
host.contains(interactive) &&
|
|
2112
|
+
!this.isOwnItemElement(interactive)) {
|
|
2113
|
+
return;
|
|
2114
|
+
}
|
|
2115
|
+
if (this.activeItem()) {
|
|
2116
|
+
event.preventDefault();
|
|
2117
|
+
this.activateCurrent();
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2120
|
+
// Nothing to activate: Space would scroll the page from a focused host.
|
|
2121
|
+
// A text host never gets here with Space (the keydown handler leaves it
|
|
2122
|
+
// to the field). Enter stays untouched so a consumer's own Enter handler
|
|
2123
|
+
// still runs.
|
|
2124
|
+
if (key === ' ') {
|
|
2125
|
+
event.preventDefault();
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
1668
2128
|
isNavKey(key) {
|
|
1669
2129
|
switch (key) {
|
|
1670
2130
|
case 'ArrowDown':
|
|
@@ -1721,7 +2181,8 @@ class CngxActiveDescendant {
|
|
|
1721
2181
|
* semantics on a separate listbox.
|
|
1722
2182
|
*
|
|
1723
2183
|
* Consumers should only forward single-character printable keys (`length === 1`,
|
|
1724
|
-
* non-whitespace)
|
|
2184
|
+
* non-whitespace), plus a space while {@link typeaheadActive} is `true`.
|
|
2185
|
+
* Navigation keys and non-printables must not be forwarded.
|
|
1725
2186
|
*/
|
|
1726
2187
|
typeaheadChar(ch) {
|
|
1727
2188
|
if (!this.typeahead()) {
|
|
@@ -1730,48 +2191,24 @@ class CngxActiveDescendant {
|
|
|
1730
2191
|
this.handleTypeahead(ch);
|
|
1731
2192
|
}
|
|
1732
2193
|
handleTypeahead(ch) {
|
|
1733
|
-
const
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
this.typeaheadBuffer.set('');
|
|
1741
|
-
this.typeaheadTimer = null;
|
|
1742
|
-
}, this.typeaheadDebounce());
|
|
1743
|
-
// Labels exist only for rendered items, so the search space is the
|
|
1744
|
-
// rendered window; matches map back to absolute indices in virtual mode.
|
|
1745
|
-
const items = this.resolvedItems();
|
|
1746
|
-
const skip = this.skipDisabled();
|
|
1747
|
-
const count = items.length;
|
|
1748
|
-
// APG cycle: a single-character query (including a repeated letter, whose
|
|
1749
|
-
// buffer collapses back to that letter) searches AFTER the active item so
|
|
1750
|
-
// each press advances through the matches. A genuine multi-character query
|
|
1751
|
-
// keeps matching the current item first.
|
|
1752
|
-
const sameChar = next.length > 1 && [...next].every((c) => c === next[0]);
|
|
1753
|
-
const term = sameChar ? next[0] : next;
|
|
1754
|
-
if (count === 0) {
|
|
2194
|
+
const term = this.typeaheadWalker.type(ch);
|
|
2195
|
+
// Labels exist only for rendered items unless the host hands the full list
|
|
2196
|
+
// over, so the search space is the rendered window by default; matches map
|
|
2197
|
+
// back to absolute indices in virtual mode.
|
|
2198
|
+
const fullList = this.typeaheadItems();
|
|
2199
|
+
const items = fullList ?? this.resolvedItems();
|
|
2200
|
+
if (items.length === 0) {
|
|
1755
2201
|
this.typeaheadMissed.emit(term);
|
|
1756
2202
|
return;
|
|
1757
2203
|
}
|
|
1758
|
-
const
|
|
1759
|
-
const activeRel = this.activeIndexState() < 0 ? -1 : this.activeIndexState() -
|
|
1760
|
-
const
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
const rel = (((startRel + step) % count) + count) % count;
|
|
1765
|
-
const candidate = items[rel];
|
|
1766
|
-
if (skip && candidate.disabled) {
|
|
1767
|
-
continue;
|
|
1768
|
-
}
|
|
1769
|
-
if (matches(candidate.label, candidate)) {
|
|
1770
|
-
this.activeIndexState.set(rel + windowOffset);
|
|
1771
|
-
return;
|
|
1772
|
-
}
|
|
2204
|
+
const offset = fullList ? 0 : this.windowOffset();
|
|
2205
|
+
const activeRel = this.activeIndexState() < 0 ? -1 : this.activeIndexState() - offset;
|
|
2206
|
+
const rel = this.typeaheadWalker.find(items, term, activeRel, this.skipDisabled());
|
|
2207
|
+
if (rel < 0) {
|
|
2208
|
+
this.typeaheadMissed.emit(term);
|
|
2209
|
+
return;
|
|
1773
2210
|
}
|
|
1774
|
-
this.
|
|
2211
|
+
this.writeIndex(rel + offset);
|
|
1775
2212
|
}
|
|
1776
2213
|
findFrom(current, direction) {
|
|
1777
2214
|
return resolveStepFrom(current, direction, {
|
|
@@ -1832,7 +2269,7 @@ class CngxActiveDescendant {
|
|
|
1832
2269
|
}
|
|
1833
2270
|
}
|
|
1834
2271
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxActiveDescendant, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1835
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxActiveDescendant, isStandalone: true, selector: "[cngxActiveDescendant]", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, typeahead: { classPropertyName: "typeahead", publicName: "typeahead", isSignal: true, isRequired: false, transformFunction: null }, typeaheadDebounce: { classPropertyName: "typeaheadDebounce", publicName: "typeaheadDebounce", isSignal: true, isRequired: false, transformFunction: null }, autoHighlightFirst: { classPropertyName: "autoHighlightFirst", publicName: "autoHighlightFirst", isSignal: true, isRequired: false, transformFunction: null }, skipDisabled: { classPropertyName: "skipDisabled", publicName: "skipDisabled", isSignal: true, isRequired: false, transformFunction: null }, virtualCount: { classPropertyName: "virtualCount", publicName: "virtualCount", isSignal: true, isRequired: false, transformFunction: null }, windowStart: { classPropertyName: "windowStart", publicName: "windowStart", isSignal: true, isRequired: false, transformFunction: null }, compareWith: { classPropertyName: "compareWith", publicName: "compareWith", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { activated: "activated", highlighted: "highlighted", typeaheadMissed: "typeaheadMissed" }, host: { listeners: { "keydown": "handleKeydown($event)" }, properties: { "attr.aria-activedescendant": "activeId()" } }, queries: [{ propertyName: "registered", predicate: CNGX_AD_ITEM, descendants: true, isSignal: true }], exportAs: ["cngxActiveDescendant"], ngImport: i0 });
|
|
2272
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxActiveDescendant, isStandalone: true, selector: "[cngxActiveDescendant]", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, typeahead: { classPropertyName: "typeahead", publicName: "typeahead", isSignal: true, isRequired: false, transformFunction: null }, typeaheadDebounce: { classPropertyName: "typeaheadDebounce", publicName: "typeaheadDebounce", isSignal: true, isRequired: false, transformFunction: null }, autoHighlightFirst: { classPropertyName: "autoHighlightFirst", publicName: "autoHighlightFirst", isSignal: true, isRequired: false, transformFunction: null }, skipDisabled: { classPropertyName: "skipDisabled", publicName: "skipDisabled", isSignal: true, isRequired: false, transformFunction: null }, virtualCount: { classPropertyName: "virtualCount", publicName: "virtualCount", isSignal: true, isRequired: false, transformFunction: null }, windowStart: { classPropertyName: "windowStart", publicName: "windowStart", isSignal: true, isRequired: false, transformFunction: null }, typeaheadItems: { classPropertyName: "typeaheadItems", publicName: "typeaheadItems", isSignal: true, isRequired: false, transformFunction: null }, compareWith: { classPropertyName: "compareWith", publicName: "compareWith", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { activated: "activated", highlighted: "highlighted", typeaheadMissed: "typeaheadMissed" }, host: { listeners: { "keydown": "handleKeydown($event)" }, properties: { "attr.aria-activedescendant": "activeId()" } }, queries: [{ propertyName: "registered", predicate: CNGX_AD_ITEM, descendants: true, isSignal: true }], exportAs: ["cngxActiveDescendant"], ngImport: i0 });
|
|
1836
2273
|
}
|
|
1837
2274
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxActiveDescendant, decorators: [{
|
|
1838
2275
|
type: Directive,
|
|
@@ -1845,26 +2282,52 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1845
2282
|
'(keydown)': 'handleKeydown($event)',
|
|
1846
2283
|
},
|
|
1847
2284
|
}]
|
|
1848
|
-
}], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], loop: [{ type: i0.Input, args: [{ isSignal: true, alias: "loop", required: false }] }], typeahead: [{ type: i0.Input, args: [{ isSignal: true, alias: "typeahead", required: false }] }], typeaheadDebounce: [{ type: i0.Input, args: [{ isSignal: true, alias: "typeaheadDebounce", required: false }] }], autoHighlightFirst: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoHighlightFirst", required: false }] }], skipDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "skipDisabled", required: false }] }], virtualCount: [{ type: i0.Input, args: [{ isSignal: true, alias: "virtualCount", required: false }] }], windowStart: [{ type: i0.Input, args: [{ isSignal: true, alias: "windowStart", required: false }] }], compareWith: [{ type: i0.Input, args: [{ isSignal: true, alias: "compareWith", required: false }] }], activated: [{ type: i0.Output, args: ["activated"] }], highlighted: [{ type: i0.Output, args: ["highlighted"] }], typeaheadMissed: [{ type: i0.Output, args: ["typeaheadMissed"] }], registered: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => CNGX_AD_ITEM), { ...{ descendants: true }, isSignal: true }] }] } });
|
|
2285
|
+
}], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], loop: [{ type: i0.Input, args: [{ isSignal: true, alias: "loop", required: false }] }], typeahead: [{ type: i0.Input, args: [{ isSignal: true, alias: "typeahead", required: false }] }], typeaheadDebounce: [{ type: i0.Input, args: [{ isSignal: true, alias: "typeaheadDebounce", required: false }] }], autoHighlightFirst: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoHighlightFirst", required: false }] }], skipDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "skipDisabled", required: false }] }], virtualCount: [{ type: i0.Input, args: [{ isSignal: true, alias: "virtualCount", required: false }] }], windowStart: [{ type: i0.Input, args: [{ isSignal: true, alias: "windowStart", required: false }] }], typeaheadItems: [{ type: i0.Input, args: [{ isSignal: true, alias: "typeaheadItems", required: false }] }], compareWith: [{ type: i0.Input, args: [{ isSignal: true, alias: "compareWith", required: false }] }], activated: [{ type: i0.Output, args: ["activated"] }], highlighted: [{ type: i0.Output, args: ["highlighted"] }], typeaheadMissed: [{ type: i0.Output, args: ["typeaheadMissed"] }], registered: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => CNGX_AD_ITEM), { ...{ descendants: true }, isSignal: true }] }] } });
|
|
2286
|
+
/** @internal Resolves an open gesture against a populated item space; -1 when nothing qualifies. */
|
|
2287
|
+
function resolveIntent(source) {
|
|
2288
|
+
const { items, offset, total, intent } = source;
|
|
2289
|
+
const isDisabledAt = source.skipDisabled
|
|
2290
|
+
? (i) => !!items[i - offset]?.disabled
|
|
2291
|
+
: undefined;
|
|
2292
|
+
switch (intent.kind) {
|
|
2293
|
+
case 'first':
|
|
2294
|
+
return resolveBoundaryStep(1, { count: total, isDisabledAt }) ?? -1;
|
|
2295
|
+
case 'last':
|
|
2296
|
+
return resolveBoundaryStep(-1, { count: total, isDisabledAt }) ?? -1;
|
|
2297
|
+
case 'byIndex': {
|
|
2298
|
+
const outside = intent.index < 0 || intent.index >= total;
|
|
2299
|
+
return outside || isDisabledAt?.(intent.index) ? -1 : intent.index;
|
|
2300
|
+
}
|
|
2301
|
+
case 'byValue': {
|
|
2302
|
+
const idx = items.findIndex((it) => source.compareWith(it.value, intent.value));
|
|
2303
|
+
return idx < 0 || (source.skipDisabled && items[idx].disabled) ? -1 : idx + offset;
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
1849
2307
|
/**
|
|
1850
2308
|
* @internal
|
|
1851
|
-
*
|
|
1852
|
-
*
|
|
1853
|
-
*
|
|
2309
|
+
* Re-derives the index for a new item space. A virtual window keeps its
|
|
2310
|
+
* absolute index while its total holds (a window move); a changed total is a
|
|
2311
|
+
* new list, so the index is dropped rather than left on another option. The
|
|
2312
|
+
* index also means nothing once the list turns plain. In a
|
|
2313
|
+
* plain list the previously active value is looked up again; unchanged items,
|
|
2314
|
+
* no previous highlight, or an index past the old items keep the index.
|
|
1854
2315
|
*/
|
|
1855
2316
|
function reResolveIndex(source, previousSource, previousIndex) {
|
|
2317
|
+
if (source.virtual) {
|
|
2318
|
+
return source.total === previousSource.total ? previousIndex : -1;
|
|
2319
|
+
}
|
|
2320
|
+
if (previousSource.virtual) {
|
|
2321
|
+
return -1;
|
|
2322
|
+
}
|
|
1856
2323
|
if (previousSource.items === source.items || previousIndex < 0) {
|
|
1857
2324
|
return previousIndex;
|
|
1858
2325
|
}
|
|
1859
|
-
const previous = previousSource.items[previousIndex
|
|
2326
|
+
const previous = previousSource.items[previousIndex];
|
|
1860
2327
|
if (!previous) {
|
|
1861
2328
|
return previousIndex;
|
|
1862
2329
|
}
|
|
1863
|
-
|
|
1864
|
-
if (match >= 0) {
|
|
1865
|
-
return match + source.offset;
|
|
1866
|
-
}
|
|
1867
|
-
return source.virtual ? previousIndex : -1;
|
|
2330
|
+
return source.items.findIndex((it) => source.compareWith(it.value, previous.value));
|
|
1868
2331
|
}
|
|
1869
2332
|
/** @internal Pulls an index that ran past the item space back onto its last item. */
|
|
1870
2333
|
function clampIndex(index, total) {
|
|
@@ -1886,36 +2349,6 @@ function handleToItem(handle) {
|
|
|
1886
2349
|
function isPrintableChar(key) {
|
|
1887
2350
|
return key.length === 1 && /\S/.exec(key) !== null;
|
|
1888
2351
|
}
|
|
1889
|
-
/**
|
|
1890
|
-
* True when the element would capture text input natively - a text
|
|
1891
|
-
* `<input>`, `<textarea>`, or any `contenteditable` host. Read-only /
|
|
1892
|
-
* button-type inputs (submit, radio, checkbox) are NOT editable; AD's
|
|
1893
|
-
* keyboard navigation still applies when focus lands on them.
|
|
1894
|
-
*
|
|
1895
|
-
* @internal
|
|
1896
|
-
*/
|
|
1897
|
-
function isEditableTarget(el) {
|
|
1898
|
-
if (el.isContentEditable) {
|
|
1899
|
-
return true;
|
|
1900
|
-
}
|
|
1901
|
-
const tag = el.tagName;
|
|
1902
|
-
if (tag === 'TEXTAREA') {
|
|
1903
|
-
return true;
|
|
1904
|
-
}
|
|
1905
|
-
if (tag === 'INPUT') {
|
|
1906
|
-
const type = el.type.toLowerCase();
|
|
1907
|
-
return (type !== 'button' &&
|
|
1908
|
-
type !== 'submit' &&
|
|
1909
|
-
type !== 'reset' &&
|
|
1910
|
-
type !== 'checkbox' &&
|
|
1911
|
-
type !== 'radio' &&
|
|
1912
|
-
type !== 'range' &&
|
|
1913
|
-
type !== 'color' &&
|
|
1914
|
-
type !== 'file' &&
|
|
1915
|
-
type !== 'image');
|
|
1916
|
-
}
|
|
1917
|
-
return false;
|
|
1918
|
-
}
|
|
1919
2352
|
/** @internal */
|
|
1920
2353
|
function cssEscape(id) {
|
|
1921
2354
|
const api = globalThis.CSS;
|
|
@@ -1937,6 +2370,11 @@ function cssEscape(id) {
|
|
|
1937
2370
|
* directive makes the preference available in component logic (e.g., to pick
|
|
1938
2371
|
* a different animation strategy or suppress requestAnimationFrame loops).
|
|
1939
2372
|
*
|
|
2373
|
+
* This is the OS preference only. An in-app pick through `provideMotion` /
|
|
2374
|
+
* `injectMotion` (`CNGX_MOTION`, `<html data-motion>`) is not seen here; to
|
|
2375
|
+
* decide on the motion the user actually gets, read `injectEffectiveMotion()`
|
|
2376
|
+
* from `@cngx/core` instead.
|
|
2377
|
+
*
|
|
1940
2378
|
* ### Conditional animation
|
|
1941
2379
|
* ```html
|
|
1942
2380
|
* <div cngxReducedMotion #rm="cngxReducedMotion"
|
|
@@ -1950,15 +2388,15 @@ function cssEscape(id) {
|
|
|
1950
2388
|
* readonly duration = computed(() => this.rm()?.prefersReducedMotion() ? 0 : 300);
|
|
1951
2389
|
* ```
|
|
1952
2390
|
*
|
|
1953
|
-
* @category common/a11y
|
|
1954
2391
|
* @wcag AA
|
|
1955
2392
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/motion/reduced-motion.directive.ts
|
|
1956
|
-
* @since 0.
|
|
1957
|
-
* <example-url
|
|
1958
|
-
* <example-url
|
|
2393
|
+
* @since 0.3.0
|
|
2394
|
+
* <example-url>/#/common/a11y/reduced-motion/animation-toggle</example-url>
|
|
2395
|
+
* <example-url>/#/common/a11y/reduced-motion/toast-notifications-motion-aware</example-url>
|
|
2396
|
+
* @axis level atom
|
|
1959
2397
|
*/
|
|
1960
2398
|
class CngxReducedMotion {
|
|
1961
|
-
/** `true` when the user's OS is set to prefer reduced motion. Updates reactively. */
|
|
2399
|
+
/** `true` when the user's OS is set to prefer reduced motion (ignores `CNGX_MOTION`). Updates reactively. */
|
|
1962
2400
|
prefersReducedMotion;
|
|
1963
2401
|
constructor() {
|
|
1964
2402
|
this.prefersReducedMotion = createMediaQuerySignal('(prefers-reduced-motion: reduce)', inject(DestroyRef), inject(DOCUMENT).defaultView);
|
|
@@ -1977,12 +2415,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1977
2415
|
}], ctorParameters: () => [] });
|
|
1978
2416
|
|
|
1979
2417
|
/**
|
|
1980
|
-
* @module
|
|
2418
|
+
* @module `@cngx/common/a11y`
|
|
1981
2419
|
*/
|
|
1982
2420
|
|
|
1983
2421
|
/**
|
|
1984
2422
|
* Generated bundle index. Do not edit.
|
|
1985
2423
|
*/
|
|
1986
2424
|
|
|
1987
|
-
export { CNGX_AD_ITEM, CNGX_FOCUSABLE_SELECTOR, CNGX_FOCUS_TRAP_DRIVER, CngxActiveDescendant, CngxAriaExpanded, CngxAutofocus, CngxFocusRestore, CngxFocusTrap, CngxFocusVisible, CngxLiveAnnouncer, CngxLiveRegion, CngxReducedMotion, CngxRovingItem, CngxRovingTabindex, injectScopedLiveRegion };
|
|
2425
|
+
export { CNGX_AD_ITEM, CNGX_ARIA_EXPANDED_DRIVER, CNGX_FOCUSABLE_SELECTOR, CNGX_FOCUS_RESTORE_DRIVER, CNGX_FOCUS_TRAP_DRIVER, CngxActiveDescendant, CngxAriaExpanded, CngxAutofocus, CngxFocusRestore, CngxFocusTrap, CngxFocusVisible, CngxLiveAnnouncer, CngxLiveRegion, CngxReducedMotion, CngxRovingItem, CngxRovingTabindex, injectScopedLiveRegion };
|
|
1988
2426
|
//# sourceMappingURL=cngx-common-a11y.mjs.map
|