@angular/cdk 9.1.3 → 9.2.2

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/a11y/focus-monitor/focus-monitor.d.ts +43 -4
  2. package/a11y/high-contrast-mode/high-contrast-mode-detector.d.ts +2 -2
  3. package/a11y/index.metadata.json +1 -1
  4. package/bundles/cdk-a11y.umd.js +140 -90
  5. package/bundles/cdk-a11y.umd.js.map +1 -1
  6. package/bundles/cdk-a11y.umd.min.js +14 -7
  7. package/bundles/cdk-a11y.umd.min.js.map +1 -1
  8. package/bundles/cdk-coercion.umd.js +0 -1
  9. package/bundles/cdk-coercion.umd.js.map +1 -1
  10. package/bundles/cdk-coercion.umd.min.js.map +1 -1
  11. package/bundles/cdk-drag-drop.umd.js +292 -179
  12. package/bundles/cdk-drag-drop.umd.js.map +1 -1
  13. package/bundles/cdk-drag-drop.umd.min.js +23 -9
  14. package/bundles/cdk-drag-drop.umd.min.js.map +1 -1
  15. package/bundles/cdk-overlay.umd.js.map +1 -1
  16. package/bundles/cdk-platform.umd.js +3 -1
  17. package/bundles/cdk-platform.umd.js.map +1 -1
  18. package/bundles/cdk-platform.umd.min.js +4 -4
  19. package/bundles/cdk-platform.umd.min.js.map +1 -1
  20. package/bundles/cdk-scrolling.umd.js +18 -3
  21. package/bundles/cdk-scrolling.umd.js.map +1 -1
  22. package/bundles/cdk-scrolling.umd.min.js +2 -2
  23. package/bundles/cdk-scrolling.umd.min.js.map +1 -1
  24. package/bundles/cdk-table.umd.js +58 -27
  25. package/bundles/cdk-table.umd.js.map +1 -1
  26. package/bundles/cdk-table.umd.min.js +12 -5
  27. package/bundles/cdk-table.umd.min.js.map +1 -1
  28. package/bundles/cdk-testing-protractor.umd.js +15 -9
  29. package/bundles/cdk-testing-protractor.umd.js.map +1 -1
  30. package/bundles/cdk-testing-protractor.umd.min.js +2 -2
  31. package/bundles/cdk-testing-protractor.umd.min.js.map +1 -1
  32. package/bundles/cdk-testing-testbed.umd.js +77 -19
  33. package/bundles/cdk-testing-testbed.umd.js.map +1 -1
  34. package/bundles/cdk-testing-testbed.umd.min.js +8 -8
  35. package/bundles/cdk-testing-testbed.umd.min.js.map +1 -1
  36. package/bundles/cdk-tree.umd.js +9 -4
  37. package/bundles/cdk-tree.umd.js.map +1 -1
  38. package/bundles/cdk-tree.umd.min.js +1 -1
  39. package/bundles/cdk-tree.umd.min.js.map +1 -1
  40. package/bundles/cdk.umd.js +1 -1
  41. package/bundles/cdk.umd.js.map +1 -1
  42. package/bundles/cdk.umd.min.js +1 -1
  43. package/bundles/cdk.umd.min.js.map +1 -1
  44. package/coercion/array.d.ts +1 -0
  45. package/drag-drop/client-rect.d.ts +31 -0
  46. package/drag-drop/directives/config.d.ts +1 -0
  47. package/drag-drop/directives/drop-list.d.ts +4 -3
  48. package/drag-drop/drag-ref.d.ts +8 -2
  49. package/drag-drop/drop-list-ref.d.ts +9 -8
  50. package/drag-drop/index.metadata.json +1 -1
  51. package/drag-drop/parent-position-tracker.d.ts +31 -0
  52. package/drag-drop/public-api.d.ts +1 -1
  53. package/esm2015/a11y/aria-describer/aria-reference.js +6 -6
  54. package/esm2015/a11y/focus-monitor/focus-monitor.js +198 -92
  55. package/esm2015/a11y/focus-trap/configurable-focus-trap-factory.js +3 -3
  56. package/esm2015/a11y/focus-trap/focus-trap.js +1 -1
  57. package/esm2015/a11y/high-contrast-mode/high-contrast-mode-detector.js +10 -6
  58. package/esm2015/a11y/live-announcer/live-announcer.js +1 -1
  59. package/esm2015/a11y/public-api.js +2 -2
  60. package/esm2015/coercion/array.js +1 -2
  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/position/flexible-connected-position-strategy.js +1 -1
  71. package/esm2015/platform/features/shadow-dom.js +4 -2
  72. package/esm2015/scrolling/public-api.js +2 -2
  73. package/esm2015/scrolling/scrolling-module.js +15 -4
  74. package/esm2015/table/cell.js +18 -8
  75. package/esm2015/table/public-api.js +3 -2
  76. package/esm2015/table/row.js +24 -8
  77. package/esm2015/table/table.js +26 -12
  78. package/esm2015/table/text-column.js +3 -26
  79. package/esm2015/table/tokens.js +44 -0
  80. package/esm2015/testing/protractor/protractor-harness-environment.js +13 -8
  81. package/esm2015/testing/testbed/fake-events/dispatch-events.js +11 -4
  82. package/esm2015/testing/testbed/fake-events/event-objects.js +37 -3
  83. package/esm2015/testing/testbed/testbed-harness-environment.js +16 -10
  84. package/esm2015/testing/testbed/unit-test-element.js +13 -2
  85. package/esm2015/tree/padding.js +9 -10
  86. package/esm2015/tree/tree.js +2 -1
  87. package/esm2015/version.js +1 -1
  88. package/esm5/a11y/aria-describer/aria-reference.js +6 -6
  89. package/esm5/a11y/focus-monitor/focus-monitor.js +112 -65
  90. package/esm5/a11y/high-contrast-mode/high-contrast-mode-detector.js +9 -6
  91. package/esm5/coercion/array.js +1 -2
  92. package/esm5/drag-drop/client-rect.js +60 -0
  93. package/esm5/drag-drop/directives/config.js +1 -1
  94. package/esm5/drag-drop/directives/drag.js +3 -2
  95. package/esm5/drag-drop/directives/drop-list.js +13 -10
  96. package/esm5/drag-drop/drag-drop-module.js +3 -1
  97. package/esm5/drag-drop/drag-ref.js +62 -33
  98. package/esm5/drag-drop/drop-list-ref.js +89 -139
  99. package/esm5/drag-drop/parent-position-tracker.js +74 -0
  100. package/esm5/drag-drop/public-api.js +1 -1
  101. package/esm5/overlay/position/flexible-connected-position-strategy.js +1 -1
  102. package/esm5/platform/features/shadow-dom.js +4 -2
  103. package/esm5/scrolling/scrolling-module.js +19 -4
  104. package/esm5/table/cell.js +13 -8
  105. package/esm5/table/public-api.js +2 -1
  106. package/esm5/table/row.js +21 -11
  107. package/esm5/table/table.js +16 -11
  108. package/esm5/table/text-column.js +3 -4
  109. package/esm5/table/tokens.js +16 -0
  110. package/esm5/testing/protractor/protractor-harness-environment.js +17 -11
  111. package/esm5/testing/testbed/fake-events/dispatch-events.js +15 -7
  112. package/esm5/testing/testbed/fake-events/event-objects.js +43 -5
  113. package/esm5/testing/testbed/testbed-harness-environment.js +17 -11
  114. package/esm5/testing/testbed/unit-test-element.js +10 -3
  115. package/esm5/tree/padding.js +9 -5
  116. package/esm5/tree/tree.js +2 -1
  117. package/esm5/version.js +1 -1
  118. package/fesm2015/a11y.js +234 -126
  119. package/fesm2015/a11y.js.map +1 -1
  120. package/fesm2015/cdk.js +1 -1
  121. package/fesm2015/cdk.js.map +1 -1
  122. package/fesm2015/coercion.js +0 -1
  123. package/fesm2015/coercion.js.map +1 -1
  124. package/fesm2015/drag-drop.js +448 -247
  125. package/fesm2015/drag-drop.js.map +1 -1
  126. package/fesm2015/overlay.js.map +1 -1
  127. package/fesm2015/platform.js +3 -1
  128. package/fesm2015/platform.js.map +1 -1
  129. package/fesm2015/scrolling.js +15 -4
  130. package/fesm2015/scrolling.js.map +1 -1
  131. package/fesm2015/table.js +98 -49
  132. package/fesm2015/table.js.map +1 -1
  133. package/fesm2015/testing/protractor.js +13 -8
  134. package/fesm2015/testing/protractor.js.map +1 -1
  135. package/fesm2015/testing/testbed.js +71 -13
  136. package/fesm2015/testing/testbed.js.map +1 -1
  137. package/fesm2015/tree.js +9 -9
  138. package/fesm2015/tree.js.map +1 -1
  139. package/fesm5/a11y.js +141 -92
  140. package/fesm5/a11y.js.map +1 -1
  141. package/fesm5/cdk.js +1 -1
  142. package/fesm5/cdk.js.map +1 -1
  143. package/fesm5/coercion.js +0 -1
  144. package/fesm5/coercion.js.map +1 -1
  145. package/fesm5/drag-drop.js +294 -181
  146. package/fesm5/drag-drop.js.map +1 -1
  147. package/fesm5/overlay.js.map +1 -1
  148. package/fesm5/platform.js +3 -1
  149. package/fesm5/platform.js.map +1 -1
  150. package/fesm5/scrolling.js +18 -4
  151. package/fesm5/scrolling.js.map +1 -1
  152. package/fesm5/table.js +59 -29
  153. package/fesm5/table.js.map +1 -1
  154. package/fesm5/testing/protractor.js +17 -11
  155. package/fesm5/testing/protractor.js.map +1 -1
  156. package/fesm5/testing/testbed.js +78 -20
  157. package/fesm5/testing/testbed.js.map +1 -1
  158. package/fesm5/tree.js +9 -4
  159. package/fesm5/tree.js.map +1 -1
  160. package/overlay/position/flexible-connected-position-strategy.d.ts +1 -1
  161. package/package.json +1 -1
  162. package/schematics/ng-add/index.js +1 -1
  163. package/schematics/ng-update/devkit-file-system.d.ts +29 -0
  164. package/schematics/ng-update/devkit-file-system.js +67 -0
  165. package/schematics/ng-update/devkit-migration-rule.d.ts +25 -0
  166. package/schematics/ng-update/devkit-migration-rule.js +152 -0
  167. package/schematics/ng-update/devkit-migration.d.ts +37 -0
  168. package/schematics/ng-update/devkit-migration.js +29 -0
  169. package/schematics/ng-update/index.js +7 -7
  170. package/schematics/ng-update/{upgrade-rules/attribute-selectors-rule.d.ts → migrations/attribute-selectors.d.ts} +6 -6
  171. package/schematics/ng-update/migrations/attribute-selectors.js +76 -0
  172. package/schematics/ng-update/{upgrade-rules/class-inheritance-rule.d.ts → migrations/class-inheritance.d.ts} +6 -6
  173. package/schematics/ng-update/migrations/class-inheritance.js +67 -0
  174. package/schematics/ng-update/{upgrade-rules/class-names-rule.d.ts → migrations/class-names.d.ts} +6 -6
  175. package/schematics/ng-update/migrations/class-names.js +98 -0
  176. package/schematics/ng-update/{upgrade-rules/constructor-signature-rule.d.ts → migrations/constructor-signature.d.ts} +6 -6
  177. package/schematics/ng-update/migrations/constructor-signature.js +144 -0
  178. package/schematics/ng-update/{upgrade-rules/css-selectors-rule.d.ts → migrations/css-selectors.d.ts} +6 -6
  179. package/schematics/ng-update/migrations/css-selectors.js +83 -0
  180. package/schematics/ng-update/{upgrade-rules/element-selectors-rule.d.ts → migrations/element-selectors.d.ts} +6 -6
  181. package/schematics/ng-update/migrations/element-selectors.js +74 -0
  182. package/schematics/ng-update/{upgrade-rules/input-names-rule.d.ts → migrations/input-names.d.ts} +6 -6
  183. package/schematics/ng-update/migrations/input-names.js +69 -0
  184. package/schematics/ng-update/{upgrade-rules/method-call-arguments-rule.d.ts → migrations/method-call-arguments.d.ts} +6 -6
  185. package/schematics/ng-update/migrations/method-call-arguments.js +70 -0
  186. package/schematics/ng-update/{upgrade-rules/misc-template-rule.d.ts → migrations/misc-template.d.ts} +6 -6
  187. package/schematics/ng-update/migrations/misc-template.js +47 -0
  188. package/schematics/ng-update/{upgrade-rules/output-names-rule.d.ts → migrations/output-names.d.ts} +6 -6
  189. package/schematics/ng-update/migrations/output-names.js +56 -0
  190. package/schematics/ng-update/{upgrade-rules/property-names-rule.d.ts → migrations/property-names.d.ts} +6 -6
  191. package/schematics/ng-update/migrations/property-names.js +56 -0
  192. package/schematics/ng-update/public-api.d.ts +3 -2
  193. package/schematics/ng-update/public-api.js +5 -4
  194. package/schematics/ng-update/upgrade-data.d.ts +7 -8
  195. package/schematics/ng-update/upgrade-data.js +6 -7
  196. package/schematics/update-tool/component-resource-collector.d.ts +3 -1
  197. package/schematics/update-tool/component-resource-collector.js +8 -8
  198. package/schematics/update-tool/file-system.d.ts +38 -0
  199. package/schematics/update-tool/file-system.js +20 -0
  200. package/schematics/update-tool/index.d.ts +41 -11
  201. package/schematics/update-tool/index.js +135 -106
  202. package/schematics/update-tool/logger.d.ts +16 -0
  203. package/schematics/update-tool/logger.js +27 -0
  204. package/schematics/update-tool/{migration-rule.d.ts → migration.d.ts} +23 -45
  205. package/schematics/update-tool/migration.js +76 -0
  206. package/schematics/update-tool/public-api.d.ts +5 -4
  207. package/schematics/update-tool/public-api.js +6 -6
  208. package/schematics/update-tool/update-recorder.d.ts +14 -0
  209. package/schematics/update-tool/update-recorder.js +20 -0
  210. package/schematics/update-tool/utils/parse-tsconfig.js +1 -1
  211. package/schematics/update-tool/version-changes.js +3 -4
  212. package/schematics/utils/ast/ng-module-imports.js +3 -2
  213. package/scrolling/index.metadata.json +1 -1
  214. package/scrolling/scrolling-module.d.ts +2 -0
  215. package/table/cell.d.ts +2 -0
  216. package/table/index.metadata.json +1 -1
  217. package/table/public-api.d.ts +1 -0
  218. package/table/row.d.ts +6 -3
  219. package/table/table.d.ts +2 -0
  220. package/table/text-column.d.ts +2 -13
  221. package/table/tokens.d.ts +25 -0
  222. package/testing/protractor/protractor-harness-environment.d.ts +10 -3
  223. package/testing/testbed/fake-events/dispatch-events.d.ts +8 -3
  224. package/testing/testbed/fake-events/event-objects.d.ts +12 -1
  225. package/testing/testbed/testbed-harness-environment.d.ts +12 -4
  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 -96
  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/fesm5/a11y.js CHANGED
