@angular/cdk 12.2.7 → 12.2.11

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.
@@ -941,9 +941,24 @@
941
941
  var _this = _super.call(this, document) || this;
942
942
  _this._platform = _platform;
943
943
  _this._cursorStyleIsSet = false;
944
+ /** Store pointerdown event target to track origin of click. */
945
+ _this._pointerDownListener = function (event) {
946
+ _this._pointerDownEventTarget = i2._getEventTarget(event);
947
+ };
944
948
  /** Click event listener that will be attached to the body propagate phase. */
945
949
  _this._clickListener = function (event) {
946
950
  var target = i2._getEventTarget(event);
951
+ // In case of a click event, we want to check the origin of the click
952
+ // (e.g. in case where a user starts a click inside the overlay and
953
+ // releases the click outside of it).
954
+ // This is done by using the event target of the preceding pointerdown event.
955
+ // Every click event caused by a pointer device has a preceding pointerdown
956
+ // event, unless the click was programmatically triggered (e.g. in a unit test).
957
+ var origin = event.type === 'click' && _this._pointerDownEventTarget
958
+ ? _this._pointerDownEventTarget : target;
959
+ // Reset the stored pointerdown event target, to avoid having it interfere
960
+ // in subsequent events.
961
+ _this._pointerDownEventTarget = null;
947
962
  // We copy the array because the original may be modified asynchronously if the
948
963
  // outsidePointerEvents listener decides to detach overlays resulting in index errors inside
949
964
  // the for loop.
@@ -958,8 +973,10 @@
958
973
  continue;
959
974
  }
960
975
  // If it's a click inside the overlay, just break - we should do nothing
961
- // If it's an outside click dispatch the mouse event, and proceed with the next overlay
962
- if (overlayRef.overlayElement.contains(target)) {
976
+ // If it's an outside click (both origin and target of the click) dispatch the mouse event,
977
+ // and proceed with the next overlay
978
+ if (overlayRef.overlayElement.contains(target) ||
979
+ overlayRef.overlayElement.contains(origin)) {
963
980
  break;
964
981
  }
965
982
  overlayRef._outsidePointerEvents.next(event);
@@ -978,6 +995,7 @@
978
995
  // https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html
979
996
  if (!this._isAttached) {
980
997
  var body = this._document.body;
998
+ body.addEventListener('pointerdown', this._pointerDownListener, true);
981
999
  body.addEventListener('click', this._clickListener, true);
982
1000
  body.addEventListener('auxclick', this._clickListener, true);
983
1001
  body.addEventListener('contextmenu', this._clickListener, true);
@@ -995,6 +1013,7 @@
995
1013
  OverlayOutsideClickDispatcher.prototype.detach = function () {
996
1014
  if (this._isAttached) {
997
1015
  var body = this._document.body;
1016
+ body.removeEventListener('pointerdown', this._pointerDownListener, true);
998
1017
  body.removeEventListener('click', this._clickListener, true);
999
1018
  body.removeEventListener('auxclick', this._clickListener, true);
1000
1019
  body.removeEventListener('contextmenu', this._clickListener, true);