@angular/cdk 9.2.0 → 9.2.4

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 (241) hide show
  1. package/_text-field.scss +19 -4
  2. package/a11y/focus-monitor/focus-monitor.d.ts +15 -2
  3. package/a11y/high-contrast-mode/high-contrast-mode-detector.d.ts +2 -2
  4. package/a11y/index.metadata.json +1 -1
  5. package/bundles/cdk-a11y.umd.js +133 -86
  6. package/bundles/cdk-a11y.umd.js.map +1 -1
  7. package/bundles/cdk-a11y.umd.min.js +13 -6
  8. package/bundles/cdk-a11y.umd.min.js.map +1 -1
  9. package/bundles/cdk-drag-drop.umd.js +292 -179
  10. package/bundles/cdk-drag-drop.umd.js.map +1 -1
  11. package/bundles/cdk-drag-drop.umd.min.js +23 -9
  12. package/bundles/cdk-drag-drop.umd.min.js.map +1 -1
  13. package/bundles/cdk-overlay.umd.js +2 -12
  14. package/bundles/cdk-overlay.umd.js.map +1 -1
  15. package/bundles/cdk-overlay.umd.min.js +2 -2
  16. package/bundles/cdk-overlay.umd.min.js.map +1 -1
  17. package/bundles/cdk-platform.umd.js +3 -1
  18. package/bundles/cdk-platform.umd.js.map +1 -1
  19. package/bundles/cdk-platform.umd.min.js +4 -4
  20. package/bundles/cdk-platform.umd.min.js.map +1 -1
  21. package/bundles/cdk-scrolling.umd.js +18 -3
  22. package/bundles/cdk-scrolling.umd.js.map +1 -1
  23. package/bundles/cdk-scrolling.umd.min.js +2 -2
  24. package/bundles/cdk-scrolling.umd.min.js.map +1 -1
  25. package/bundles/cdk-table.umd.js +8 -0
  26. package/bundles/cdk-table.umd.js.map +1 -1
  27. package/bundles/cdk-table.umd.min.js +1 -1
  28. package/bundles/cdk-table.umd.min.js.map +1 -1
  29. package/bundles/cdk-testing-protractor.umd.js +14 -10
  30. package/bundles/cdk-testing-protractor.umd.js.map +1 -1
  31. package/bundles/cdk-testing-protractor.umd.min.js +1 -1
  32. package/bundles/cdk-testing-protractor.umd.min.js.map +1 -1
  33. package/bundles/cdk-testing-testbed.umd.js +71 -16
  34. package/bundles/cdk-testing-testbed.umd.js.map +1 -1
  35. package/bundles/cdk-testing-testbed.umd.min.js +6 -6
  36. package/bundles/cdk-testing-testbed.umd.min.js.map +1 -1
  37. package/bundles/cdk-testing.umd.js.map +1 -1
  38. package/bundles/cdk-text-field.umd.js +7 -4
  39. package/bundles/cdk-text-field.umd.js.map +1 -1
  40. package/bundles/cdk-text-field.umd.min.js +2 -2
  41. package/bundles/cdk-text-field.umd.min.js.map +1 -1
  42. package/bundles/cdk-tree.umd.js +9 -4
  43. package/bundles/cdk-tree.umd.js.map +1 -1
  44. package/bundles/cdk-tree.umd.min.js +1 -1
  45. package/bundles/cdk-tree.umd.min.js.map +1 -1
  46. package/bundles/cdk.umd.js +1 -1
  47. package/bundles/cdk.umd.js.map +1 -1
  48. package/bundles/cdk.umd.min.js +1 -1
  49. package/bundles/cdk.umd.min.js.map +1 -1
  50. package/drag-drop/client-rect.d.ts +31 -0
  51. package/drag-drop/directives/config.d.ts +1 -0
  52. package/drag-drop/directives/drop-list.d.ts +4 -3
  53. package/drag-drop/drag-ref.d.ts +8 -2
  54. package/drag-drop/drop-list-ref.d.ts +9 -8
  55. package/drag-drop/index.metadata.json +1 -1
  56. package/drag-drop/parent-position-tracker.d.ts +31 -0
  57. package/drag-drop/public-api.d.ts +1 -1
  58. package/esm2015/a11y/aria-describer/aria-reference.js +6 -6
  59. package/esm2015/a11y/focus-monitor/focus-monitor.js +151 -82
  60. package/esm2015/a11y/high-contrast-mode/high-contrast-mode-detector.js +10 -6
  61. package/esm2015/drag-drop/client-rect.js +75 -0
  62. package/esm2015/drag-drop/directives/config.js +3 -1
  63. package/esm2015/drag-drop/directives/drag.js +3 -2
  64. package/esm2015/drag-drop/directives/drop-list.js +24 -18
  65. package/esm2015/drag-drop/drag-drop-module.js +3 -1
  66. package/esm2015/drag-drop/drag-ref.js +97 -43
  67. package/esm2015/drag-drop/drop-list-ref.js +119 -187
  68. package/esm2015/drag-drop/parent-position-tracker.js +141 -0
  69. package/esm2015/drag-drop/public-api.js +1 -1
  70. package/esm2015/overlay/keyboard/overlay-keyboard-dispatcher.js +2 -2
  71. package/esm2015/overlay/overlay-ref.js +3 -33
  72. package/esm2015/overlay/position/flexible-connected-position-strategy.js +1 -1
  73. package/esm2015/platform/features/shadow-dom.js +4 -2
  74. package/esm2015/scrolling/public-api.js +2 -2
  75. package/esm2015/scrolling/scrolling-module.js +15 -4
  76. package/esm2015/table/row.js +9 -1
  77. package/esm2015/testing/protractor/protractor-element.js +7 -3
  78. package/esm2015/testing/test-element.js +1 -1
  79. package/esm2015/testing/testbed/fake-events/dispatch-events.js +11 -4
  80. package/esm2015/testing/testbed/fake-events/event-objects.js +37 -3
  81. package/esm2015/testing/testbed/unit-test-element.js +17 -5
  82. package/esm2015/text-field/autosize.js +14 -5
  83. package/esm2015/tree/padding.js +9 -10
  84. package/esm2015/tree/tree.js +2 -1
  85. package/esm2015/version.js +1 -1
  86. package/esm5/a11y/aria-describer/aria-reference.js +6 -6
  87. package/esm5/a11y/focus-monitor/focus-monitor.js +105 -60
  88. package/esm5/a11y/high-contrast-mode/high-contrast-mode-detector.js +9 -6
  89. package/esm5/drag-drop/client-rect.js +60 -0
  90. package/esm5/drag-drop/directives/config.js +1 -1
  91. package/esm5/drag-drop/directives/drag.js +3 -2
  92. package/esm5/drag-drop/directives/drop-list.js +13 -10
  93. package/esm5/drag-drop/drag-drop-module.js +3 -1
  94. package/esm5/drag-drop/drag-ref.js +62 -33
  95. package/esm5/drag-drop/drop-list-ref.js +89 -139
  96. package/esm5/drag-drop/parent-position-tracker.js +74 -0
  97. package/esm5/drag-drop/public-api.js +1 -1
  98. package/esm5/overlay/keyboard/overlay-keyboard-dispatcher.js +2 -2
  99. package/esm5/overlay/overlay-ref.js +3 -13
  100. package/esm5/overlay/position/flexible-connected-position-strategy.js +1 -1
  101. package/esm5/platform/features/shadow-dom.js +4 -2
  102. package/esm5/scrolling/scrolling-module.js +19 -4
  103. package/esm5/table/row.js +9 -1
  104. package/esm5/testing/protractor/protractor-element.js +15 -11
  105. package/esm5/testing/test-element.js +1 -1
  106. package/esm5/testing/testbed/fake-events/dispatch-events.js +15 -7
  107. package/esm5/testing/testbed/fake-events/event-objects.js +43 -5
  108. package/esm5/testing/testbed/unit-test-element.js +19 -9
  109. package/esm5/text-field/autosize.js +8 -5
  110. package/esm5/tree/padding.js +9 -5
  111. package/esm5/tree/tree.js +2 -1
  112. package/esm5/version.js +1 -1
  113. package/fesm2015/a11y.js +188 -116
  114. package/fesm2015/a11y.js.map +1 -1
  115. package/fesm2015/cdk.js +1 -1
  116. package/fesm2015/cdk.js.map +1 -1
  117. package/fesm2015/drag-drop.js +448 -247
  118. package/fesm2015/drag-drop.js.map +1 -1
  119. package/fesm2015/overlay.js +3 -33
  120. package/fesm2015/overlay.js.map +1 -1
  121. package/fesm2015/platform.js +3 -1
  122. package/fesm2015/platform.js.map +1 -1
  123. package/fesm2015/scrolling.js +15 -4
  124. package/fesm2015/scrolling.js.map +1 -1
  125. package/fesm2015/table.js +8 -0
  126. package/fesm2015/table.js.map +1 -1
  127. package/fesm2015/testing/protractor.js +6 -2
  128. package/fesm2015/testing/protractor.js.map +1 -1
  129. package/fesm2015/testing/testbed.js +60 -7
  130. package/fesm2015/testing/testbed.js.map +1 -1
  131. package/fesm2015/testing.js.map +1 -1
  132. package/fesm2015/text-field.js +13 -4
  133. package/fesm2015/text-field.js.map +1 -1
  134. package/fesm2015/tree.js +9 -9
  135. package/fesm2015/tree.js.map +1 -1
  136. package/fesm5/a11y.js +134 -87
  137. package/fesm5/a11y.js.map +1 -1
  138. package/fesm5/cdk.js +1 -1
  139. package/fesm5/cdk.js.map +1 -1
  140. package/fesm5/drag-drop.js +294 -181
  141. package/fesm5/drag-drop.js.map +1 -1
  142. package/fesm5/overlay.js +3 -13
  143. package/fesm5/overlay.js.map +1 -1
  144. package/fesm5/platform.js +3 -1
  145. package/fesm5/platform.js.map +1 -1
  146. package/fesm5/scrolling.js +18 -4
  147. package/fesm5/scrolling.js.map +1 -1
  148. package/fesm5/table.js +8 -0
  149. package/fesm5/table.js.map +1 -1
  150. package/fesm5/testing/protractor.js +14 -10
  151. package/fesm5/testing/protractor.js.map +1 -1
  152. package/fesm5/testing/testbed.js +72 -17
  153. package/fesm5/testing/testbed.js.map +1 -1
  154. package/fesm5/testing.js.map +1 -1
  155. package/fesm5/text-field.js +7 -4
  156. package/fesm5/text-field.js.map +1 -1
  157. package/fesm5/tree.js +9 -4
  158. package/fesm5/tree.js.map +1 -1
  159. package/overlay/index.metadata.json +1 -1
  160. package/overlay/overlay-ref.d.ts +0 -3
  161. package/overlay/position/flexible-connected-position-strategy.d.ts +1 -1
  162. package/package.json +1 -1
  163. package/schematics/ng-add/index.js +1 -1
  164. package/schematics/ng-update/devkit-file-system.d.ts +29 -0
  165. package/schematics/ng-update/devkit-file-system.js +67 -0
  166. package/schematics/ng-update/devkit-migration-rule.d.ts +25 -0
  167. package/schematics/ng-update/devkit-migration-rule.js +152 -0
  168. package/schematics/ng-update/devkit-migration.d.ts +37 -0
  169. package/schematics/ng-update/devkit-migration.js +29 -0
  170. package/schematics/ng-update/index.js +7 -7
  171. package/schematics/ng-update/{upgrade-rules/attribute-selectors-rule.d.ts → migrations/attribute-selectors.d.ts} +6 -6
  172. package/schematics/ng-update/migrations/attribute-selectors.js +76 -0
  173. package/schematics/ng-update/{upgrade-rules/class-inheritance-rule.d.ts → migrations/class-inheritance.d.ts} +6 -6
  174. package/schematics/ng-update/migrations/class-inheritance.js +67 -0
  175. package/schematics/ng-update/{upgrade-rules/class-names-rule.d.ts → migrations/class-names.d.ts} +6 -6
  176. package/schematics/ng-update/migrations/class-names.js +98 -0
  177. package/schematics/ng-update/{upgrade-rules/constructor-signature-rule.d.ts → migrations/constructor-signature.d.ts} +6 -6
  178. package/schematics/ng-update/migrations/constructor-signature.js +144 -0
  179. package/schematics/ng-update/{upgrade-rules/css-selectors-rule.d.ts → migrations/css-selectors.d.ts} +6 -6
  180. package/schematics/ng-update/migrations/css-selectors.js +83 -0
  181. package/schematics/ng-update/{upgrade-rules/element-selectors-rule.d.ts → migrations/element-selectors.d.ts} +6 -6
  182. package/schematics/ng-update/migrations/element-selectors.js +74 -0
  183. package/schematics/ng-update/{upgrade-rules/input-names-rule.d.ts → migrations/input-names.d.ts} +6 -6
  184. package/schematics/ng-update/migrations/input-names.js +69 -0
  185. package/schematics/ng-update/{upgrade-rules/method-call-arguments-rule.d.ts → migrations/method-call-arguments.d.ts} +6 -6
  186. package/schematics/ng-update/migrations/method-call-arguments.js +70 -0
  187. package/schematics/ng-update/{upgrade-rules/misc-template-rule.d.ts → migrations/misc-template.d.ts} +6 -6
  188. package/schematics/ng-update/migrations/misc-template.js +47 -0
  189. package/schematics/ng-update/{upgrade-rules/output-names-rule.d.ts → migrations/output-names.d.ts} +6 -6
  190. package/schematics/ng-update/migrations/output-names.js +56 -0
  191. package/schematics/ng-update/{upgrade-rules/property-names-rule.d.ts → migrations/property-names.d.ts} +6 -6
  192. package/schematics/ng-update/migrations/property-names.js +56 -0
  193. package/schematics/ng-update/public-api.d.ts +3 -2
  194. package/schematics/ng-update/public-api.js +5 -4
  195. package/schematics/ng-update/upgrade-data.d.ts +7 -8
  196. package/schematics/ng-update/upgrade-data.js +6 -7
  197. package/schematics/update-tool/component-resource-collector.d.ts +3 -1
  198. package/schematics/update-tool/component-resource-collector.js +8 -8
  199. package/schematics/update-tool/file-system.d.ts +38 -0
  200. package/schematics/update-tool/file-system.js +20 -0
  201. package/schematics/update-tool/index.d.ts +41 -11
  202. package/schematics/update-tool/index.js +135 -106
  203. package/schematics/update-tool/logger.d.ts +16 -0
  204. package/schematics/update-tool/logger.js +27 -0
  205. package/schematics/update-tool/{migration-rule.d.ts → migration.d.ts} +23 -45
  206. package/schematics/update-tool/migration.js +76 -0
  207. package/schematics/update-tool/public-api.d.ts +5 -4
  208. package/schematics/update-tool/public-api.js +6 -6
  209. package/schematics/update-tool/update-recorder.d.ts +14 -0
  210. package/schematics/update-tool/update-recorder.js +20 -0
  211. package/schematics/update-tool/utils/parse-tsconfig.js +1 -1
  212. package/schematics/update-tool/version-changes.js +3 -4
  213. package/schematics/utils/build-component.js +15 -4
  214. package/scrolling/index.metadata.json +1 -1
  215. package/scrolling/scrolling-module.d.ts +2 -0
  216. package/table/index.metadata.json +1 -1
  217. package/testing/protractor/protractor-element.d.ts +1 -1
  218. package/testing/test-element.d.ts +4 -2
  219. package/testing/testbed/fake-events/dispatch-events.d.ts +8 -3
  220. package/testing/testbed/fake-events/event-objects.d.ts +12 -1
  221. package/testing/testbed/unit-test-element.d.ts +1 -1
  222. package/text-field/_text-field.scss +19 -4
  223. package/text-field/autosize.d.ts +2 -0
  224. package/text-field/index.metadata.json +1 -1
  225. package/text-field-prebuilt.css +1 -1
  226. package/tree/index.metadata.json +1 -1
  227. package/tree/padding.d.ts +6 -2
  228. package/schematics/ng-update/upgrade-rules/attribute-selectors-rule.js +0 -76
  229. package/schematics/ng-update/upgrade-rules/class-inheritance-rule.js +0 -67
  230. package/schematics/ng-update/upgrade-rules/class-names-rule.js +0 -98
  231. package/schematics/ng-update/upgrade-rules/constructor-signature-rule.js +0 -144
  232. package/schematics/ng-update/upgrade-rules/css-selectors-rule.js +0 -83
  233. package/schematics/ng-update/upgrade-rules/element-selectors-rule.js +0 -74
  234. package/schematics/ng-update/upgrade-rules/index.d.ts +0 -22
  235. package/schematics/ng-update/upgrade-rules/index.js +0 -116
  236. package/schematics/ng-update/upgrade-rules/input-names-rule.js +0 -69
  237. package/schematics/ng-update/upgrade-rules/method-call-arguments-rule.js +0 -70
  238. package/schematics/ng-update/upgrade-rules/misc-template-rule.js +0 -47
  239. package/schematics/ng-update/upgrade-rules/output-names-rule.js +0 -56
  240. package/schematics/ng-update/upgrade-rules/property-names-rule.js +0 -56
  241. package/schematics/update-tool/migration-rule.js +0 -101