@@ -5,7 +5,7 @@ import { Subject, Subscription, of } from 'rxjs';
5
5
  import { hasModifierKey, A, Z, ZERO, NINE, LEFT_ARROW, RIGHT_ARROW, UP_ARROW, DOWN_ARROW, TAB } from '@angular/cdk/keycodes';
6
6
  import { tap, debounceTime, filter, map, take } from 'rxjs/operators';
7
7
  import { coerceBooleanProperty, coerceElement } from '@angular/cdk/coercion';
8
- import { Platform, normalizePassiveListenerOptions, PlatformModule } from '@angular/cdk/platform';
8
+ import { Platform, normalizePassiveListenerOptions, _getShadowRoot, PlatformModule } from '@angular/cdk/platform';
9
9
  import { ContentObserver, ObserversModule } from '@angular/cdk/observers';
10
10
 
11
11
  /**
@@ -15,8 +15,8 @@ import { ContentObserver, ObserversModule } from '@angular/cdk/observers';
15
15
  * Use of this source code is governed by an MIT-style license that can be
16
16
  * found in the LICENSE file at https://angular.io/license
17
17
  */
18
- /** IDs are deliminated by an empty space, as per the spec. */
19
- var ID_DELIMINATOR = ' ';
18
+ /** IDs are delimited by an empty space, as per the spec. */
19
+ var ID_DELIMITER = ' ';
20
20
  /**
21
21
  * Adds the given ID to the specified ARIA attribute on an element.
22
22
  * Used for attributes such as aria-labelledby, aria-owns, etc.
@@ -27,7 +27,7 @@ function addAriaReferencedId(el, attr, id) {
27
27
  return;
28
28
  }
29
29
  ids.push(id.trim());
30
- el.setAttribute(attr, ids.join(ID_DELIMINATOR));
30
+ el.setAttribute(attr, ids.join(ID_DELIMITER));
31
31
  }
32
32
  /**
33
33
  * Removes the given ID from the specified ARIA attribute on an element.
@@ -37,7 +37,7 @@ function removeAriaReferencedId(el, attr, id) {
37
37
  var ids = getAriaReferenceIds(el, attr);
38
38
  var filteredIds = ids.filter(function (val) { return val != id.trim(); });
39
39
  if (filteredIds.length) {
40
- el.setAttribute(attr, filteredIds.join(ID_DELIMINATOR));
40
+ el.setAttribute(attr, filteredIds.join(ID_DELIMITER));
41
41
  }
42
42
  else {
43
43
  el.removeAttribute(attr);
@@ -48,7 +48,7 @@ function removeAriaReferencedId(el, attr, id) {
48
48
  * Used for attributes such as aria-labelledby, aria-owns, etc.
49
49
  */
