@energycap/components 0.47.0 → 0.47.1-ECAP-35408.20261008-0546

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.
@@ -4086,6 +4086,7 @@ var PopupContainerDirective = class PopupContainerDirective {
4086
4086
  this.hide();
4087
4087
  }
4088
4088
  show() {
4089
+ this.cancelFocusRestore();
4089
4090
  if (PopupContainerDirective.GlobalPopupRef) {
4090
4091
  if (PopupContainerDirective.GlobalPopupRef != this) {
4091
4092
  PopupContainerDirective.GlobalPopupRef.hide();
@@ -4113,11 +4114,27 @@ var PopupContainerDirective = class PopupContainerDirective {
4113
4114
  }
4114
4115
  if (this.popperRef && this.popupViewRef) {
4115
4116
  const shouldRestoreFocus = this.isFocusInsidePopup() || this.document.activeElement === this.document.body;
4117
+ const popupNodes = [...this.popupViewRef.rootNodes];
4116
4118
  this.popupViewRef.destroy();
4117
4119
  this.popperRef.destroy();
4118
4120
  this.popperRef = void 0;
4119
4121
  this.popperStatusChange.emit("hidden");
4120
- if (shouldRestoreFocus && this.previouslyFocusedElement?.focus) this.previouslyFocusedElement.focus();
4122
+ if (shouldRestoreFocus && this.previouslyFocusedElement?.focus) this.restoreFocusAfterHide(this.previouslyFocusedElement, popupNodes);
4123
+ }
4124
+ }
4125
+ restoreFocusAfterHide(target, popupNodes) {
4126
+ this.cancelFocusRestore();
4127
+ this.focusRestoreTimeout = setTimeout(() => {
4128
+ this.focusRestoreTimeout = void 0;
4129
+ const activeElement = this.document.activeElement;
4130
+ const focusIsUnclaimed = !activeElement || activeElement === this.document.body || popupNodes.some((node) => node.contains && node.contains(activeElement));
4131
+ if (target.isConnected && focusIsUnclaimed) target.focus();
4132
+ });
4133
+ }
4134
+ cancelFocusRestore() {
4135
+ if (this.focusRestoreTimeout !== void 0) {
4136
+ clearTimeout(this.focusRestoreTimeout);
4137
+ this.focusRestoreTimeout = void 0;
4121
4138
  }
4122
4139
  }
4123
4140
  isFocusInsidePopup() {