@vaadin/overlay 24.0.0-alpha12 → 24.0.0-alpha13

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/overlay",
3
- "version": "24.0.0-alpha12",
3
+ "version": "24.0.0-alpha13",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,16 +36,16 @@
36
36
  "dependencies": {
37
37
  "@open-wc/dedupe-mixin": "^1.3.0",
38
38
  "@polymer/polymer": "^3.0.0",
39
- "@vaadin/component-base": "24.0.0-alpha12",
40
- "@vaadin/vaadin-lumo-styles": "24.0.0-alpha12",
41
- "@vaadin/vaadin-material-styles": "24.0.0-alpha12",
42
- "@vaadin/vaadin-themable-mixin": "24.0.0-alpha12"
39
+ "@vaadin/component-base": "24.0.0-alpha13",
40
+ "@vaadin/vaadin-lumo-styles": "24.0.0-alpha13",
41
+ "@vaadin/vaadin-material-styles": "24.0.0-alpha13",
42
+ "@vaadin/vaadin-themable-mixin": "24.0.0-alpha13"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@esm-bundle/chai": "^4.3.4",
46
- "@vaadin/testing-helpers": "^0.3.2",
46
+ "@vaadin/testing-helpers": "^0.4.0",
47
47
  "lit": "^2.0.0",
48
48
  "sinon": "^13.0.2"
49
49
  },
50
- "gitHead": "7e29eee4d522fb7b03ac8e7e385e9057d71c79ce"
50
+ "gitHead": "a423ad309c12b4e4f847737ee9f491f83ea60ff0"
51
51
  }
@@ -20,25 +20,31 @@ export type OverlayOpenedChangedEvent = CustomEvent<{ value: boolean }>;
20
20
  export type OverlayOpenEvent = CustomEvent;
21
21
 
22
22
  /**
23
- * Fired before the overlay will be closed.
24
- * If canceled the closing of the overlay is canceled as well.
23
+ * Fired when the opened overlay is about to be closed.
24
+ * Calling `preventDefault()` on the event cancels the closing.
25
25
  */
26
26
  export type OverlayCloseEvent = CustomEvent;
27
27
 
28
28
  /**
29
- * Fired when the overlay will be closed.
29
+ * Fired after the overlay is closed.
30
+ */
31
+ export type OverlayClosedEvent = CustomEvent;
32
+
33
+ /**
34
+ * Fired when the overlay starts to close.
35
+ * Closing the overlay can be asynchronous depending on the animation.
30
36
  */
31
37
  export type OverlayClosingEvent = CustomEvent;
32
38
 
33
39
  /**
34
- * Fired before the overlay will be closed on outside click.
35
- * If canceled the closing of the overlay is canceled as well.
40
+ * Fired before the overlay is closed on outside click.
41
+ * Calling `preventDefault()` on the event cancels the closing.
36
42
  */
37
43
  export type OverlayOutsideClickEvent = CustomEvent<{ sourceEvent: MouseEvent }>;
38
44
 
39
45
  /**
40
- * Fired before the overlay will be closed on ESC button press.
41
- * If canceled the closing of the overlay is canceled as well.
46
+ * Fired before the overlay is closed on Escape key press.
47
+ * Calling `preventDefault()` on the event cancels the closing.
42
48
  */
43
49
  export type OverlayEscapePressEvent = CustomEvent<{ sourceEvent: KeyboardEvent }>;
44
50
 