50
50
  function getAriaReferenceIds(el, attr) {
51
- // Get string array of all individual ids (whitespace deliminated) in the attribute value
51
+ // Get string array of all individual ids (whitespace delimited) in the attribute value
52
52
  return (el.getAttribute(attr) || '').match(/\S+/g) || [];
53
53
  }
54
54
 
@@ -1688,6 +1688,24 @@ var CdkAriaLive = /** @class */ (function () {
1688
1688
  return CdkAriaLive;
1689
1689
  }());
1690
1690
 
1691
+ /**
1692
+ * @license
1693
+ * Copyright Google LLC All Rights Reserved.
1694
+ *
1695
+ * Use of this source code is governed by an MIT-style license that can be
1696
+ * found in the LICENSE file at https://angular.io/license
1697
+ */
1698
+ /**
1699
+ * Screenreaders will often fire fake mousedown events when a focusable element
1700
+ * is activated using the keyboard. We can typically distinguish between these faked
1701
+ * mousedown events and real mousedown events using the "buttons" property. While
1702
+ * real mousedowns will indicate the mouse button that was pressed (e.g. "1" for
1703
+ * the left mouse button), faked mousedowns will usually set the property value to 0.
1704
+ */
1705
+ function isFakeMousedownFromScreenReader(event) {
1706
+ return event.buttons === 0;
1707
+ }
1708
+
1691
1709
  /**
1692
1710
  * @license
1693
1711
  * Copyright Google LLC All Rights Reserved.
@@ -1698,6 +1716,8 @@ var CdkAriaLive = /** @class */ (function () {
1698
1716
  // This is the value used by AngularJS Material. Through trial and error (on iPhone 6S) they found
1699
1717
  // that a value of around 650ms seems appropriate.
1700
1718
  var TOUCH_BUFFER_MS = 650;
1719
+ /** InjectionToken for FocusMonitorOptions. */
1720
+ var FOCUS_MONITOR_DEFAULT_OPTIONS = new InjectionToken('cdk-focus-monitor-default-options');
1701
1721
  /**
1702
1722
  * Event listener options that enable capturing and also
1703
1723
  * mark the listener as passive if the browser supports it.
@@ -1710,7 +1730,7 @@ var captureEventListenerOptions = normalizePassiveListenerOptions({
1710
1730
  var FocusMonitor = /** @class */ (function () {
1711
1731
  function FocusMonitor(_ngZone, _platform,
1712
1732
  /** @breaking-change 11.0.0 make document required */
1713
- document) {
1733
+ document, options) {
1714
1734
  var _this = this;
1715
1735
  this._ngZone = _ngZone;
1716
1736
  this._platform = _platform;
@@ -1722,6 +1742,13 @@ var FocusMonitor = /** @class */ (function () {
1722
1742
  this._elementInfo = new Map();
1723
1743
  /** The number of elements currently being monitored. */
1724
1744
  this._monitoredElementCount = 0;
1745
+ /**
1746
+ * Keeps track of the root nodes to which we've currently bound a focus/blur handler,
1747
+ * as well as the number of monitored elements that they contain. We have to treat focus/blur
1748
+ * handlers differently from the rest of the events, because the browser won't emit events
1749
+ * to the document when focus moves inside of a shadow root.
1750
+ */
1751
+ this._rootNodeFocusListenerCount = new Map();
1725
1752
  /**
1726
1753
  * Event listener for `keydown` events on the document.
1727
1754
  * Needs to be an arrow function in order to preserve the context when it gets bound.
@@ -1735,11 +1762,14 @@ var FocusMonitor = /** @class */ (function () {
1735
1762
  * Event listener for `mousedown` events on the document.
1736
1763
  * Needs to be an arrow function in order to preserve the context when it gets bound.
1737
1764
  */
1738
- this._documentMousedownListener = function () {
1765
+ this._documentMousedownListener = function (event) {
1739
1766
  // On mousedown record the origin only if there is not touch
1740
1767
  // target, since a mousedown can happen as a result of a touch event.
1741
1768
  if (!_this._lastTouchTarget) {
1742
- _this._setOriginForCurrentEventQueue('mouse');
1769
+ // In some cases screen readers fire fake `mousedown` events instead of `keydown`.
1770
+ // Resolve the focus source to `keyboard` if we detect one of them.
1771
+ var source = isFakeMousedownFromScreenReader(event) ? 'keyboard' : 'mouse';
1772
+ _this._setOriginForCurrentEventQueue(source);
1743
1773
  }
1744
1774
  };
1745
1775
  /**
@@ -1753,10 +1783,7 @@ var FocusMonitor = /** @class */ (function () {
1753
1783
  if (_this._touchTimeoutId != null) {
1754
1784
  clearTimeout(_this._touchTimeoutId);
1755
1785
  }
1756
- // Since this listener is bound on the `document` level, any events coming from the shadow DOM
1757
- // will have their `target` set to the shadow root. If available, use `composedPath` to
1758
- // figure out the event target.
1759
- _this._lastTouchTarget = event.composedPath ? event.composedPath()[0] : event.target;
1786
+ _this._lastTouchTarget = getTarget(event);
1760
1787
  _this._touchTimeoutId = setTimeout(function () { return _this._lastTouchTarget = null; }, TOUCH_BUFFER_MS);
1761
1788
  };
1762
1789
  /**
@@ -1769,16 +1796,32 @@ var FocusMonitor = /** @class */ (function () {
1769
1796
  _this._windowFocused = true;
1770
1797
  _this._windowFocusTimeoutId = setTimeout(function () { return _this._windowFocused = false; });
1771
1798
  };
1799
+ /**
1800
+ * Event listener for `focus` and 'blur' events on the document.
1801
+ * Needs to be an arrow function in order to preserve the context when it gets bound.
1802
+ */
1803
+ this._rootNodeFocusAndBlurListener = function (event) {
1804
+ var target = getTarget(event);
1805
+ var handler = event.type === 'focus' ? _this._onFocus : _this._onBlur;
1806
+ // We need to walk up the ancestor chain in order to support `checkChildren`.
1807
+ for (var element = target; element; element = element.parentElement) {
1808
+ handler.call(_this, event, element);
1809
+ }
1810
+ };
1772
1811
  this._document = document;
1812
+ this._detectionMode = (options === null || options === void 0 ? void 0 : options.detectionMode) || 0 /* IMMEDIATE */;
1773
1813
  }
1774
1814
  FocusMonitor.prototype.monitor = function (element, checkChildren) {
1775
- var _this = this;
1776
1815
  if (checkChildren === void 0) { checkChildren = false; }
1777
1816
  // Do nothing if we're not on the browser platform.
1778
1817
  if (!this._platform.isBrowser) {
1779
1818
  return of(null);
1780
1819
  }
1781
1820
  var nativeElement = coerceElement(element);
1821
+ // If the element is inside the shadow DOM, we need to bind our focus/blur listeners to
1822
+ // the shadow root, rather than the `document`, because the browser won't emit focus events
1823
+ // to the `document`, if focus is moving within the same shadow root.
1824
+ var rootNode = _getShadowRoot(nativeElement) || this._getDocument();
1782
1825
  // Check if we're already monitoring this element.
1783
1826
  if (this._elementInfo.has(nativeElement)) {
1784
1827
  var cachedInfo = this._elementInfo.get(nativeElement);
@@ -1787,35 +1830,22 @@ var FocusMonitor = /** @class */ (function () {
1787
1830
  }
1788
1831
  // Create monitored element info.
1789
1832
  var info = {
1790
- unlisten: function () { },
1791
1833
  checkChildren: checkChildren,
1792
- subject: new Subject()
1834
+ subject: new Subject(),
1835
+ rootNode: rootNode
1793
1836
  };
1794
1837
  this._elementInfo.set(nativeElement, info);
1795
- this._incrementMonitoredElementCount();
1796
- // Start listening. We need to listen in capture phase since focus events don't bubble.
1797
- var focusListener = function (event) { return _this._onFocus(event, nativeElement); };
1798
- var blurListener = function (event) { return _this._onBlur(event, nativeElement); };
1799
- this._ngZone.runOutsideAngular(function () {
1800
- nativeElement.addEventListener('focus', focusListener, true);
1801
- nativeElement.addEventListener('blur', blurListener, true);
1802
- });
1803
- // Create an unlisten function for later.
1804
- info.unlisten = function () {
1805
- nativeElement.removeEventListener('focus', focusListener, true);
1806
- nativeElement.removeEventListener('blur', blurListener, true);
1807
- };
1838
+ this._registerGlobalListeners(info);
1808
1839
  return info.subject.asObservable();
1809
1840
  };
1810
1841
  FocusMonitor.prototype.stopMonitoring = function (element) {
1811
1842
  var nativeElement = coerceElement(element);
1812
1843
  var elementInfo = this._elementInfo.get(nativeElement);
1813
1844
  if (elementInfo) {
1814
- elementInfo.unlisten();
1815
1845
  elementInfo.subject.complete();
1816
1846
  this._setClasses(nativeElement);
1817
1847
  this._elementInfo.delete(nativeElement);
1818
- this._decrementMonitoredElementCount();
1848
+ this._removeGlobalListeners(elementInfo);
1819
1849
  }
1820
1850
  };
1821
1851
  FocusMonitor.prototype.focusVia = function (element, origin, options) {
@@ -1848,33 +1878,53 @@ var FocusMonitor = /** @class */ (function () {
1848
1878
  element.classList.remove(className);
1849
1879
  }
1850
1880
  };
1881
+ FocusMonitor.prototype._getFocusOrigin = function (event) {
1882
+ // If we couldn't detect a cause for the focus event, it's due to one of three reasons:
1883
+ // 1) The window has just regained focus, in which case we want to restore the focused state of
1884
+ // the element from before the window blurred.
1885
+ // 2) It was caused by a touch event, in which case we mark the origin as 'touch'.
1886
+ // 3) The element was programmatically focused, in which case we should mark the origin as
1887
+ // 'program'.
1888
+ if (this._origin) {
1889
+ return this._origin;
1890
+ }
1891
+ if (this._windowFocused && this._lastFocusOrigin) {
1892
+ return this._lastFocusOrigin;
1893
+ }
1894
+ else if (this._wasCausedByTouch(event)) {
1895
+ return 'touch';
1896
+ }
1897
+ else {
1898
+ return 'program';
1899
+ }
1900
+ };
1851
1901
  /**
1852
1902
  * Sets the focus classes on the element based on the given focus origin.
1853
1903
  * @param element The element to update the classes on.
1854
1904
  * @param origin The focus origin.
1855
1905
  */
1856
1906
  FocusMonitor.prototype._setClasses = function (element, origin) {
1857
- var elementInfo = this._elementInfo.get(element);
1858
- if (elementInfo) {
1859
- this._toggleClass(element, 'cdk-focused', !!origin);
1860
- this._toggleClass(element, 'cdk-touch-focused', origin === 'touch');
1861
- this._toggleClass(element, 'cdk-keyboard-focused', origin === 'keyboard');
1862
- this._toggleClass(element, 'cdk-mouse-focused', origin === 'mouse');
1863
- this._toggleClass(element, 'cdk-program-focused', origin === 'program');
1864
- }
1907
+ this._toggleClass(element, 'cdk-focused', !!origin);
1908
+ this._toggleClass(element, 'cdk-touch-focused', origin === 'touch');
1909
+ this._toggleClass(element, 'cdk-keyboard-focused', origin === 'keyboard');
1910
+ this._toggleClass(element, 'cdk-mouse-focused', origin === 'mouse');
1911
+ this._toggleClass(element, 'cdk-program-focused', origin === 'program');
1865
1912
  };
1866
1913
  /**
1867
1914
  * Sets the origin and schedules an async function to clear it at the end of the event queue.
1915
+ * If the detection mode is 'eventual', the origin is never cleared.
1868
1916
  * @param origin The origin to set.
1869
1917
  */
1870
1918
  FocusMonitor.prototype._setOriginForCurrentEventQueue = function (origin) {
1871
1919
  var _this = this;
1872
1920
  this._ngZone.runOutsideAngular(function () {
1873
1921
  _this._origin = origin;
1874
- // Sometimes the focus origin won't be valid in Firefox because Firefox seems to focus *one*
1875
- // tick after the interaction event fired. To ensure the focus origin is always correct,
1876
- // the focus origin will be determined at the beginning of the next tick.
1877
- _this._originTimeoutId = setTimeout(function () { return _this._origin = null; }, 1);
1922
+ if (_this._detectionMode === 0 /* IMMEDIATE */) {
1923
+ // Sometimes the focus origin won't be valid in Firefox because Firefox seems to focus *one*
1924
+ // tick after the interaction event fired. To ensure the focus origin is always correct,
1925
+ // the focus origin will be determined at the beginning of the next tick.
1926
+ _this._originTimeoutId = setTimeout(function () { return _this._origin = null; }, 1);
1927
+ }
1878
1928
  });
1879
1929
  };
1880
1930
  /**
@@ -1900,7 +1950,7 @@ var FocusMonitor = /** @class */ (function () {
1900
1950
  // for the first focus event after the touchstart, and then the first blur event after that
1901
1951
  // focus event. When that blur event fires we know that whatever follows is not a result of the
1902
1952
  // touchstart.
1903
- var focusTarget = event.target;
1953
+ var focusTarget = getTarget(event);
1904
1954
  return this._lastTouchTarget instanceof Node && focusTarget instanceof Node &&
1905
1955
  (focusTarget === this._lastTouchTarget || focusTarget.contains(this._lastTouchTarget));
1906
1956
  };
@@ -1917,27 +1967,10 @@ var FocusMonitor = /** @class */ (function () {
1917
1967
  // If we are not counting child-element-focus as focused, make sure that the event target is the
1918
1968
  // monitored element itself.
1919
1969
  var elementInfo = this._elementInfo.get(element);
1920
- if (!elementInfo || (!elementInfo.checkChildren && element !== event.target)) {
1970
+ if (!elementInfo || (!elementInfo.checkChildren && element !== getTarget(event))) {
1921
1971
  return;
1922
1972
  }
1923
- // If we couldn't detect a cause for the focus event, it's due to one of three reasons:
1924
- // 1) The window has just regained focus, in which case we want to restore the focused state of
1925
- // the element from before the window blurred.
1926
- // 2) It was caused by a touch event, in which case we mark the origin as 'touch'.
1927
- // 3) The element was programmatically focused, in which case we should mark the origin as
1928
- // 'program'.
1929
- var origin = this._origin;
1930
- if (!origin) {
1931
- if (this._windowFocused && this._lastFocusOrigin) {
1932
- origin = this._lastFocusOrigin;
1933
- }
1934
- else if (this._wasCausedByTouch(event)) {
1935
- origin = 'touch';
1936
- }
1937
- else {
1938
- origin = 'program';
1939
- }
1940
- }
1973
+ var origin = this._getFocusOrigin(event);
1941
1974
  this._setClasses(element, origin);
1942
1975
  this._emitOrigin(elementInfo.subject, origin);
1943
1976
  this._lastFocusOrigin = origin;
@@ -1961,10 +1994,22 @@ var FocusMonitor = /** @class */ (function () {
1961
1994
  FocusMonitor.prototype._emitOrigin = function (subject, origin) {
1962
1995
  this._ngZone.run(function () { return subject.next(origin); });
1963
1996
  };
1964
- FocusMonitor.prototype._incrementMonitoredElementCount = function () {
1997
+ FocusMonitor.prototype._registerGlobalListeners = function (elementInfo) {
1965
1998
  var _this = this;
1999
+ if (!this._platform.isBrowser) {
2000
+ return;
2001
+ }
2002
+ var rootNode = elementInfo.rootNode;
2003
+ var rootNodeFocusListeners = this._rootNodeFocusListenerCount.get(rootNode) || 0;
2004
+ if (!rootNodeFocusListeners) {
2005
+ this._ngZone.runOutsideAngular(function () {
2006
+ rootNode.addEventListener('focus', _this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
2007
+ rootNode.addEventListener('blur', _this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
2008
+ });
2009
+ }
2010
+ this._rootNodeFocusListenerCount.set(rootNode, rootNodeFocusListeners + 1);
1966
2011
  // Register global listeners when first element is monitored.
1967
- if (++this._monitoredElementCount == 1 && this._platform.isBrowser) {
2012
+ if (++this._monitoredElementCount === 1) {
1968
2013
  // Note: we listen to events in the capture phase so we
1969
2014
  // can detect them even if the user stops propagation.
1970
2015
  this._ngZone.runOutsideAngular(function () {
@@ -1977,7 +2022,19 @@ var FocusMonitor = /** @class */ (function () {
1977
2022
  });
1978
2023
  }
1979
2024
  };
1980
- FocusMonitor.prototype._decrementMonitoredElementCount = function () {
2025
+ FocusMonitor.prototype._removeGlobalListeners = function (elementInfo) {
2026
+ var rootNode = elementInfo.rootNode;
2027
+ if (this._rootNodeFocusListenerCount.has(rootNode)) {
2028
+ var rootNodeFocusListeners = this._rootNodeFocusListenerCount.get(rootNode);
2029
+ if (rootNodeFocusListeners > 1) {
2030
+ this._rootNodeFocusListenerCount.set(rootNode, rootNodeFocusListeners - 1);
2031
+ }
2032
+ else {
2033
+ rootNode.removeEventListener('focus', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
2034
+ rootNode.removeEventListener('blur', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
2035
+ this._rootNodeFocusListenerCount.delete(rootNode);
2036
+ }
2037
+ }
1981
2038
  // Unregister global listeners when last element is unmonitored.
1982
2039
  if (!--this._monitoredElementCount) {
1983
2040
  var document_1 = this._getDocument();
@@ -1999,11 +2056,18 @@ var FocusMonitor = /** @class */ (function () {
1999
2056
  FocusMonitor.ctorParameters = function () { return [
2000
2057
  { type: NgZone },
2001
2058
  { type: Platform },
2002
- { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }
2059
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] },
2060
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [FOCUS_MONITOR_DEFAULT_OPTIONS,] }] }
2003
2061
  ]; };
2004
- FocusMonitor.ɵprov = ɵɵdefineInjectable({ factory: function FocusMonitor_Factory() { return new FocusMonitor(ɵɵinject(NgZone), ɵɵinject(Platform), ɵɵinject(DOCUMENT, 8)); }, token: FocusMonitor, providedIn: "root" });
2062
+ FocusMonitor.ɵprov = ɵɵdefineInjectable({ factory: function FocusMonitor_Factory() { return new FocusMonitor(ɵɵinject(NgZone), ɵɵinject(Platform), ɵɵinject(DOCUMENT, 8), ɵɵinject(FOCUS_MONITOR_DEFAULT_OPTIONS, 8)); }, token: FocusMonitor, providedIn: "root" });
2005
2063
  return FocusMonitor;
2006
2064
  }());
2065
+ /** Gets the target of an event, accounting for Shadow DOM. */
2066
+ function getTarget(event) {
2067
+ // If an event is bound outside the Shadow DOM, the `event.target` will
2068
+ // point to the shadow root so we have to use `composedPath` instead.
2069
+ return (event.composedPath ? event.composedPath()[0] : event.target);
2070
+ }
2007
2071
  /**
2008
2072
  * Directive that determines how a particular element was focused (via keyboard, mouse, touch, or
2009
2073
  * programmatically) and adds corresponding classes to the element.
@@ -2042,24 +2106,6 @@ var CdkMonitorFocus = /** @class */ (function () {
2042
2106
  return CdkMonitorFocus;
2043
2107
  }());
2044
2108
 
2045
- /**
2046
- * @license
2047
- * Copyright Google LLC All Rights Reserved.
2048
- *
2049
- * Use of this source code is governed by an MIT-style license that can be
2050
- * found in the LICENSE file at https://angular.io/license
2051
- */
2052
- /**
2053
- * Screenreaders will often fire fake mousedown events when a focusable element
2054
- * is activated using the keyboard. We can typically distinguish between these faked
2055
- * mousedown events and real mousedown events using the "buttons" property. While
2056
- * real mousedowns will indicate the mouse button that was pressed (e.g. "1" for
2057
- * the left mouse button), faked mousedowns will usually set the property value to 0.
2058
- */
2059
- function isFakeMousedownFromScreenReader(event) {
2060
- return event.buttons === 0;
2061
- }
2062
-
2063
2109
  /**
2064
2110
  * @license
2065
2111
  * Copyright Google LLC All Rights Reserved.
@@ -2074,7 +2120,7 @@ var WHITE_ON_BLACK_CSS_CLASS = 'cdk-high-contrast-white-on-black';
2074
2120
  /** CSS class applied to the document body when in high-contrast mode. */
2075
2121
  var HIGH_CONTRAST_MODE_ACTIVE_CSS_CLASS = 'cdk-high-contrast-active';
2076
2122
  /**
2077
- * Service to determine whether the browser is currently in a high-constrast-mode environment.
2123
+ * Service to determine whether the browser is currently in a high-contrast-mode environment.
2078
2124
  *
2079
2125
  * Microsoft Windows supports an accessibility feature called "High Contrast Mode". This mode
2080
2126
  * changes the appearance of all applications, including web applications, to dramatically increase
@@ -2089,7 +2135,7 @@ var HighContrastModeDetector = /** @class */ (function () {
2089
2135
  this._platform = _platform;
2090
2136
  this._document = document;
2091
2137
  }
2092
- /** Gets the current high-constrast-mode for the page. */
2138
+ /** Gets the current high-contrast-mode for the page. */
2093
2139
  HighContrastModeDetector.prototype.getHighContrastMode = function () {
2094
2140
  if (!this._platform.isBrowser) {
2095
2141
  return 0 /* NONE */;
@@ -2103,9 +2149,12 @@ var HighContrastModeDetector = /** @class */ (function () {
2103
2149
  this._document.body.appendChild(testElement);
2104
2150
  // Get the computed style for the background color, collapsing spaces to normalize between
2105
2151
  // browsers. Once we get this color, we no longer need the test element. Access the `window`
2106
- // via the document so we can fake it in tests.
2107
- var documentWindow = this._document.defaultView;
2108
- var computedColor = (documentWindow.getComputedStyle(testElement).backgroundColor || '').replace(/ /g, '');
2152
+ // via the document so we can fake it in tests. Note that we have extra null checks, because
2153
+ // this logic will likely run during app bootstrap and throwing can break the entire app.
2154
+ var documentWindow = this._document.defaultView || window;
2155
+ var computedStyle = (documentWindow && documentWindow.getComputedStyle) ?
2156
+ documentWindow.getComputedStyle(testElement) : null;
2157
+ var computedColor = (computedStyle && computedStyle.backgroundColor || '').replace(/ /g, '');
2109
2158
  this._document.body.removeChild(testElement);
2110
2159
  switch (computedColor) {
2111
2160
  case 'rgb(0,0,0)': return 2 /* WHITE_ON_BLACK */;
@@ -2181,5 +2230,5 @@ var A11yModule = /** @class */ (function () {
2181
2230
  * Generated bundle index. Do not edit.
2182
2231
  */
2183
2232
 
2184
- export { A11yModule, ActiveDescendantKeyManager, AriaDescriber, CDK_DESCRIBEDBY_HOST_ATTRIBUTE, CDK_DESCRIBEDBY_ID_PREFIX, CdkAriaLive, CdkMonitorFocus, CdkTrapFocus, ConfigurableFocusTrap, ConfigurableFocusTrapFactory, EventListenerFocusTrapInertStrategy, FOCUS_TRAP_INERT_STRATEGY, FocusKeyManager, FocusMonitor, FocusTrap, FocusTrapFactory, HighContrastModeDetector, InteractivityChecker, LIVE_ANNOUNCER_DEFAULT_OPTIONS, LIVE_ANNOUNCER_ELEMENT_TOKEN, LIVE_ANNOUNCER_ELEMENT_TOKEN_FACTORY, ListKeyManager, LiveAnnouncer, MESSAGES_CONTAINER_ID, TOUCH_BUFFER_MS, isFakeMousedownFromScreenReader, FocusTrapManager as ɵangular_material_src_cdk_a11y_a11y_a, ConfigurableFocusTrapConfig as ɵangular_material_src_cdk_a11y_a11y_b };
2233
+ export { A11yModule, ActiveDescendantKeyManager, AriaDescriber, CDK_DESCRIBEDBY_HOST_ATTRIBUTE, CDK_DESCRIBEDBY_ID_PREFIX, CdkAriaLive, CdkMonitorFocus, CdkTrapFocus, ConfigurableFocusTrap, ConfigurableFocusTrapFactory, EventListenerFocusTrapInertStrategy, FOCUS_MONITOR_DEFAULT_OPTIONS, FOCUS_TRAP_INERT_STRATEGY, FocusKeyManager, FocusMonitor, FocusTrap, FocusTrapFactory, HighContrastModeDetector, InteractivityChecker, LIVE_ANNOUNCER_DEFAULT_OPTIONS, LIVE_ANNOUNCER_ELEMENT_TOKEN, LIVE_ANNOUNCER_ELEMENT_TOKEN_FACTORY, ListKeyManager, LiveAnnouncer, MESSAGES_CONTAINER_ID, TOUCH_BUFFER_MS, isFakeMousedownFromScreenReader, FocusTrapManager as ɵangular_material_src_cdk_a11y_a11y_a, ConfigurableFocusTrapConfig as ɵangular_material_src_cdk_a11y_a11y_b };
2185
2234
  //# sourceMappingURL=a11y.js.map