@angular/cdk 21.0.0-next.9 → 21.0.0-rc.1

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.
Files changed (124) hide show
  1. package/_adev_assets/cdk_drag_drop.json +13 -12
  2. package/_adev_assets/cdk_testing.json +9 -9
  3. package/_adev_assets/cdk_testing_protractor.json +1 -1
  4. package/_adev_assets/cdk_testing_selenium_webdriver.json +1 -1
  5. package/_adev_assets/cdk_testing_testbed.json +1 -1
  6. package/fesm2022/_a11y-module-chunk.mjs +755 -869
  7. package/fesm2022/_a11y-module-chunk.mjs.map +1 -1
  8. package/fesm2022/_activedescendant-key-manager-chunk.mjs +8 -8
  9. package/fesm2022/_activedescendant-key-manager-chunk.mjs.map +1 -1
  10. package/fesm2022/_array-chunk.mjs +1 -1
  11. package/fesm2022/_array-chunk.mjs.map +1 -1
  12. package/fesm2022/_breakpoints-observer-chunk.mjs +149 -152
  13. package/fesm2022/_breakpoints-observer-chunk.mjs.map +1 -1
  14. package/fesm2022/_css-pixel-value-chunk.mjs +4 -5
  15. package/fesm2022/_css-pixel-value-chunk.mjs.map +1 -1
  16. package/fesm2022/_data-source-chunk.mjs +2 -8
  17. package/fesm2022/_data-source-chunk.mjs.map +1 -1
  18. package/fesm2022/_directionality-chunk.mjs +54 -54
  19. package/fesm2022/_directionality-chunk.mjs.map +1 -1
  20. package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs +25 -36
  21. package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs.map +1 -1
  22. package/fesm2022/_element-chunk.mjs +6 -17
  23. package/fesm2022/_element-chunk.mjs.map +1 -1
  24. package/fesm2022/_fake-event-detection-chunk.mjs +3 -17
  25. package/fesm2022/_fake-event-detection-chunk.mjs.map +1 -1
  26. package/fesm2022/_focus-key-manager-chunk.mjs +10 -14
  27. package/fesm2022/_focus-key-manager-chunk.mjs.map +1 -1
  28. package/fesm2022/_focus-monitor-chunk.mjs +376 -566
  29. package/fesm2022/_focus-monitor-chunk.mjs.map +1 -1
  30. package/fesm2022/_id-generator-chunk.mjs +37 -27
  31. package/fesm2022/_id-generator-chunk.mjs.map +1 -1
  32. package/fesm2022/_keycodes-chunk.mjs +9 -9
  33. package/fesm2022/_keycodes-chunk.mjs.map +1 -1
  34. package/fesm2022/_list-key-manager-chunk.mjs +248 -336
  35. package/fesm2022/_list-key-manager-chunk.mjs.map +1 -1
  36. package/fesm2022/_overlay-module-chunk.mjs +2535 -2947
  37. package/fesm2022/_overlay-module-chunk.mjs.map +1 -1
  38. package/fesm2022/_passive-listeners-chunk.mjs +10 -22
  39. package/fesm2022/_passive-listeners-chunk.mjs.map +1 -1
  40. package/fesm2022/_platform-chunk.mjs +42 -65
  41. package/fesm2022/_platform-chunk.mjs.map +1 -1
  42. package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs +78 -134
  43. package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs.map +1 -1
  44. package/fesm2022/_scrolling-chunk.mjs +44 -85
  45. package/fesm2022/_scrolling-chunk.mjs.map +1 -1
  46. package/fesm2022/_selection-model-chunk.mjs +138 -209
  47. package/fesm2022/_selection-model-chunk.mjs.map +1 -1
  48. package/fesm2022/_shadow-dom-chunk.mjs +21 -35
  49. package/fesm2022/_shadow-dom-chunk.mjs.map +1 -1
  50. package/fesm2022/_style-loader-chunk.mjs +50 -37
  51. package/fesm2022/_style-loader-chunk.mjs.map +1 -1
  52. package/fesm2022/_test-environment-chunk.mjs +2 -14
  53. package/fesm2022/_test-environment-chunk.mjs.map +1 -1
  54. package/fesm2022/_tree-key-manager-chunk.mjs +229 -308
  55. package/fesm2022/_tree-key-manager-chunk.mjs.map +1 -1
  56. package/fesm2022/_typeahead-chunk.mjs +52 -74
  57. package/fesm2022/_typeahead-chunk.mjs.map +1 -1
  58. package/fesm2022/_unique-selection-dispatcher-chunk.mjs +43 -40
  59. package/fesm2022/_unique-selection-dispatcher-chunk.mjs.map +1 -1
  60. package/fesm2022/a11y.mjs +351 -449
  61. package/fesm2022/a11y.mjs.map +1 -1
  62. package/fesm2022/accordion.mjs +254 -192
  63. package/fesm2022/accordion.mjs.map +1 -1
  64. package/fesm2022/bidi.mjs +121 -64
  65. package/fesm2022/bidi.mjs.map +1 -1
  66. package/fesm2022/cdk.mjs +1 -2
  67. package/fesm2022/cdk.mjs.map +1 -1
  68. package/fesm2022/clipboard.mjs +208 -186
  69. package/fesm2022/clipboard.mjs.map +1 -1
  70. package/fesm2022/coercion-private.mjs +4 -8
  71. package/fesm2022/coercion-private.mjs.map +1 -1
  72. package/fesm2022/coercion.mjs +11 -29
  73. package/fesm2022/coercion.mjs.map +1 -1
  74. package/fesm2022/dialog.mjs +660 -808
  75. package/fesm2022/dialog.mjs.map +1 -1
  76. package/fesm2022/drag-drop.mjs +3347 -4286
  77. package/fesm2022/drag-drop.mjs.map +1 -1
  78. package/fesm2022/keycodes.mjs +4 -8
  79. package/fesm2022/keycodes.mjs.map +1 -1
  80. package/fesm2022/layout.mjs +44 -26
  81. package/fesm2022/layout.mjs.map +1 -1
  82. package/fesm2022/listbox.mjs +841 -895
  83. package/fesm2022/listbox.mjs.map +1 -1
  84. package/fesm2022/menu.mjs +1942 -1858
  85. package/fesm2022/menu.mjs.map +1 -1
  86. package/fesm2022/observers-private.mjs +88 -106
  87. package/fesm2022/observers-private.mjs.map +1 -1
  88. package/fesm2022/observers.mjs +262 -184
  89. package/fesm2022/observers.mjs.map +1 -1
  90. package/fesm2022/overlay.mjs +72 -68
  91. package/fesm2022/overlay.mjs.map +1 -1
  92. package/fesm2022/platform.mjs +43 -54
  93. package/fesm2022/platform.mjs.map +1 -1
  94. package/fesm2022/portal.mjs +402 -560
  95. package/fesm2022/portal.mjs.map +1 -1
  96. package/fesm2022/private.mjs +38 -10
  97. package/fesm2022/private.mjs.map +1 -1
  98. package/fesm2022/scrolling.mjs +1323 -1400
  99. package/fesm2022/scrolling.mjs.map +1 -1
  100. package/fesm2022/stepper.mjs +758 -590
  101. package/fesm2022/stepper.mjs.map +1 -1
  102. package/fesm2022/table.mjs +2327 -2319
  103. package/fesm2022/table.mjs.map +1 -1
  104. package/fesm2022/testing-selenium-webdriver.mjs +252 -325
  105. package/fesm2022/testing-selenium-webdriver.mjs.map +1 -1
  106. package/fesm2022/testing-testbed.mjs +592 -709
  107. package/fesm2022/testing-testbed.mjs.map +1 -1
  108. package/fesm2022/testing.mjs +368 -889
  109. package/fesm2022/testing.mjs.map +1 -1
  110. package/fesm2022/text-field.mjs +459 -388
  111. package/fesm2022/text-field.mjs.map +1 -1
  112. package/fesm2022/tree.mjs +1483 -1731
  113. package/fesm2022/tree.mjs.map +1 -1
  114. package/overlay/_index.scss +30 -0
  115. package/overlay-prebuilt.css +1 -1
  116. package/package.json +1 -1
  117. package/schematics/ng-add/index.js +1 -1
  118. package/types/_overlay-module-chunk.d.ts +69 -7
  119. package/types/_portal-directives-chunk.d.ts +2 -18
  120. package/types/a11y.d.ts +3 -1
  121. package/types/accordion.d.ts +3 -1
  122. package/types/dialog.d.ts +1 -1
  123. package/types/overlay.d.ts +1 -1
  124. package/types/portal.d.ts +1 -1