package/fesm2015/a11y.js CHANGED
@@ -4,7 +4,7 @@ import { Subject, Subscription, of } from 'rxjs';
4
4
  import { hasModifierKey, A, Z, ZERO, NINE, LEFT_ARROW, RIGHT_ARROW, UP_ARROW, DOWN_ARROW, TAB } from '@angular/cdk/keycodes';
5
5
  import { tap, debounceTime, filter, map, take } from 'rxjs/operators';
6
6
  import { coerceBooleanProperty, coerceElement } from '@angular/cdk/coercion';
7
- import { Platform, normalizePassiveListenerOptions, PlatformModule } from '@angular/cdk/platform';
7
+ import { Platform, normalizePassiveListenerOptions, _getShadowRoot, PlatformModule } from '@angular/cdk/platform';
8
8
  import { ContentObserver, ObserversModule } from '@angular/cdk/observers';
9
9
 
10
10
  /**
@@ -20,10 +20,10 @@ import { ContentObserver, ObserversModule } from '@angular/cdk/observers';
20
20
  * found in the LICENSE file at https://angular.io/license
21
21
  */
22
22
  /**
23
- * IDs are deliminated by an empty space, as per the spec.
23
+ * IDs are delimited by an empty space, as per the spec.
24
24
  * @type {?}
25
25
  */