@@ -46,6 +52,7 @@ export interface OverlayCustomEventMap {
46
52
  'opened-changed': OverlayOpenedChangedEvent;
47
53
  'vaadin-overlay-open': OverlayOpenEvent;
48
54
  'vaadin-overlay-close': OverlayCloseEvent;
55
+ 'vaadin-overlay-closed': OverlayClosedEvent;
49
56
  'vaadin-overlay-closing': OverlayClosingEvent;
50
57
  'vaadin-overlay-outside-click': OverlayOutsideClickEvent;
51
58
  'vaadin-overlay-escape-press': OverlayEscapePressEvent;
@@ -106,10 +113,11 @@ export type OverlayEventMap = HTMLElementEventMap & OverlayCustomEventMap;
106
113
  *
107
114
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
108
115
  * @fires {CustomEvent} vaadin-overlay-open - Fired after the overlay is opened.
109
- * @fires {CustomEvent} vaadin-overlay-close - Fired before the overlay will be closed. If canceled the closing of the overlay is canceled as well.
110
- * @fires {CustomEvent} vaadin-overlay-closing - Fired when the overlay will be closed.
111
- * @fires {CustomEvent} vaadin-overlay-outside-click - Fired before the overlay will be closed on outside click. If canceled the closing of the overlay is canceled as well.
112
- * @fires {CustomEvent} vaadin-overlay-escape-press - Fired before the overlay will be closed on ESC button press. If canceled the closing of the overlay is canceled as well.
116
+ * @fires {CustomEvent} vaadin-overlay-close - Fired when the opened overlay is about to be closed. Calling `preventDefault()` on the event cancels the closing.
117
+ * @fires {CustomEvent} vaadin-overlay-closing - Fired when the overlay starts to close. Closing the overlay can be asynchronous depending on the animation.
118
+ * @fires {CustomEvent} vaadin-overlay-closed - Fired after the overlay is closed.
119
+ * @fires {CustomEvent} vaadin-overlay-outside-click - Fired before the overlay is closed on outside click. Calling `preventDefault()` on the event cancels the closing.
120
+ * @fires {CustomEvent} vaadin-overlay-escape-press - Fired before the overlay is closed on Escape key press. Calling `preventDefault()` on the event cancels the closing.
113
121
  */
114
122
  declare class Overlay extends ThemableMixin(DirMixin(ControllerMixin(HTMLElement))) {
115
123
  /**
@@ -171,6 +179,11 @@ declare class Overlay extends ThemableMixin(DirMixin(ControllerMixin(HTMLElement
171
179
  */
172
180
  restoreFocusNode?: HTMLElement;
173
181
 
182
+ /**
183
+ * Returns true if this is the last one in the opened overlays stack.
184
+ */
185
+ protected readonly _last: boolean;
186
+
174
187
  close(sourceEvent?: Event | null): void;
175
188
 
176
189
  /**
@@ -197,6 +210,14 @@ declare class Overlay extends ThemableMixin(DirMixin(ControllerMixin(HTMLElement
197
210
  listener: (this: Overlay, ev: OverlayEventMap[K]) => void,
198
211
  options?: EventListenerOptions | boolean,
199
212
  ): void;
213
+
214
+ protected _flushAnimation(type: 'closing' | 'opening'): void;
215
+
216
+ /**
217
+ * Whether to close the overlay on outside click or not.
218
+ * Override this method to customize the closing logic.
219
+ */
220
+ protected _shouldCloseOnOutsideClick(event: Event): boolean;
200
221
  }
201
222
 
202
223
  declare global {
@@ -65,10 +65,11 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
65
65
  *
66
66
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
67
67
  * @fires {CustomEvent} vaadin-overlay-open - Fired after the overlay is opened.
68
- * @fires {CustomEvent} vaadin-overlay-close - Fired before the overlay will be closed. If canceled the closing of the overlay is canceled as well.
69
- * @fires {CustomEvent} vaadin-overlay-closing - Fired when the overlay will be closed.
70
- * @fires {CustomEvent} vaadin-overlay-outside-click - Fired before the overlay will be closed on outside click. If canceled the closing of the overlay is canceled as well.
71
- * @fires {CustomEvent} vaadin-overlay-escape-press - Fired before the overlay will be closed on ESC button press. If canceled the closing of the overlay is canceled as well.
68
+ * @fires {CustomEvent} vaadin-overlay-close - Fired when the opened overlay is about to be closed. Calling `preventDefault()` on the event cancels the closing.
69
+ * @fires {CustomEvent} vaadin-overlay-closing - Fired when the overlay starts to close. Closing the overlay can be asynchronous depending on the animation.
70
+ * @fires {CustomEvent} vaadin-overlay-closed - Fired after the overlay is closed.
71
+ * @fires {CustomEvent} vaadin-overlay-outside-click - Fired before the overlay is closed on outside click. Calling `preventDefault()` on the event cancels the closing.
72
+ * @fires {CustomEvent} vaadin-overlay-escape-press - Fired before the overlay is closed on Escape key press. Calling `preventDefault()` on the event cancels the closing.
72
73
  *
73
74
  * @extends HTMLElement
74
75
  * @mixes ThemableMixin
@@ -352,8 +353,6 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
352
353
 
353
354
  /**
354
355
  * @param {Event=} sourceEvent
355
- * @event vaadin-overlay-close
356
- * fired before the `vaadin-overlay` will be closed. If canceled the closing of the overlay is canceled as well.
357
356
  */
358
357
  close(sourceEvent) {
359
358
  const evt = new CustomEvent('vaadin-overlay-close', {
@@ -411,12 +410,21 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
411
410
  }
412
411
 
413
412
  /**
414
- * We need to listen on 'click' / 'tap' event and capture it and close the overlay before
415
- * propagating the event to the listener in the button. Otherwise, if the clicked button would call
416
- * open(), this would happen: https://www.youtube.com/watch?v=Z86V_ICUCD4
413
+ * Whether to close the overlay on outside click or not.
414
+ * Override this method to customize the closing logic.
417
415
  *
418
- * @event vaadin-overlay-outside-click
419
- * fired before the `vaadin-overlay` will be closed on outside click. If canceled the closing of the overlay is canceled as well.
416
+ * @param {Event} _event
417
+ * @return {boolean}
418
+ * @protected
419
+ */
420
+ _shouldCloseOnOutsideClick(_event) {
421
+ return this._last;
422
+ }
423
+
424
+ /**
425
+ * Outside click listener used in capture phase to close the overlay before
426
+ * propagating the event to the listener on the element that triggered it.
427
+ * Otherwise, calling `open()` would result in closing and re-opening.
420
428
  *
421
429
  * @private
422
430
  */
@@ -426,7 +434,8 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
426
434
  this._mouseUpInside = false;
427
435
  return;
428
436
  }
429
- if (!this._last) {
437
+
438
+ if (!this._shouldCloseOnOutsideClick(event)) {
430
439
  return;
431
440
  }
432
441
 
@@ -443,9 +452,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
443
452
  }
444
453
 
445
454
  /**
446
- * @event vaadin-overlay-escape-press
447
- * fired before the `vaadin-overlay` will be closed on ESC button press. If canceled the closing of the overlay is canceled as well.
448
- *
455
+ * Listener used to close whe overlay on Escape press, if it is the last one.
449
456
  * @private
450
457
  */
451
458
  _keydownListener(event) {
@@ -472,12 +479,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
472
479
  }
473
480
  }
474
481
 
475
- /**
476
- * @event vaadin-overlay-open
477
- * fired after the `vaadin-overlay` is opened.
478
- *
479
- * @private
480
- */
482
+ /** @private */
481
483
  _openedChanged(opened, wasOpened) {
482
484
  if (opened) {
483
485
  // Store focused node.
@@ -522,18 +524,19 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
522
524
 
523
525
  /**
524
526
  * @return {boolean}
525
- * @protected
527
+ * @private
526
528
  */
527
529
  _shouldAnimate() {
528
- const name = getComputedStyle(this).getPropertyValue('animation-name');
529
- const hidden = getComputedStyle(this).getPropertyValue('display') === 'none';
530
+ const style = getComputedStyle(this);
531
+ const name = style.getPropertyValue('animation-name');
532
+ const hidden = style.getPropertyValue('display') === 'none';
530
533
  return !hidden && name && name !== 'none';
531
534
  }
532
535
 
533
536
  /**
534
537
  * @param {string} type
535
538
  * @param {Function} callback
536
- * @protected
539
+ * @private
537
540
  */
538
541
  _enqueueAnimation(type, callback) {
539
542
  const handler = `__${type}Handler`;
@@ -560,7 +563,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
560
563
  }
561
564
  }
562
565
 
563
- /** @protected */
566
+ /** @private */
564
567
  _animatedOpening() {
565
568
  if (this.parentNode === document.body && this.hasAttribute('closing')) {
566
569
  this._flushAnimation('closing');
@@ -580,7 +583,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
580
583
  }
581
584
  }
582
585
 
583
- /** @protected */
586
+ /** @private */
584
587
  _attachOverlay() {
585
588
  this._placeholder = document.createComment('vaadin-overlay-placeholder');
586
589
  this.parentNode.insertBefore(this._placeholder, this);
@@ -588,24 +591,20 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
588
591
  this.bringToFront();
589
592
  }
590
593
 
591
- /** @protected */
594
+ /** @private */
592
595
  _finishOpening() {
593
596
  this.removeAttribute('opening');
594
597
  }
595
598
 
596
- /** @protected */
599
+ /** @private */
597
600
  _finishClosing() {
598
601
  this._detachOverlay();
599
602
  this.$.overlay.style.removeProperty('pointer-events');
600
603
  this.removeAttribute('closing');
604
+ this.dispatchEvent(new CustomEvent('vaadin-overlay-closed'));
601
605
  }
602
606
 
603
- /**
604
- * @event vaadin-overlay-closing
605
- * Fired when the overlay will be closed.
606
- *
607
- * @protected
608
- */
607
+ /** @private */
609
608
  _animatedClosing() {
610
609
  if (this.hasAttribute('opening')) {
611
610
  this._flushAnimation('opening');
@@ -646,7 +645,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
646
645
  }
647
646
  }
648
647
 
649
- /** @protected */
648
+ /** @private */
650
649
  _detachOverlay() {
651
650
  this._placeholder.parentNode.insertBefore(this, this._placeholder);
652
651
  this._placeholder.parentNode.removeChild(this._placeholder);
@@ -665,7 +664,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
665
664
  }
666
665
  }
667
666
 
668
- /** @protected */
667
+ /** @private */
669
668
  _addGlobalListeners() {
670
669
  document.addEventListener('mousedown', this._boundMouseDownListener);
671
670
  document.addEventListener('mouseup', this._boundMouseUpListener);
@@ -674,7 +673,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
674
673
  document.documentElement.addEventListener('click', this._boundOutsideClickListener, true);
675
674
  }
676
675
 
677
- /** @protected */
676
+ /** @private */
678
677
  _enterModalState() {
679
678
  if (document.body.style.pointerEvents !== 'none') {
680
679
  // Set body pointer-events to 'none' to disable mouse interactions with
@@ -691,14 +690,14 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
691
690
  });
692
691
  }
693
692
 
694
- /** @protected */
693
+ /** @private */
695
694
  _removeGlobalListeners() {
696
695
  document.removeEventListener('mousedown', this._boundMouseDownListener);
697
696
  document.removeEventListener('mouseup', this._boundMouseUpListener);
698
697
  document.documentElement.removeEventListener('click', this._boundOutsideClickListener, true);
699
698
  }
700
699
 
701
- /** @protected */
700
+ /** @private */
702
701
  _exitModalState() {
703
702
  if (this._previousDocumentPointerEvents !== undefined) {
704
703
  // Restore body pointer-events
@@ -750,7 +749,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
750
749
 
751
750
  /**
752
751
  * @return {!Element}
753
- * @protected
752
+ * @private
754
753
  */
755
754
  _getActiveElement() {
756
755
  // Document.activeElement can be null
@@ -765,7 +764,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
765
764
  /**
766
765
  * @param {!Node} node
767
766
  * @return {boolean}
768
- * @protected
767
+ * @private
769
768
  */
770
769
  _deepContains(node) {
771
770
  if (this.contains(node)) {
@@ -793,6 +792,40 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
793
792
  this.style.zIndex = zIndex;
794
793
  this.__zIndex = zIndex || parseFloat(getComputedStyle(this).zIndex);
795
794
  }
795
+
796
+ /**
797
+ * @event vaadin-overlay-open
798
+ * Fired after the overlay is opened.
799
+ */
800
+
801
+ /**
802
+ * @event vaadin-overlay-close
803
+ * Fired when the opened overlay is about to be closed.
804
+ * Calling `preventDefault()` on the event cancels the closing.
805
+ */
806
+
807
+ /**
808
+ * @event vaadin-overlay-closing
809
+ * Fired when the overlay starts to close.
810
+ * Closing the overlay can be asynchronous depending on the animation.
811
+ */
812
+
813
+ /**
814
+ * @event vaadin-overlay-closed
815
+ * Fired after the overlay is closed.
816
+ */
817
+
818
+ /**
819
+ * @event vaadin-overlay-escape-press
820
+ * Fired before the overlay is closed on Escape key press.
821
+ * Calling `preventDefault()` on the event cancels the closing.
822
+ */
823
+
824
+ /**
825
+ * @event vaadin-overlay-outside-click
826
+ * Fired before the overlay is closed on outside click.
827
+ * Calling `preventDefault()` on the event cancels the closing.
828
+ */
796
829
  }
797
830
 
798
831
  customElements.define(Overlay.is, Overlay);