@@ -9,614 +9,424 @@ import { Platform } from './_platform-chunk.mjs';
9
9
  import { normalizePassiveListenerOptions } from './_passive-listeners-chunk.mjs';
10
10
  import { coerceElement } from './_element-chunk.mjs';
11
11
 
12
- /**
13
- * Injectable options for the InputModalityDetector. These are shallowly merged with the default
14
- * options.
15
- */
16
12
  const INPUT_MODALITY_DETECTOR_OPTIONS = new InjectionToken('cdk-input-modality-detector-options');
17
- /**
18
- * Default options for the InputModalityDetector.
19
- *
20
- * Modifier keys are ignored by default (i.e. when pressed won't cause the service to detect
21
- * keyboard input modality) for two reasons:
22
- *
23
- * 1. Modifier keys are commonly used with mouse to perform actions such as 'right click' or 'open
24
- * in new tab', and are thus less representative of actual keyboard interaction.
25
- * 2. VoiceOver triggers some keyboard events when linearly navigating with Control + Option (but
26
- * confusingly not with Caps Lock). Thus, to have parity with other screen readers, we ignore
27
- * these keys so as to not update the input modality.
28
- *
29
- * Note that we do not by default ignore the right Meta key on Safari because it has the same key
30
- * code as the ContextMenu key on other browsers. When we switch to using event.key, we can
31
- * distinguish between the two.
32
- */
33
13
  const INPUT_MODALITY_DETECTOR_DEFAULT_OPTIONS = {
34
- ignoreKeys: [ALT, CONTROL, MAC_META, META, SHIFT],
14
+ ignoreKeys: [ALT, CONTROL, MAC_META, META, SHIFT]
35
15
  };
36
- /**
37
- * The amount of time needed to pass after a touchstart event in order for a subsequent mousedown
38
- * event to be attributed as mouse and not touch.
39
- *
40
- * This is the value used by AngularJS Material. Through trial and error (on iPhone 6S) they found
41
- * that a value of around 650ms seems appropriate.
42
- */
43
16
  const TOUCH_BUFFER_MS = 650;
44
- /**
45
- * Event listener options that enable capturing and also mark the listener as passive if the browser
46
- * supports it.
47
- */
48
17
  const modalityEventListenerOptions = {
49
- passive: true,
50
- capture: true,
18
+ passive: true,
19
+ capture: true
51
20
  };