26
- const ID_DELIMINATOR = ' ';
26
+ const ID_DELIMITER = ' ';
27
27
  /**
28
28
  * Adds the given ID to the specified ARIA attribute on an element.
29
29
  * Used for attributes such as aria-labelledby, aria-owns, etc.
@@ -43,7 +43,7 @@ function addAriaReferencedId(el, attr, id) {
43
43
  return;
44
44
  }
45
45
  ids.push(id.trim());
46
- el.setAttribute(attr, ids.join(ID_DELIMINATOR));
46
+ el.setAttribute(attr, ids.join(ID_DELIMITER));
47
47
  }
48
48
  /**
49
49
  * Removes the given ID from the specified ARIA attribute on an element.
@@ -63,7 +63,7 @@ function removeAriaReferencedId(el, attr, id) {
63
63
  */
64
64
  val => val != id.trim()));
65
65
  if (filteredIds.length) {
66
- el.setAttribute(attr, filteredIds.join(ID_DELIMINATOR));
66
+ el.setAttribute(attr, filteredIds.join(ID_DELIMITER));
67
67
  }
68
68
  else {
69
69
  el.removeAttribute(attr);
@@ -77,7 +77,7 @@ function removeAriaReferencedId(el, attr, id) {
77
77
  * @return {?}
78
78
  */
79
79
  function getAriaReferenceIds(el, attr) {
80
- // Get string array of all individual ids (whitespace deliminated) in the attribute value
80
+ // Get string array of all individual ids (whitespace delimited) in the attribute value
81
81
  return (el.getAttribute(attr) || '').match(/\S+/g) || [];
82
82
  }
83
83
 
@@ -2653,6 +2653,31 @@ if (false) {
2653
2653
  CdkAriaLive.prototype._ngZone;
2654
2654
  }
2655
2655
 
2656
+ /**
2657
+ * @fileoverview added by tsickle
2658
+ * Generated from: src/cdk/a11y/fake-mousedown.ts
2659
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2660
+ */
2661
+ /**
2662
+ * @license
2663
+ * Copyright Google LLC All Rights Reserved.
2664
+ *
2665
+ * Use of this source code is governed by an MIT-style license that can be
2666
+ * found in the LICENSE file at https://angular.io/license
2667
+ */
2668
+ /**
2669
+ * Screenreaders will often fire fake mousedown events when a focusable element
2670
+ * is activated using the keyboard. We can typically distinguish between these faked
2671
+ * mousedown events and real mousedown events using the "buttons" property. While
2672
+ * real mousedowns will indicate the mouse button that was pressed (e.g. "1" for
2673
+ * the left mouse button), faked mousedowns will usually set the property value to 0.
2674
+ * @param {?} event
2675
+ * @return {?}
2676
+ */
2677
+ function isFakeMousedownFromScreenReader(event) {
2678
+ return event.buttons === 0;
2679
+ }
2680
+
2656
2681
  /**
2657
2682
  * @fileoverview added by tsickle
2658
2683
  * Generated from: src/cdk/a11y/focus-monitor/focus-monitor.ts
@@ -2743,6 +2768,13 @@ class FocusMonitor {
2743
2768
  * The number of elements currently being monitored.
2744
2769
  */
2745
2770
  this._monitoredElementCount = 0;
2771
+ /**
2772
+ * Keeps track of the root nodes to which we've currently bound a focus/blur handler,
2773
+ * as well as the number of monitored elements that they contain. We have to treat focus/blur
2774
+ * handlers differently from the rest of the events, because the browser won't emit events
2775
+ * to the document when focus moves inside of a shadow root.
2776
+ */
2777
+ this._rootNodeFocusListenerCount = new Map();
2746
2778
  /**
2747
2779
  * Event listener for `keydown` events on the document.
2748
2780
  * Needs to be an arrow function in order to preserve the context when it gets bound.
@@ -2760,13 +2792,18 @@ class FocusMonitor {
2760
2792
  * Needs to be an arrow function in order to preserve the context when it gets bound.
2761
2793
  */
2762
2794
  this._documentMousedownListener = (/**
2795
+ * @param {?} event
2763
2796
  * @return {?}
2764
2797
  */
2765
- () => {
2798
+ (event) => {
2766
2799
  // On mousedown record the origin only if there is not touch
2767
2800
  // target, since a mousedown can happen as a result of a touch event.
2768
2801
  if (!this._lastTouchTarget) {
2769
- this._setOriginForCurrentEventQueue('mouse');
2802
+ // In some cases screen readers fire fake `mousedown` events instead of `keydown`.
2803
+ // Resolve the focus source to `keyboard` if we detect one of them.
2804
+ /** @type {?} */
2805
+ const source = isFakeMousedownFromScreenReader(event) ? 'keyboard' : 'mouse';
2806
+ this._setOriginForCurrentEventQueue(source);
2770
2807
  }
2771
2808
  });
2772
2809
  /**
@@ -2784,10 +2821,7 @@ class FocusMonitor {
2784
2821
  if (this._touchTimeoutId != null) {
2785
2822
  clearTimeout(this._touchTimeoutId);
2786
2823
  }
2787
- // Since this listener is bound on the `document` level, any events coming from the shadow DOM
2788
- // will have their `target` set to the shadow root. If available, use `composedPath` to
2789
- // figure out the event target.
2790
- this._lastTouchTarget = event.composedPath ? event.composedPath()[0] : event.target;
2824
+ this._lastTouchTarget = getTarget(event);
2791
2825
  this._touchTimeoutId = setTimeout((/**
2792
2826
  * @return {?}
2793
2827
  */
@@ -2809,6 +2843,24 @@ class FocusMonitor {
2809
2843
  */
2810
2844
  () => this._windowFocused = false));
2811
2845
  });
