@momentum-design/components 0.83.1 → 0.83.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.
@@ -123,6 +123,17 @@ declare class Popover extends Popover_base {
123
123
  * @default false
124
124
  */
125
125
  hideOnEscape: boolean;
126
+ /**
127
+ * Propagates the event, when the escape key is pressed (only when pressed inside the popover)
128
+ * If true, the escape key press close the popover and will propagate the keydown event.
129
+ * If false, the escape key press will close the popover but will not propagate the keydown event.
130
+ * (set to false to prevent the event from bubbling up to the document).
131
+ *
132
+ * This only works when `hideOnEscape` is true.
133
+ *
134
+ * @default false
135
+ */
136
+ propagateEventOnEscape: boolean;
126
137
  /**
127
138
  * Hide popover on blur.
128
139
  * @default false
@@ -231,6 +242,8 @@ declare class Popover extends Popover_base {
231
242
  /**
232
243
  * Handles the escape keydown event to close the popover.
233
244
  *
245
+ * This method is attached to the document.
246
+ *
234
247
  * @param event - The keyboard event.
235
248
  */
236
249
  private onEscapeKeydown;
@@ -141,6 +141,17 @@ class Popover extends FocusTrapMixin(Component) {
141
141
  * @default false
142
142
  */
143
143
  this.hideOnEscape = DEFAULTS.HIDE_ON_ESCAPE;
144
+ /**
145
+ * Propagates the event, when the escape key is pressed (only when pressed inside the popover)
146
+ * If true, the escape key press close the popover and will propagate the keydown event.
147
+ * If false, the escape key press will close the popover but will not propagate the keydown event.
148
+ * (set to false to prevent the event from bubbling up to the document).
149
+ *
150
+ * This only works when `hideOnEscape` is true.
151
+ *
152
+ * @default false
153
+ */
154
+ this.propagateEventOnEscape = DEFAULTS.PROPAGATE_EVENT_ON_ESCAPE;
144
155
  /**
145
156
  * Hide popover on blur.
146
157
  * @default false
@@ -240,12 +251,18 @@ class Popover extends FocusTrapMixin(Component) {
240
251
  /**
241
252
  * Handles the escape keydown event to close the popover.
242
253
  *
254
+ * This method is attached to the document.
255
+ *
243
256
  * @param event - The keyboard event.
244
257
  */
245
258
  this.onEscapeKeydown = (event) => {
246
259
  if (!this.visible || event.code !== 'Escape') {
247
260
  return;
248
261
  }
262
+ if (!this.propagateEventOnEscape) {
263
+ // If propagateEventOnEscape is false, we don't want to allow the event to bubble up
264
+ event.stopPropagation();
265
+ }
249
266
  event.preventDefault();
250
267
  this.hidePopover();
251
268
  };
@@ -446,7 +463,7 @@ class Popover extends FocusTrapMixin(Component) {
446
463
  * @param newValue - The new value of the visible property.
447
464
  */
448
465
  async isOpenUpdated(oldValue, newValue) {
449
- var _a, _b, _c;
466
+ var _a, _b, _c, _d, _e;
450
467
  if (oldValue === newValue || !this.triggerElement) {
451
468
  return;
452
469
  }
@@ -471,7 +488,8 @@ class Popover extends FocusTrapMixin(Component) {
471
488
  document.addEventListener('click', this.onOutsidePopoverClick);
472
489
  }
473
490
  if (this.hideOnEscape) {
474
- document.addEventListener('keydown', this.onEscapeKeydown);
491
+ this.addEventListener('keydown', this.onEscapeKeydown);
492
+ (_a = this.triggerElement) === null || _a === void 0 ? void 0 : _a.addEventListener('keydown', this.onEscapeKeydown);
475
493
  }
476
494
  PopoverEventManager.onShowPopover(this);
477
495
  }
@@ -480,7 +498,7 @@ class Popover extends FocusTrapMixin(Component) {
480
498
  popoverStack.pop();
481
499
  }
482
500
  if (this.backdropElement) {
483
- (_a = this.backdropElement) === null || _a === void 0 ? void 0 : _a.remove();
501
+ (_b = this.backdropElement) === null || _b === void 0 ? void 0 : _b.remove();
484
502
  this.backdropElement = null;
485
503
  }
486
504
  if (this.hideOnBlur) {
@@ -493,9 +511,10 @@ class Popover extends FocusTrapMixin(Component) {
493
511
  document.removeEventListener('click', this.onOutsidePopoverClick);
494
512
  }
495
513
  if (this.hideOnEscape) {
496
- document.removeEventListener('keydown', this.onEscapeKeydown);
514
+ this.removeEventListener('keydown', this.onEscapeKeydown);
515
+ (_c = this.triggerElement) === null || _c === void 0 ? void 0 : _c.removeEventListener('keydown', this.onEscapeKeydown);
497
516
  }
498
- (_b = this.deactivateFocusTrap) === null || _b === void 0 ? void 0 : _b.call(this);
517
+ (_d = this.deactivateFocusTrap) === null || _d === void 0 ? void 0 : _d.call(this);
499
518
  if (!this.disableAriaExpanded) {
500
519
  this.triggerElement.removeAttribute('aria-expanded');
501
520
  }
@@ -504,7 +523,7 @@ class Popover extends FocusTrapMixin(Component) {
504
523
  this.triggerElement.removeAttribute('aria-haspopup');
505
524
  }
506
525
  if (this.focusBackToTrigger) {
507
- (_c = this.triggerElement) === null || _c === void 0 ? void 0 : _c.focus();
526
+ (_e = this.triggerElement) === null || _e === void 0 ? void 0 : _e.focus();
508
527
  }
509
528
  PopoverEventManager.onHidePopover(this);
510
529
  }
@@ -651,6 +670,10 @@ __decorate([
651
670
  property({ type: Boolean, reflect: true, attribute: 'hide-on-escape' }),
652
671
  __metadata("design:type", Boolean)
653
672
  ], Popover.prototype, "hideOnEscape", void 0);
673
+ __decorate([
674
+ property({ type: Boolean, reflect: true, attribute: 'propagate-event-on-escape' }),
675
+ __metadata("design:type", Boolean)
676
+ ], Popover.prototype, "propagateEventOnEscape", void 0);
654
677
  __decorate([
655
678
  property({ type: Boolean, reflect: true, attribute: 'hide-on-blur' }),
656
679
  __metadata("design:type", Boolean)
@@ -46,5 +46,6 @@ declare const DEFAULTS: {
46
46
  readonly Z_INDEX: 1000;
47
47
  readonly DISABLE_ARIA_EXPANDED: false;
48
48
  readonly DISABLE_ARIA_HAS_POPUP: false;
49
+ readonly PROPAGATE_EVENT_ON_ESCAPE: false;
49
50
  };
50
51
  export { TAG_NAME, POPOVER_PLACEMENT, COLOR, TRIGGER, DEFAULTS };
@@ -47,5 +47,6 @@ const DEFAULTS = {
47
47
  Z_INDEX: 1000,
48
48
  DISABLE_ARIA_EXPANDED: false,
49
49
  DISABLE_ARIA_HAS_POPUP: false,
50
+ PROPAGATE_EVENT_ON_ESCAPE: false,
50
51
  };
51
52
  export { TAG_NAME, POPOVER_PLACEMENT, COLOR, TRIGGER, DEFAULTS };