52
- /**
53
- * Service that detects the user's input modality.
54
- *
55
- * This service does not update the input modality when a user navigates with a screen reader
56
- * (e.g. linear navigation with VoiceOver, object navigation / browse mode with NVDA, virtual PC
57
- * cursor mode with JAWS). This is in part due to technical limitations (i.e. keyboard events do not
58
- * fire as expected in these modes) but is also arguably the correct behavior. Navigating with a
59
- * screen reader is akin to visually scanning a page, and should not be interpreted as actual user
60
- * input interaction.
61
- *
62
- * When a user is not navigating but *interacting* with a screen reader, this service attempts to
63
- * update the input modality to keyboard, but in general this service's behavior is largely
64
- * undefined.
65
- */
66
21
  class InputModalityDetector {
67
- _platform = inject(Platform);
68
- _listenerCleanups;
69
- /** Emits whenever an input modality is detected. */
70
- modalityDetected;
71
- /** Emits when the input modality changes. */
72
- modalityChanged;
73
- /** The most recently detected input modality. */
74
- get mostRecentModality() {
75
- return this._modality.value;
22
+ _platform = inject(Platform);
23
+ _listenerCleanups;
24
+ modalityDetected;
25
+ modalityChanged;
26
+ get mostRecentModality() {
27
+ return this._modality.value;
28
+ }
29
+ _mostRecentTarget = null;
30
+ _modality = new BehaviorSubject(null);
31
+ _options;
32
+ _lastTouchMs = 0;
33
+ _onKeydown = event => {
34
+ if (this._options?.ignoreKeys?.some(keyCode => keyCode === event.keyCode)) {
35
+ return;
76
36
  }
77
- /**
78
- * The most recently detected input modality event target. Is null if no input modality has been
79
- * detected or if the associated event target is null for some unknown reason.
80
- */
81
- _mostRecentTarget = null;
82
- /** The underlying BehaviorSubject that emits whenever an input modality is detected. */
83
- _modality = new BehaviorSubject(null);
84
- /** Options for this InputModalityDetector. */
85
- _options;
86
- /**
87
- * The timestamp of the last touch input modality. Used to determine whether mousedown events
88
- * should be attributed to mouse or touch.
89
- */
90
- _lastTouchMs = 0;
91
- /**
92
- * Handles keydown events. Must be an arrow function in order to preserve the context when it gets
93
- * bound.
94
- */
95
- _onKeydown = (event) => {
96
- // If this is one of the keys we should ignore, then ignore it and don't update the input
97
- // modality to keyboard.
98
- if (this._options?.ignoreKeys?.some(keyCode => keyCode === event.keyCode)) {
99
- return;
100
- }
101
- this._modality.next('keyboard');
102
- this._mostRecentTarget = _getEventTarget(event);
103
- };
104
- /**
105
- * Handles mousedown events. Must be an arrow function in order to preserve the context when it
106
- * gets bound.
107
- */
108
- _onMousedown = (event) => {
109
- // Touches trigger both touch and mouse events, so we need to distinguish between mouse events
110
- // that were triggered via mouse vs touch. To do so, check if the mouse event occurs closely
111
- // after the previous touch event.
112
- if (Date.now() - this._lastTouchMs < TOUCH_BUFFER_MS) {
113
- return;
114
- }
115
- // Fake mousedown events are fired by some screen readers when controls are activated by the
116
- // screen reader. Attribute them to keyboard input modality.
117
- this._modality.next(isFakeMousedownFromScreenReader(event) ? 'keyboard' : 'mouse');
118
- this._mostRecentTarget = _getEventTarget(event);
119
- };
120
- /**
121
- * Handles touchstart events. Must be an arrow function in order to preserve the context when it
122
- * gets bound.
123
- */
124
- _onTouchstart = (event) => {
125
- // Same scenario as mentioned in _onMousedown, but on touch screen devices, fake touchstart
126
- // events are fired. Again, attribute to keyboard input modality.
127
- if (isFakeTouchstartFromScreenReader(event)) {
128
- this._modality.next('keyboard');
129
- return;
130
- }
131
- // Store the timestamp of this touch event, as it's used to distinguish between mouse events
132
- // triggered via mouse vs touch.
133
- this._lastTouchMs = Date.now();
134
- this._modality.next('touch');
135
- this._mostRecentTarget = _getEventTarget(event);
136
- };
137
- constructor() {
138
- const ngZone = inject(NgZone);
139
- const document = inject(DOCUMENT);
140
- const options = inject(INPUT_MODALITY_DETECTOR_OPTIONS, { optional: true });
141
- this._options = {
142
- ...INPUT_MODALITY_DETECTOR_DEFAULT_OPTIONS,
143
- ...options,
144
- };
145
- // Skip the first emission as it's null.
146
- this.modalityDetected = this._modality.pipe(skip(1));
147
- this.modalityChanged = this.modalityDetected.pipe(distinctUntilChanged());
148
- // If we're not in a browser, this service should do nothing, as there's no relevant input
149
- // modality to detect.
150
- if (this._platform.isBrowser) {
151
- const renderer = inject(RendererFactory2).createRenderer(null, null);
152
- this._listenerCleanups = ngZone.runOutsideAngular(() => {
153
- return [
154
- renderer.listen(document, 'keydown', this._onKeydown, modalityEventListenerOptions),
155
- renderer.listen(document, 'mousedown', this._onMousedown, modalityEventListenerOptions),
156
- renderer.listen(document, 'touchstart', this._onTouchstart, modalityEventListenerOptions),
157
- ];
158
- });
159
- }
37
+ this._modality.next('keyboard');
38
+ this._mostRecentTarget = _getEventTarget(event);
39
+ };
40
+ _onMousedown = event => {
41
+ if (Date.now() - this._lastTouchMs < TOUCH_BUFFER_MS) {
42
+ return;
160
43
  }
161
- ngOnDestroy() {
162
- this._modality.complete();
163
- this._listenerCleanups?.forEach(cleanup => cleanup());
44
+ this._modality.next(isFakeMousedownFromScreenReader(event) ? 'keyboard' : 'mouse');
45
+ this._mostRecentTarget = _getEventTarget(event);
46
+ };
47
+ _onTouchstart = event => {
48
+ if (isFakeTouchstartFromScreenReader(event)) {
49
+ this._modality.next('keyboard');
50
+ return;
51
+ }
52
+ this._lastTouchMs = Date.now();
53
+ this._modality.next('touch');
54
+ this._mostRecentTarget = _getEventTarget(event);
55
+ };
56
+ constructor() {
57
+ const ngZone = inject(NgZone);
58
+ const document = inject(DOCUMENT);
59
+ const options = inject(INPUT_MODALITY_DETECTOR_OPTIONS, {
60
+ optional: true
61
+ });
62
+ this._options = {
63
+ ...INPUT_MODALITY_DETECTOR_DEFAULT_OPTIONS,
64
+ ...options
65
+ };
66
+ this.modalityDetected = this._modality.pipe(skip(1));
67
+ this.modalityChanged = this.modalityDetected.pipe(distinctUntilChanged());
68
+ if (this._platform.isBrowser) {
69
+ const renderer = inject(RendererFactory2).createRenderer(null, null);
70
+ this._listenerCleanups = ngZone.runOutsideAngular(() => {
71
+ return [renderer.listen(document, 'keydown', this._onKeydown, modalityEventListenerOptions), renderer.listen(document, 'mousedown', this._onMousedown, modalityEventListenerOptions), renderer.listen(document, 'touchstart', this._onTouchstart, modalityEventListenerOptions)];
72
+ });
164
73
  }
165
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: InputModalityDetector, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
166
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: InputModalityDetector, providedIn: 'root' });
74
+ }
75
+ ngOnDestroy() {
76
+ this._modality.complete();
77
+ this._listenerCleanups?.forEach(cleanup => cleanup());
78
+ }
79
+ static ɵfac = i0.ɵɵngDeclareFactory({
80
+ minVersion: "12.0.0",
81
+ version: "20.2.0-next.2",
82
+ ngImport: i0,
83
+ type: InputModalityDetector,
84
+ deps: [],
85
+ target: i0.ɵɵFactoryTarget.Injectable
86
+ });
87
+ static ɵprov = i0.ɵɵngDeclareInjectable({
88
+ minVersion: "12.0.0",
89
+ version: "20.2.0-next.2",
90
+ ngImport: i0,
91
+ type: InputModalityDetector,
92
+ providedIn: 'root'
93
+ });
167
94
  }
168
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: InputModalityDetector, decorators: [{
169
- type: Injectable,
170
- args: [{ providedIn: 'root' }]
171
- }], ctorParameters: () => [] });
95
+ i0.ɵɵngDeclareClassMetadata({
96
+ minVersion: "12.0.0",
97
+ version: "20.2.0-next.2",
98
+ ngImport: i0,
99
+ type: InputModalityDetector,
100
+ decorators: [{
101
+ type: Injectable,
102
+ args: [{
103
+ providedIn: 'root'
104
+ }]
105
+ }],
106
+ ctorParameters: () => []
107
+ });
172
108
 
173
- /** Detection mode used for attributing the origin of a focus event. */
174
109
  var FocusMonitorDetectionMode;