2846
+ /**
2847
+ * Event listener for `focus` and 'blur' events on the document.
2848
+ * Needs to be an arrow function in order to preserve the context when it gets bound.
2849
+ */
2850
+ this._rootNodeFocusAndBlurListener = (/**
2851
+ * @param {?} event
2852
+ * @return {?}
2853
+ */
2854
+ (event) => {
2855
+ /** @type {?} */
2856
+ const target = getTarget(event);
2857
+ /** @type {?} */
2858
+ const handler = event.type === 'focus' ? this._onFocus : this._onBlur;
2859
+ // We need to walk up the ancestor chain in order to support `checkChildren`.
2860
+ for (let element = target; element; element = element.parentElement) {
2861
+ handler.call(this, (/** @type {?} */ (event)), element);
2862
+ }
2863
+ });
2812
2864
  this._document = document;
2813
2865
  this._detectionMode = (options === null || options === void 0 ? void 0 : options.detectionMode) || 0 /* IMMEDIATE */;
2814
2866
  }
@@ -2824,53 +2876,32 @@ class FocusMonitor {
2824
2876
  }
2825
2877
  /** @type {?} */
2826
2878
  const nativeElement = coerceElement(element);
2879
+ // If the element is inside the shadow DOM, we need to bind our focus/blur listeners to
2880
+ // the shadow root, rather than the `document`, because the browser won't emit focus events
2881
+ // to the `document`, if focus is moving within the same shadow root.
2882
+ /** @type {?} */
2883
+ const rootNode = ((/** @type {?} */ (_getShadowRoot(nativeElement)))) || this._getDocument();
2884
+ /** @type {?} */
2885
+ const cachedInfo = this._elementInfo.get(nativeElement);
2827
2886
  // Check if we're already monitoring this element.
2828
- if (this._elementInfo.has(nativeElement)) {
2829
- /** @type {?} */
2830
- let cachedInfo = this._elementInfo.get(nativeElement);
2831
- (/** @type {?} */ (cachedInfo)).checkChildren = checkChildren;
2832
- return (/** @type {?} */ (cachedInfo)).subject.asObservable();
2887
+ if (cachedInfo) {
2888
+ if (checkChildren) {
2889
+ // TODO(COMP-318): this can be problematic, because it'll turn all non-checkChildren
2890
+ // observers into ones that behave as if `checkChildren` was turned on. We need a more
2891
+ // robust solution.
2892
+ cachedInfo.checkChildren = true;
2893
+ }
2894
+ return cachedInfo.subject.asObservable();
2833
2895
  }
2834
2896
  // Create monitored element info.
2835
2897
  /** @type {?} */
2836
- let info = {
2837
- unlisten: (/**
2838
- * @return {?}
2839
- */
2840
- () => { }),
2898
+ const info = {
2841
2899
  checkChildren: checkChildren,
2842
- subject: new Subject()
2900
+ subject: new Subject(),
2901
+ rootNode
2843
2902
  };
2844
2903
  this._elementInfo.set(nativeElement, info);
2845
- this._incrementMonitoredElementCount();
2846
- // Start listening. We need to listen in capture phase since focus events don't bubble.
2847
- /** @type {?} */
2848
- let focusListener = (/**
2849
- * @param {?} event
2850
- * @return {?}
2851
- */
2852
- (event) => this._onFocus(event, nativeElement));
2853
- /** @type {?} */
2854
- let blurListener = (/**
2855
- * @param {?} event
2856
- * @return {?}
2857
- */
2858
- (event) => this._onBlur(event, nativeElement));
2859
- this._ngZone.runOutsideAngular((/**
2860
- * @return {?}
2861
- */
2862
- () => {
2863
- nativeElement.addEventListener('focus', focusListener, true);
2864
- nativeElement.addEventListener('blur', blurListener, true);
2865
- }));
2866
- // Create an unlisten function for later.
2867
- info.unlisten = (/**
2868
- * @return {?}
2869
- */
2870
- () => {
2871
- nativeElement.removeEventListener('focus', focusListener, true);
2872
- nativeElement.removeEventListener('blur', blurListener, true);
2873
- });
2904
+ this._registerGlobalListeners(info);
2874
2905
  return info.subject.asObservable();
2875
2906
  }
2876
2907
  /**
@@ -2883,11 +2914,10 @@ class FocusMonitor {
2883
2914
  /** @type {?} */
2884
2915
  const elementInfo = this._elementInfo.get(nativeElement);
2885
2916
  if (elementInfo) {
2886
- elementInfo.unlisten();
2887
2917
  elementInfo.subject.complete();
2888
2918
  this._setClasses(nativeElement);
2889
2919
  this._elementInfo.delete(nativeElement);
2890
- this._decrementMonitoredElementCount();
2920
+ this._removeGlobalListeners(elementInfo);
2891
2921
  }
2892
2922
  }