175
110
  (function (FocusMonitorDetectionMode) {
176
- /**
177
- * Any mousedown, keydown, or touchstart event that happened in the previous
178
- * tick or the current tick will be used to assign a focus event's origin (to
179
- * either mouse, keyboard, or touch). This is the default option.
180
- */
181
- FocusMonitorDetectionMode[FocusMonitorDetectionMode["IMMEDIATE"] = 0] = "IMMEDIATE";
182
- /**
183
- * A focus event's origin is always attributed to the last corresponding
184
- * mousedown, keydown, or touchstart event, no matter how long ago it occurred.
185
- */
186
- FocusMonitorDetectionMode[FocusMonitorDetectionMode["EVENTUAL"] = 1] = "EVENTUAL";
111
+ FocusMonitorDetectionMode[FocusMonitorDetectionMode["IMMEDIATE"] = 0] = "IMMEDIATE";
112
+ FocusMonitorDetectionMode[FocusMonitorDetectionMode["EVENTUAL"] = 1] = "EVENTUAL";
187
113
  })(FocusMonitorDetectionMode || (FocusMonitorDetectionMode = {}));
188
- /** InjectionToken for FocusMonitorOptions. */
189
114
  const FOCUS_MONITOR_DEFAULT_OPTIONS = new InjectionToken('cdk-focus-monitor-default-options');
190
- /**
191
- * Event listener options that enable capturing and also
192
- * mark the listener as passive if the browser supports it.
193
- */
194
115
  const captureEventListenerOptions = normalizePassiveListenerOptions({
195
- passive: true,
196
- capture: true,
116
+ passive: true,
117
+ capture: true
197
118
  });