2893
2923
  /**
@@ -2950,6 +2980,31 @@ class FocusMonitor {
2950
2980
  element.classList.remove(className);
2951
2981
  }
2952
2982
  }
2983
+ /**
2984
+ * @private
2985
+ * @param {?} event
2986
+ * @return {?}
2987
+ */
2988
+ _getFocusOrigin(event) {
2989
+ // If we couldn't detect a cause for the focus event, it's due to one of three reasons:
2990
+ // 1) The window has just regained focus, in which case we want to restore the focused state of
2991
+ // the element from before the window blurred.
2992
+ // 2) It was caused by a touch event, in which case we mark the origin as 'touch'.
2993
+ // 3) The element was programmatically focused, in which case we should mark the origin as
2994
+ // 'program'.
2995
+ if (this._origin) {
2996
+ return this._origin;
2997
+ }
2998
+ if (this._windowFocused && this._lastFocusOrigin) {
2999
+ return this._lastFocusOrigin;
3000
+ }
3001
+ else if (this._wasCausedByTouch(event)) {
3002
+ return 'touch';
3003
+ }
3004
+ else {
3005
+ return 'program';
3006
+ }
3007
+ }
2953
3008
  /**
2954
3009
  * Sets the focus classes on the element based on the given focus origin.
2955
3010
  * @private
@@ -2958,15 +3013,11 @@ class FocusMonitor {
2958
3013
  * @return {?}
2959
3014
  */
2960
3015
  _setClasses(element, origin) {
2961
- /** @type {?} */
2962
- const elementInfo = this._elementInfo.get(element);
2963
- if (elementInfo) {
2964
- this._toggleClass(element, 'cdk-focused', !!origin);
2965
- this._toggleClass(element, 'cdk-touch-focused', origin === 'touch');
2966
- this._toggleClass(element, 'cdk-keyboard-focused', origin === 'keyboard');
2967
- this._toggleClass(element, 'cdk-mouse-focused', origin === 'mouse');
2968
- this._toggleClass(element, 'cdk-program-focused', origin === 'program');
2969
- }
3016
+ this._toggleClass(element, 'cdk-focused', !!origin);
3017
+ this._toggleClass(element, 'cdk-touch-focused', origin === 'touch');
3018
+ this._toggleClass(element, 'cdk-keyboard-focused', origin === 'keyboard');
3019
+ this._toggleClass(element, 'cdk-mouse-focused', origin === 'mouse');
3020
+ this._toggleClass(element, 'cdk-program-focused', origin === 'program');
2970
3021
  }
2971
3022
  /**
2972
3023
  * Sets the origin and schedules an async function to clear it at the end of the event queue.
@@ -3017,7 +3068,7 @@ class FocusMonitor {
3017
3068
  // focus event. When that blur event fires we know that whatever follows is not a result of the
3018
3069
  // touchstart.
3019
3070
  /** @type {?} */
3020
- let focusTarget = event.target;
3071
+ const focusTarget = getTarget(event);
3021
3072
  return this._lastTouchTarget instanceof Node && focusTarget instanceof Node &&
3022
3073
  (focusTarget === this._lastTouchTarget || focusTarget.contains(this._lastTouchTarget));
3023
3074
  }
@@ -3041,28 +3092,11 @@ class FocusMonitor {
3041
3092
  // monitored element itself.
3042
3093
  /** @type {?} */
3043
3094
  const elementInfo = this._elementInfo.get(element);
3044
- if (!elementInfo || (!elementInfo.checkChildren && element !== event.target)) {
3095
+ if (!elementInfo || (!elementInfo.checkChildren && element !== getTarget(event))) {
3045
3096
  return;
3046
3097
  }
3047
- // If we couldn't detect a cause for the focus event, it's due to one of three reasons:
3048
- // 1) The window has just regained focus, in which case we want to restore the focused state of
3049
- // the element from before the window blurred.
3050
- // 2) It was caused by a touch event, in which case we mark the origin as 'touch'.
3051
- // 3) The element was programmatically focused, in which case we should mark the origin as
3052
- // 'program'.
3053
3098
  /** @type {?} */
3054
- let origin = this._origin;
3055
- if (!origin) {
3056
- if (this._windowFocused && this._lastFocusOrigin) {
3057
- origin = this._lastFocusOrigin;
3058
- }
3059
- else if (this._wasCausedByTouch(event)) {
3060
- origin = 'touch';
3061
- }
3062
- else {
3063
- origin = 'program';
3064
- }
3065
- }
3099
+ const origin = this._getFocusOrigin(event);
3066
3100
  this._setClasses(element, origin);
3067
3101
  this._emitOrigin(elementInfo.subject, origin);
3068
3102
  this._lastFocusOrigin = origin;
@@ -3099,11 +3133,29 @@ class FocusMonitor {
3099
3133
  }
3100
3134
  /**
3101
3135
  * @private
3136
+ * @param {?} elementInfo
3102
3137
  * @return {?}
3103
3138
  */
3104
- _incrementMonitoredElementCount() {
3139
+ _registerGlobalListeners(elementInfo) {
3140
+ if (!this._platform.isBrowser) {
3141
+ return;
3142
+ }
3143
+ /** @type {?} */
3144
+ const rootNode = elementInfo.rootNode;
3145
+ /** @type {?} */
3146
+ const rootNodeFocusListeners = this._rootNodeFocusListenerCount.get(rootNode) || 0;
3147
+ if (!rootNodeFocusListeners) {
3148
+ this._ngZone.runOutsideAngular((/**
3149
+ * @return {?}
3150
+ */
3151
+ () => {
3152
+ rootNode.addEventListener('focus', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
3153
+ rootNode.addEventListener('blur', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
3154
+ }));
3155
+ }
3156
+ this._rootNodeFocusListenerCount.set(rootNode, rootNodeFocusListeners + 1);
3105
3157
  // Register global listeners when first element is monitored.
3106
- if (++this._monitoredElementCount == 1 && this._platform.isBrowser) {
3158
+ if (++this._monitoredElementCount === 1) {
3107
3159
  // Note: we listen to events in the capture phase so we
3108
3160
  // can detect them even if the user stops propagation.
3109
3161
  this._ngZone.runOutsideAngular((/**
@@ -3123,9 +3175,24 @@ class FocusMonitor {
3123
3175
  }
3124
3176
  /**
3125
3177
  * @private
3178
+ * @param {?} elementInfo
3126
3179
  * @return {?}
3127
3180
  */
3128
- _decrementMonitoredElementCount() {
3181
+ _removeGlobalListeners(elementInfo) {
3182
+ /** @type {?} */
3183
+ const rootNode = elementInfo.rootNode;
3184
+ if (this._rootNodeFocusListenerCount.has(rootNode)) {
3185
+ /** @type {?} */
3186
+ const rootNodeFocusListeners = (/** @type {?} */ (this._rootNodeFocusListenerCount.get(rootNode)));
3187
+ if (rootNodeFocusListeners > 1) {
3188
+ this._rootNodeFocusListenerCount.set(rootNode, rootNodeFocusListeners - 1);
3189
+ }
3190
+ else {
3191
+ rootNode.removeEventListener('focus', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
3192
+ rootNode.removeEventListener('blur', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
3193
+ this._rootNodeFocusListenerCount.delete(rootNode);
3194
+ }
3195
+ }
3129
3196
  // Unregister global listeners when last element is unmonitored.
3130
3197
  if (!--this._monitoredElementCount) {
3131
3198
  /** @type {?} */
@@ -3209,6 +3276,15 @@ if (false) {
3209
3276
  * @private
3210
3277
  */
3211
3278
  FocusMonitor.prototype._monitoredElementCount;
3279
+ /**
3280
+ * Keeps track of the root nodes to which we've currently bound a focus/blur handler,
3281
+ * as well as the number of monitored elements that they contain. We have to treat focus/blur
3282
+ * handlers differently from the rest of the events, because the browser won't emit events
3283
+ * to the document when focus moves inside of a shadow root.
3284
+ * @type {?}
3285
+ * @private
3286
+ */
3287
+ FocusMonitor.prototype._rootNodeFocusListenerCount;
3212
3288
  /**
3213
3289
  * The specified detection mode, used for attributing the origin of a focus
3214
3290
  * event.
@@ -3250,6 +3326,13 @@ if (false) {
3250
3326
  * @protected
3251
3327
  */
3252
3328
  FocusMonitor.prototype._document;
3329
+ /**
3330
+ * Event listener for `focus` and 'blur' events on the document.
3331
+ * Needs to be an arrow function in order to preserve the context when it gets bound.
3332
+ * @type {?}
3333
+ * @private
3334
+ */
3335
+ FocusMonitor.prototype._rootNodeFocusAndBlurListener;
3253
3336
  /**
3254
3337
  * @type {?}
3255
3338
  * @private
@@ -3261,6 +3344,16 @@ if (false) {
3261
3344
  */
3262
3345
  FocusMonitor.prototype._platform;
3263
3346
  }
3347
+ /**
3348
+ * Gets the target of an event, accounting for Shadow DOM.
3349
+ * @param {?} event
3350
+ * @return {?}
3351
+ */
3352
+ function getTarget(event) {
3353
+ // If an event is bound outside the Shadow DOM, the `event.target` will
3354
+ // point to the shadow root so we have to use `composedPath` instead.
3355
+ return (/** @type {?} */ ((event.composedPath ? event.composedPath()[0] : event.target)));
3356
+ }
3264
3357
  /**
3265
3358
  * Directive that determines how a particular element was focused (via keyboard, mouse, touch, or
3266
3359
  * programmatically) and adds corresponding classes to the element.
@@ -3327,31 +3420,6 @@ if (false) {
3327
3420
  CdkMonitorFocus.prototype._focusMonitor;
3328
3421
  }
3329
3422
 
3330
- /**
3331
- * @fileoverview added by tsickle
3332
- * Generated from: src/cdk/a11y/fake-mousedown.ts
3333
- * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3334
- */
3335
- /**
3336
- * @license
3337
- * Copyright Google LLC All Rights Reserved.
3338
- *
3339
- * Use of this source code is governed by an MIT-style license that can be
3340
- * found in the LICENSE file at https://angular.io/license
3341
- */
3342
- /**
3343
- * Screenreaders will often fire fake mousedown events when a focusable element
3344
- * is activated using the keyboard. We can typically distinguish between these faked
3345
- * mousedown events and real mousedown events using the "buttons" property. While
3346
- * real mousedowns will indicate the mouse button that was pressed (e.g. "1" for
3347
- * the left mouse button), faked mousedowns will usually set the property value to 0.
3348
- * @param {?} event
3349
- * @return {?}
3350
- */
3351
- function isFakeMousedownFromScreenReader(event) {
3352
- return event.buttons === 0;
3353
- }
3354
-
3355
3423
  /**
3356
3424
  * @fileoverview added by tsickle
3357
3425
  * Generated from: src/cdk/a11y/high-contrast-mode/high-contrast-mode-detector.ts
@@ -3379,7 +3447,7 @@ const WHITE_ON_BLACK_CSS_CLASS = 'cdk-high-contrast-white-on-black';
3379
3447
  */
3380
3448
  const HIGH_CONTRAST_MODE_ACTIVE_CSS_CLASS = 'cdk-high-contrast-active';
3381
3449
  /**
3382
- * Service to determine whether the browser is currently in a high-constrast-mode environment.
3450
+ * Service to determine whether the browser is currently in a high-contrast-mode environment.
3383
3451
  *
3384
3452
  * Microsoft Windows supports an accessibility feature called "High Contrast Mode". This mode
3385
3453
  * changes the appearance of all applications, including web applications, to dramatically increase
@@ -3399,7 +3467,7 @@ class HighContrastModeDetector {
3399
3467
  this._document = document;
3400
3468
  }
3401
3469
  /**
3402
- * Gets the current high-constrast-mode for the page.
3470
+ * Gets the current high-contrast-mode for the page.
3403
3471
  * @return {?}
3404
3472
  */
3405
3473
  getHighContrastMode() {
@@ -3416,11 +3484,15 @@ class HighContrastModeDetector {
3416
3484
  this._document.body.appendChild(testElement);
3417
3485
  // Get the computed style for the background color, collapsing spaces to normalize between
3418
3486
  // browsers. Once we get this color, we no longer need the test element. Access the `window`
3419
- // via the document so we can fake it in tests.
3487
+ // via the document so we can fake it in tests. Note that we have extra null checks, because
3488
+ // this logic will likely run during app bootstrap and throwing can break the entire app.
3489
+ /** @type {?} */
3490
+ const documentWindow = this._document.defaultView || window;
3420
3491
  /** @type {?} */
3421
- const documentWindow = (/** @type {?} */ (this._document.defaultView));
3492
+ const computedStyle = (documentWindow && documentWindow.getComputedStyle) ?
3493
+ documentWindow.getComputedStyle(testElement) : null;
3422
3494
  /** @type {?} */
3423
- const computedColor = (documentWindow.getComputedStyle(testElement).backgroundColor || '').replace(/ /g, '');
3495
+ const computedColor = (computedStyle && computedStyle.backgroundColor || '').replace(/ /g, '');
3424
3496
  this._document.body.removeChild(testElement);
3425
3497
  switch (computedColor) {
3426
3498
  case 'rgb(0,0,0)': return 2 /* WHITE_ON_BLACK */;