198
- /** Monitors mouse and keyboard events to determine the cause of focus events. */
199
119
  class FocusMonitor {
200
- _ngZone = inject(NgZone);
201
- _platform = inject(Platform);
202
- _inputModalityDetector = inject(InputModalityDetector);
203
- /** The focus origin that the next focus event is a result of. */
204
- _origin = null;
205
- /** The FocusOrigin of the last focus event tracked by the FocusMonitor. */
206
- _lastFocusOrigin;
207
- /** Whether the window has just been focused. */
208
- _windowFocused = false;
209
- /** The timeout id of the window focus timeout. */
210
- _windowFocusTimeoutId;
211
- /** The timeout id of the origin clearing timeout. */
212
- _originTimeoutId;
213
- /**
214
- * Whether the origin was determined via a touch interaction. Necessary as properly attributing
215
- * focus events to touch interactions requires special logic.
216
- */
217
- _originFromTouchInteraction = false;
218
- /** Map of elements being monitored to their info. */
219
- _elementInfo = new Map();
220
- /** The number of elements currently being monitored. */
221
- _monitoredElementCount = 0;
222
- /**
223
- * Keeps track of the root nodes to which we've currently bound a focus/blur handler,
224
- * as well as the number of monitored elements that they contain. We have to treat focus/blur
225
- * handlers differently from the rest of the events, because the browser won't emit events
226
- * to the document when focus moves inside of a shadow root.
227
- */
228
- _rootNodeFocusListenerCount = new Map();
229
- /**
230
- * The specified detection mode, used for attributing the origin of a focus
231
- * event.
232
- */
233
- _detectionMode;
234
- /**
235
- * Event listener for `focus` events on the window.
236
- * Needs to be an arrow function in order to preserve the context when it gets bound.
237
- */
238
- _windowFocusListener = () => {
239
- // Make a note of when the window regains focus, so we can
240
- // restore the origin info for the focused element.
241
- this._windowFocused = true;
242
- this._windowFocusTimeoutId = setTimeout(() => (this._windowFocused = false));
243
- };
244
- /** Used to reference correct document/window */
245
- _document = inject(DOCUMENT);
246
- /** Subject for stopping our InputModalityDetector subscription. */
247
- _stopInputModalityDetector = new Subject();
248
- constructor() {
249
- const options = inject(FOCUS_MONITOR_DEFAULT_OPTIONS, {
250
- optional: true,
251
- });
252
- this._detectionMode = options?.detectionMode || FocusMonitorDetectionMode.IMMEDIATE;
120
+ _ngZone = inject(NgZone);
121
+ _platform = inject(Platform);
122
+ _inputModalityDetector = inject(InputModalityDetector);
123
+ _origin = null;
124
+ _lastFocusOrigin;
125
+ _windowFocused = false;
126
+ _windowFocusTimeoutId;
127
+ _originTimeoutId;
128
+ _originFromTouchInteraction = false;
129
+ _elementInfo = new Map();
130
+ _monitoredElementCount = 0;
131
+ _rootNodeFocusListenerCount = new Map();
132
+ _detectionMode;
133
+ _windowFocusListener = () => {
134
+ this._windowFocused = true;
135
+ this._windowFocusTimeoutId = setTimeout(() => this._windowFocused = false);
136
+ };
137
+ _document = inject(DOCUMENT);
138
+ _stopInputModalityDetector = new Subject();
139
+ constructor() {
140
+ const options = inject(FOCUS_MONITOR_DEFAULT_OPTIONS, {
141
+ optional: true
142
+ });
143
+ this._detectionMode = options?.detectionMode || FocusMonitorDetectionMode.IMMEDIATE;
144
+ }
145
+ _rootNodeFocusAndBlurListener = event => {
146
+ const target = _getEventTarget(event);
147
+ for (let element = target; element; element = element.parentElement) {
148
+ if (event.type === 'focus') {
149
+ this._onFocus(event, element);
150
+ } else {
151
+ this._onBlur(event, element);
152
+ }
253
153
  }
254
- /**
255
- * Event listener for `focus` and 'blur' events on the document.
256
- * Needs to be an arrow function in order to preserve the context when it gets bound.
257
- */
258
- _rootNodeFocusAndBlurListener = (event) => {
259
- const target = _getEventTarget(event);
260
- // We need to walk up the ancestor chain in order to support `checkChildren`.
261
- for (let element = target; element; element = element.parentElement) {
262
- if (event.type === 'focus') {
263
- this._onFocus(event, element);
264
- }
265
- else {
266
- this._onBlur(event, element);
267
- }
268
- }
269
- };
270
- monitor(element, checkChildren = false) {
271
- const nativeElement = coerceElement(element);
272
- // Do nothing if we're not on the browser platform or the passed in node isn't an element.
273
- if (!this._platform.isBrowser || nativeElement.nodeType !== 1) {
274
- // Note: we don't want the observable to emit at all so we don't pass any parameters.
275
- return of();
276
- }
277
- // If the element is inside the shadow DOM, we need to bind our focus/blur listeners to
278
- // the shadow root, rather than the `document`, because the browser won't emit focus events
279
- // to the `document`, if focus is moving within the same shadow root.
280
- const rootNode = _getShadowRoot(nativeElement) || this._document;
281
- const cachedInfo = this._elementInfo.get(nativeElement);
282
- // Check if we're already monitoring this element.
283
- if (cachedInfo) {
284
- if (checkChildren) {
285
- // TODO(COMP-318): this can be problematic, because it'll turn all non-checkChildren
286
- // observers into ones that behave as if `checkChildren` was turned on. We need a more
287
- // robust solution.
288
- cachedInfo.checkChildren = true;
289
- }
290
- return cachedInfo.subject;
291
- }
292
- // Create monitored element info.
293
- const info = {
294
- checkChildren: checkChildren,
295
- subject: new Subject(),
296
- rootNode,
297
- };
298
- this._elementInfo.set(nativeElement, info);
299
- this._registerGlobalListeners(info);
300
- return info.subject;
154
+ };
155
+ monitor(element, checkChildren = false) {
156
+ const nativeElement = coerceElement(element);
157
+ if (!this._platform.isBrowser || nativeElement.nodeType !== 1) {
158
+ return of();
301
159
  }
302
- stopMonitoring(element) {
303
- const nativeElement = coerceElement(element);
304
- const elementInfo = this._elementInfo.get(nativeElement);
305
- if (elementInfo) {
306
- elementInfo.subject.complete();
307
- this._setClasses(nativeElement);
308
- this._elementInfo.delete(nativeElement);
309
- this._removeGlobalListeners(elementInfo);
310
- }
160
+ const rootNode = _getShadowRoot(nativeElement) || this._document;
161
+ const cachedInfo = this._elementInfo.get(nativeElement);
162
+ if (cachedInfo) {
163
+ if (checkChildren) {
164
+ cachedInfo.checkChildren = true;
165
+ }
166
+ return cachedInfo.subject;
311
167
  }
312
- focusVia(element, origin, options) {
313
- const nativeElement = coerceElement(element);
314
- const focusedElement = this._document.activeElement;
315
- // If the element is focused already, calling `focus` again won't trigger the event listener
316
- // which means that the focus classes won't be updated. If that's the case, update the classes
317
- // directly without waiting for an event.
318
- if (nativeElement === focusedElement) {
319
- this._getClosestElementsInfo(nativeElement).forEach(([currentElement, info]) => this._originChanged(currentElement, origin, info));
320
- }
321
- else {
322
- this._setOrigin(origin);
323
- // `focus` isn't available on the server
324
- if (typeof nativeElement.focus === 'function') {
325
- nativeElement.focus(options);
326
- }
327
- }
168
+ const info = {
169
+ checkChildren: checkChildren,
170
+ subject: new Subject(),
171
+ rootNode
172
+ };
173
+ this._elementInfo.set(nativeElement, info);
174
+ this._registerGlobalListeners(info);
175
+ return info.subject;
176
+ }
177
+ stopMonitoring(element) {
178
+ const nativeElement = coerceElement(element);
179
+ const elementInfo = this._elementInfo.get(nativeElement);
180
+ if (elementInfo) {
181
+ elementInfo.subject.complete();
182
+ this._setClasses(nativeElement);
183
+ this._elementInfo.delete(nativeElement);
184
+ this._removeGlobalListeners(elementInfo);
328
185
  }
329
- ngOnDestroy() {
330
- this._elementInfo.forEach((_info, element) => this.stopMonitoring(element));
186
+ }
187
+ focusVia(element, origin, options) {
188
+ const nativeElement = coerceElement(element);
189
+ const focusedElement = this._document.activeElement;
190
+ if (nativeElement === focusedElement) {
191
+ this._getClosestElementsInfo(nativeElement).forEach(([currentElement, info]) => this._originChanged(currentElement, origin, info));
192
+ } else {
193
+ this._setOrigin(origin);
194
+ if (typeof nativeElement.focus === 'function') {
195
+ nativeElement.focus(options);
196
+ }
331
197
  }
332
- /** Use defaultView of injected document if available or fallback to global window reference */
333
- _getWindow() {
334
- return this._document.defaultView || window;
198
+ }
199
+ ngOnDestroy() {
200
+ this._elementInfo.forEach((_info, element) => this.stopMonitoring(element));
201
+ }
202
+ _getWindow() {
203
+ return this._document.defaultView || window;
204
+ }
205
+ _getFocusOrigin(focusEventTarget) {
206
+ if (this._origin) {
207
+ if (this._originFromTouchInteraction) {
208
+ return this._shouldBeAttributedToTouch(focusEventTarget) ? 'touch' : 'program';
209
+ } else {
210
+ return this._origin;
211
+ }
335
212
  }
336
- _getFocusOrigin(focusEventTarget) {
337
- if (this._origin) {
338
- // If the origin was realized via a touch interaction, we need to perform additional checks
339
- // to determine whether the focus origin should be attributed to touch or program.
340
- if (this._originFromTouchInteraction) {
341
- return this._shouldBeAttributedToTouch(focusEventTarget) ? 'touch' : 'program';
342
- }
343
- else {
344
- return this._origin;
345
- }
346
- }
347
- // If the window has just regained focus, we can restore the most recent origin from before the
348
- // window blurred. Otherwise, we've reached the point where we can't identify the source of the
349
- // focus. This typically means one of two things happened:
350
- //
351
- // 1) The element was programmatically focused, or
352
- // 2) The element was focused via screen reader navigation (which generally doesn't fire
353
- // events).
354
- //
355
- // Because we can't distinguish between these two cases, we default to setting `program`.
356
- if (this._windowFocused && this._lastFocusOrigin) {
357
- return this._lastFocusOrigin;
358
- }
359
- // If the interaction is coming from an input label, we consider it a mouse interactions.
360
- // This is a special case where focus moves on `click`, rather than `mousedown` which breaks
361
- // our detection, because all our assumptions are for `mousedown`. We need to handle this
362
- // special case, because it's very common for checkboxes and radio buttons.
363
- if (focusEventTarget && this._isLastInteractionFromInputLabel(focusEventTarget)) {
364
- return 'mouse';
365
- }
366
- return 'program';
213
+ if (this._windowFocused && this._lastFocusOrigin) {
214
+ return this._lastFocusOrigin;
367
215
  }
368
- /**
369
- * Returns whether the focus event should be attributed to touch. Recall that in IMMEDIATE mode, a
370
- * touch origin isn't immediately reset at the next tick (see _setOrigin). This means that when we
371
- * handle a focus event following a touch interaction, we need to determine whether (1) the focus
372
- * event was directly caused by the touch interaction or (2) the focus event was caused by a
373
- * subsequent programmatic focus call triggered by the touch interaction.
374
- * @param focusEventTarget The target of the focus event under examination.
375
- */
376
- _shouldBeAttributedToTouch(focusEventTarget) {
377
- // Please note that this check is not perfect. Consider the following edge case:
378
- //
379
- // <div #parent tabindex="0">
380
- // <div #child tabindex="0" (click)="#parent.focus()"></div>
381
- // </div>
382
- //
383
- // Suppose there is a FocusMonitor in IMMEDIATE mode attached to #parent. When the user touches
384
- // #child, #parent is programmatically focused. This code will attribute the focus to touch
385
- // instead of program. This is a relatively minor edge-case that can be worked around by using
386
- // focusVia(parent, 'program') to focus #parent.
387
- return (this._detectionMode === FocusMonitorDetectionMode.EVENTUAL ||
388
- !!focusEventTarget?.contains(this._inputModalityDetector._mostRecentTarget));
216
+ if (focusEventTarget && this._isLastInteractionFromInputLabel(focusEventTarget)) {
217
+ return 'mouse';
389
218
  }
390
- /**
391
- * Sets the focus classes on the element based on the given focus origin.
392
- * @param element The element to update the classes on.
393
- * @param origin The focus origin.
394
- */
395
- _setClasses(element, origin) {
396
- element.classList.toggle('cdk-focused', !!origin);
397
- element.classList.toggle('cdk-touch-focused', origin === 'touch');
398
- element.classList.toggle('cdk-keyboard-focused', origin === 'keyboard');
399
- element.classList.toggle('cdk-mouse-focused', origin === 'mouse');
400
- element.classList.toggle('cdk-program-focused', origin === 'program');
219
+ return 'program';
220
+ }
221
+ _shouldBeAttributedToTouch(focusEventTarget) {
222
+ return this._detectionMode === FocusMonitorDetectionMode.EVENTUAL || !!focusEventTarget?.contains(this._inputModalityDetector._mostRecentTarget);
223
+ }
224
+ _setClasses(element, origin) {
225
+ element.classList.toggle('cdk-focused', !!origin);
226
+ element.classList.toggle('cdk-touch-focused', origin === 'touch');
227
+ element.classList.toggle('cdk-keyboard-focused', origin === 'keyboard');
228
+ element.classList.toggle('cdk-mouse-focused', origin === 'mouse');
229
+ element.classList.toggle('cdk-program-focused', origin === 'program');
230
+ }
231
+ _setOrigin(origin, isFromInteraction = false) {
232
+ this._ngZone.runOutsideAngular(() => {
233
+ this._origin = origin;
234
+ this._originFromTouchInteraction = origin === 'touch' && isFromInteraction;
235
+ if (this._detectionMode === FocusMonitorDetectionMode.IMMEDIATE) {
236
+ clearTimeout(this._originTimeoutId);
237
+ const ms = this._originFromTouchInteraction ? TOUCH_BUFFER_MS : 1;
238
+ this._originTimeoutId = setTimeout(() => this._origin = null, ms);
239
+ }
240
+ });
241
+ }
242
+ _onFocus(event, element) {
243
+ const elementInfo = this._elementInfo.get(element);
244
+ const focusEventTarget = _getEventTarget(event);
245
+ if (!elementInfo || !elementInfo.checkChildren && element !== focusEventTarget) {
246
+ return;
401
247
  }
402
- /**
403
- * Updates the focus origin. If we're using immediate detection mode, we schedule an async
404
- * function to clear the origin at the end of a timeout. The duration of the timeout depends on
405
- * the origin being set.
406
- * @param origin The origin to set.
407
- * @param isFromInteraction Whether we are setting the origin from an interaction event.
408
- */
409
- _setOrigin(origin, isFromInteraction = false) {
410
- this._ngZone.runOutsideAngular(() => {
411
- this._origin = origin;
412
- this._originFromTouchInteraction = origin === 'touch' && isFromInteraction;
413
- // If we're in IMMEDIATE mode, reset the origin at the next tick (or in `TOUCH_BUFFER_MS` ms
414
- // for a touch event). We reset the origin at the next tick because Firefox focuses one tick
415
- // after the interaction event. We wait `TOUCH_BUFFER_MS` ms before resetting the origin for
416
- // a touch event because when a touch event is fired, the associated focus event isn't yet in
417
- // the event queue. Before doing so, clear any pending timeouts.
418
- if (this._detectionMode === FocusMonitorDetectionMode.IMMEDIATE) {
419
- clearTimeout(this._originTimeoutId);
420
- const ms = this._originFromTouchInteraction ? TOUCH_BUFFER_MS : 1;
421
- this._originTimeoutId = setTimeout(() => (this._origin = null), ms);
422
- }
423
- });
248
+ this._originChanged(element, this._getFocusOrigin(focusEventTarget), elementInfo);
249
+ }
250
+ _onBlur(event, element) {
251
+ const elementInfo = this._elementInfo.get(element);
252
+ if (!elementInfo || elementInfo.checkChildren && event.relatedTarget instanceof Node && element.contains(event.relatedTarget)) {
253
+ return;
424
254
  }
425
- /**
426
- * Handles focus events on a registered element.
427
- * @param event The focus event.
428
- * @param element The monitored element.
429
- */
430
- _onFocus(event, element) {
431
- // NOTE(mmalerba): We currently set the classes based on the focus origin of the most recent
432
- // focus event affecting the monitored element. If we want to use the origin of the first event
433
- // instead we should check for the cdk-focused class here and return if the element already has
434
- // it. (This only matters for elements that have includesChildren = true).
435
- // If we are not counting child-element-focus as focused, make sure that the event target is the
436
- // monitored element itself.
437
- const elementInfo = this._elementInfo.get(element);
438
- const focusEventTarget = _getEventTarget(event);
439
- if (!elementInfo || (!elementInfo.checkChildren && element !== focusEventTarget)) {
440
- return;
441
- }
442
- this._originChanged(element, this._getFocusOrigin(focusEventTarget), elementInfo);
255
+ this._setClasses(element);
256
+ this._emitOrigin(elementInfo, null);
257
+ }
258
+ _emitOrigin(info, origin) {
259
+ if (info.subject.observers.length) {
260
+ this._ngZone.run(() => info.subject.next(origin));
443
261
  }
444
- /**
445
- * Handles blur events on a registered element.
446
- * @param event The blur event.
447
- * @param element The monitored element.
448
- */
449
- _onBlur(event, element) {
450
- // If we are counting child-element-focus as focused, make sure that we aren't just blurring in
451
- // order to focus another child of the monitored element.
452
- const elementInfo = this._elementInfo.get(element);
453
- if (!elementInfo ||
454
- (elementInfo.checkChildren &&
455
- event.relatedTarget instanceof Node &&
456
- element.contains(event.relatedTarget))) {
457
- return;
458
- }
459
- this._setClasses(element);
460
- this._emitOrigin(elementInfo, null);
262
+ }
263
+ _registerGlobalListeners(elementInfo) {
264
+ if (!this._platform.isBrowser) {
265
+ return;
461
266
  }
462
- _emitOrigin(info, origin) {
463
- if (info.subject.observers.length) {
464
- this._ngZone.run(() => info.subject.next(origin));
465
- }
267
+ const rootNode = elementInfo.rootNode;
268
+ const rootNodeFocusListeners = this._rootNodeFocusListenerCount.get(rootNode) || 0;
269
+ if (!rootNodeFocusListeners) {
270
+ this._ngZone.runOutsideAngular(() => {
271
+ rootNode.addEventListener('focus', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
272
+ rootNode.addEventListener('blur', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
273
+ });
466
274
  }
467
- _registerGlobalListeners(elementInfo) {
468
- if (!this._platform.isBrowser) {
469
- return;
470
- }
471
- const rootNode = elementInfo.rootNode;
472
- const rootNodeFocusListeners = this._rootNodeFocusListenerCount.get(rootNode) || 0;
473
- if (!rootNodeFocusListeners) {
474
- this._ngZone.runOutsideAngular(() => {
475
- rootNode.addEventListener('focus', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
476
- rootNode.addEventListener('blur', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
477
- });
478
- }
479
- this._rootNodeFocusListenerCount.set(rootNode, rootNodeFocusListeners + 1);
480
- // Register global listeners when first element is monitored.
481
- if (++this._monitoredElementCount === 1) {
482
- // Note: we listen to events in the capture phase so we
483
- // can detect them even if the user stops propagation.
484
- this._ngZone.runOutsideAngular(() => {
485
- const window = this._getWindow();
486
- window.addEventListener('focus', this._windowFocusListener);
487
- });
488
- // The InputModalityDetector is also just a collection of global listeners.
489
- this._inputModalityDetector.modalityDetected
490
- .pipe(takeUntil(this._stopInputModalityDetector))
491
- .subscribe(modality => {
492
- this._setOrigin(modality, true /* isFromInteraction */);
493
- });
494
- }
275
+ this._rootNodeFocusListenerCount.set(rootNode, rootNodeFocusListeners + 1);
276
+ if (++this._monitoredElementCount === 1) {
277
+ this._ngZone.runOutsideAngular(() => {
278
+ const window = this._getWindow();
279
+ window.addEventListener('focus', this._windowFocusListener);
280
+ });
281
+ this._inputModalityDetector.modalityDetected.pipe(takeUntil(this._stopInputModalityDetector)).subscribe(modality => {
282
+ this._setOrigin(modality, true);
283
+ });
495
284
  }
496
- _removeGlobalListeners(elementInfo) {
497
- const rootNode = elementInfo.rootNode;
498
- if (this._rootNodeFocusListenerCount.has(rootNode)) {
499
- const rootNodeFocusListeners = this._rootNodeFocusListenerCount.get(rootNode);
500
- if (rootNodeFocusListeners > 1) {
501
- this._rootNodeFocusListenerCount.set(rootNode, rootNodeFocusListeners - 1);
502
- }
503
- else {
504
- rootNode.removeEventListener('focus', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
505
- rootNode.removeEventListener('blur', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
506
- this._rootNodeFocusListenerCount.delete(rootNode);
507
- }
508
- }
509
- // Unregister global listeners when last element is unmonitored.
510
- if (!--this._monitoredElementCount) {
511
- const window = this._getWindow();
512
- window.removeEventListener('focus', this._windowFocusListener);
513
- // Equivalently, stop our InputModalityDetector subscription.
514
- this._stopInputModalityDetector.next();
515
- // Clear timeouts for all potentially pending timeouts to prevent the leaks.
516
- clearTimeout(this._windowFocusTimeoutId);
517
- clearTimeout(this._originTimeoutId);
518
- }
285
+ }
286
+ _removeGlobalListeners(elementInfo) {
287
+ const rootNode = elementInfo.rootNode;
288
+ if (this._rootNodeFocusListenerCount.has(rootNode)) {
289
+ const rootNodeFocusListeners = this._rootNodeFocusListenerCount.get(rootNode);
290
+ if (rootNodeFocusListeners > 1) {
291
+ this._rootNodeFocusListenerCount.set(rootNode, rootNodeFocusListeners - 1);
292
+ } else {
293
+ rootNode.removeEventListener('focus', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
294
+ rootNode.removeEventListener('blur', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
295
+ this._rootNodeFocusListenerCount.delete(rootNode);
296
+ }
519
297
  }
520
- /** Updates all the state on an element once its focus origin has changed. */
521
- _originChanged(element, origin, elementInfo) {
522
- this._setClasses(element, origin);
523
- this._emitOrigin(elementInfo, origin);
524
- this._lastFocusOrigin = origin;
298
+ if (! --this._monitoredElementCount) {
299
+ const window = this._getWindow();
300
+ window.removeEventListener('focus', this._windowFocusListener);
301
+ this._stopInputModalityDetector.next();
302
+ clearTimeout(this._windowFocusTimeoutId);
303
+ clearTimeout(this._originTimeoutId);
525
304
  }
526
- /**
527
- * Collects the `MonitoredElementInfo` of a particular element and
528
- * all of its ancestors that have enabled `checkChildren`.
529
- * @param element Element from which to start the search.
530
- */
531
- _getClosestElementsInfo(element) {
532
- const results = [];
533
- this._elementInfo.forEach((info, currentElement) => {
534
- if (currentElement === element || (info.checkChildren && currentElement.contains(element))) {
535
- results.push([currentElement, info]);
536
- }
537
- });
538
- return results;
305
+ }
306
+ _originChanged(element, origin, elementInfo) {
307
+ this._setClasses(element, origin);
308
+ this._emitOrigin(elementInfo, origin);
309
+ this._lastFocusOrigin = origin;
310
+ }
311
+ _getClosestElementsInfo(element) {
312
+ const results = [];
313
+ this._elementInfo.forEach((info, currentElement) => {
314
+ if (currentElement === element || info.checkChildren && currentElement.contains(element)) {
315
+ results.push([currentElement, info]);
316
+ }
317
+ });
318
+ return results;
319
+ }
320
+ _isLastInteractionFromInputLabel(focusEventTarget) {
321
+ const {
322
+ _mostRecentTarget: mostRecentTarget,
323
+ mostRecentModality
324
+ } = this._inputModalityDetector;
325
+ if (mostRecentModality !== 'mouse' || !mostRecentTarget || mostRecentTarget === focusEventTarget || focusEventTarget.nodeName !== 'INPUT' && focusEventTarget.nodeName !== 'TEXTAREA' || focusEventTarget.disabled) {
326
+ return false;
539
327
  }
540
- /**
541
- * Returns whether an interaction is likely to have come from the user clicking the `label` of
542
- * an `input` or `textarea` in order to focus it.
543
- * @param focusEventTarget Target currently receiving focus.
544
- */
545
- _isLastInteractionFromInputLabel(focusEventTarget) {
546
- const { _mostRecentTarget: mostRecentTarget, mostRecentModality } = this._inputModalityDetector;
547
- // If the last interaction used the mouse on an element contained by one of the labels
548
- // of an `input`/`textarea` that is currently focused, it is very likely that the
549
- // user redirected focus using the label.
550
- if (mostRecentModality !== 'mouse' ||
551
- !mostRecentTarget ||
552
- mostRecentTarget === focusEventTarget ||
553
- (focusEventTarget.nodeName !== 'INPUT' && focusEventTarget.nodeName !== 'TEXTAREA') ||
554
- focusEventTarget.disabled) {
555
- return false;
328
+ const labels = focusEventTarget.labels;
329
+ if (labels) {
330
+ for (let i = 0; i < labels.length; i++) {
331
+ if (labels[i].contains(mostRecentTarget)) {
332
+ return true;
556
333
  }
557
- const labels = focusEventTarget.labels;
558
- if (labels) {
559
- for (let i = 0; i < labels.length; i++) {
560
- if (labels[i].contains(mostRecentTarget)) {
561
- return true;
562
- }
563
- }
564
- }
565
- return false;
334
+ }
566
335
  }
567
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: FocusMonitor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
568
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: FocusMonitor, providedIn: 'root' });
336
+ return false;
337
+ }
338
+ static ɵfac = i0.ɵɵngDeclareFactory({
339
+ minVersion: "12.0.0",
340
+ version: "20.2.0-next.2",
341
+ ngImport: i0,
342
+ type: FocusMonitor,
343
+ deps: [],
344
+ target: i0.ɵɵFactoryTarget.Injectable
345
+ });
346
+ static ɵprov = i0.ɵɵngDeclareInjectable({
347
+ minVersion: "12.0.0",
348
+ version: "20.2.0-next.2",
349
+ ngImport: i0,
350
+ type: FocusMonitor,
351
+ providedIn: 'root'
352
+ });
569
353
  }
570
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: FocusMonitor, decorators: [{
571
- type: Injectable,
572
- args: [{ providedIn: 'root' }]
573
- }], ctorParameters: () => [] });
574
- /**
575
- * Directive that determines how a particular element was focused (via keyboard, mouse, touch, or
576
- * programmatically) and adds corresponding classes to the element.
577
- *
578
- * There are two variants of this directive:
579
- * 1) cdkMonitorElementFocus: does not consider an element to be focused if one of its children is
580
- * focused.
581
- * 2) cdkMonitorSubtreeFocus: considers an element focused if it or any of its children are focused.
582
- */
354
+ i0.ɵɵngDeclareClassMetadata({
355
+ minVersion: "12.0.0",
356
+ version: "20.2.0-next.2",
357
+ ngImport: i0,
358
+ type: FocusMonitor,
359
+ decorators: [{
360
+ type: Injectable,
361
+ args: [{
362
+ providedIn: 'root'
363
+ }]
364
+ }],
365
+ ctorParameters: () => []
366
+ });
583
367
  class CdkMonitorFocus {
584
- _elementRef = inject(ElementRef);
585
- _focusMonitor = inject(FocusMonitor);
586
- _monitorSubscription;
587
- _focusOrigin = null;
588
- cdkFocusChange = new EventEmitter();
589
- constructor() { }
590
- get focusOrigin() {
591
- return this._focusOrigin;
368
+ _elementRef = inject(ElementRef);
369
+ _focusMonitor = inject(FocusMonitor);
370
+ _monitorSubscription;
371
+ _focusOrigin = null;
372
+ cdkFocusChange = new EventEmitter();
373
+ constructor() {}
374
+ get focusOrigin() {
375
+ return this._focusOrigin;
376
+ }
377
+ ngAfterViewInit() {
378
+ const element = this._elementRef.nativeElement;
379
+ this._monitorSubscription = this._focusMonitor.monitor(element, element.nodeType === 1 && element.hasAttribute('cdkMonitorSubtreeFocus')).subscribe(origin => {
380
+ this._focusOrigin = origin;
381
+ this.cdkFocusChange.emit(origin);
382
+ });
383
+ }
384
+ ngOnDestroy() {
385
+ this._focusMonitor.stopMonitoring(this._elementRef);
386
+ if (this._monitorSubscription) {
387
+ this._monitorSubscription.unsubscribe();
592
388
  }
593
- ngAfterViewInit() {
594
- const element = this._elementRef.nativeElement;
595
- this._monitorSubscription = this._focusMonitor
596
- .monitor(element, element.nodeType === 1 && element.hasAttribute('cdkMonitorSubtreeFocus'))
597
- .subscribe(origin => {
598
- this._focusOrigin = origin;
599
- this.cdkFocusChange.emit(origin);
600
- });
601
- }
602
- ngOnDestroy() {
603
- this._focusMonitor.stopMonitoring(this._elementRef);
604
- if (this._monitorSubscription) {
605
- this._monitorSubscription.unsubscribe();
606
- }
607
- }
608
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: CdkMonitorFocus, deps: [], target: i0.ɵɵFactoryTarget.Directive });
609
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.2.0-next.2", type: CdkMonitorFocus, isStandalone: true, selector: "[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]", outputs: { cdkFocusChange: "cdkFocusChange" }, exportAs: ["cdkMonitorFocus"], ngImport: i0 });
389
+ }
390
+ static ɵfac = i0.ɵɵngDeclareFactory({
391
+ minVersion: "12.0.0",
392
+ version: "20.2.0-next.2",
393
+ ngImport: i0,
394
+ type: CdkMonitorFocus,
395
+ deps: [],
396
+ target: i0.ɵɵFactoryTarget.Directive
397
+ });
398
+ static ɵdir = i0.ɵɵngDeclareDirective({
399
+ minVersion: "14.0.0",
400
+ version: "20.2.0-next.2",
401
+ type: CdkMonitorFocus,
402
+ isStandalone: true,
403
+ selector: "[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]",
404
+ outputs: {
405
+ cdkFocusChange: "cdkFocusChange"
406
+ },
407
+ exportAs: ["cdkMonitorFocus"],
408
+ ngImport: i0
409
+ });
610
410
  }
611
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: CdkMonitorFocus, decorators: [{
612
- type: Directive,
613
- args: [{
614
- selector: '[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]',
615
- exportAs: 'cdkMonitorFocus',
616
- }]
617
- }], ctorParameters: () => [], propDecorators: { cdkFocusChange: [{
618
- type: Output
619
- }] } });
411
+ i0.ɵɵngDeclareClassMetadata({
412
+ minVersion: "12.0.0",
413
+ version: "20.2.0-next.2",
414
+ ngImport: i0,
415
+ type: CdkMonitorFocus,
416
+ decorators: [{
417
+ type: Directive,
418
+ args: [{
419
+ selector: '[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]',
420
+ exportAs: 'cdkMonitorFocus'
421
+ }]
422
+ }],
423
+ ctorParameters: () => [],
424
+ propDecorators: {
425
+ cdkFocusChange: [{
426
+ type: Output
427
+ }]
428
+ }
429
+ });
620
430
 
621
431
  export { CdkMonitorFocus, FOCUS_MONITOR_DEFAULT_OPTIONS, FocusMonitor, FocusMonitorDetectionMode, INPUT_MODALITY_DETECTOR_DEFAULT_OPTIONS, INPUT_MODALITY_DETECTOR_OPTIONS, InputModalityDetector };
622
432
  //# sourceMappingURL=_focus-monitor-chunk.mjs.map