@vaadin/overlay 25.0.0-alpha14 → 25.0.0-alpha15

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": "25.0.0-alpha14",
3
+ "version": "25.0.0-alpha15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -33,17 +33,17 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@open-wc/dedupe-mixin": "^1.3.0",
36
- "@vaadin/a11y-base": "25.0.0-alpha14",
37
- "@vaadin/component-base": "25.0.0-alpha14",
38
- "@vaadin/vaadin-themable-mixin": "25.0.0-alpha14",
36
+ "@vaadin/a11y-base": "25.0.0-alpha15",
37
+ "@vaadin/component-base": "25.0.0-alpha15",
38
+ "@vaadin/vaadin-themable-mixin": "25.0.0-alpha15",
39
39
  "lit": "^3.0.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@vaadin/chai-plugins": "25.0.0-alpha14",
43
- "@vaadin/test-runner-commands": "25.0.0-alpha14",
42
+ "@vaadin/chai-plugins": "25.0.0-alpha15",
43
+ "@vaadin/test-runner-commands": "25.0.0-alpha15",
44
44
  "@vaadin/testing-helpers": "^2.0.0",
45
- "@vaadin/vaadin-lumo-styles": "25.0.0-alpha14",
45
+ "@vaadin/vaadin-lumo-styles": "25.0.0-alpha15",
46
46
  "sinon": "^18.0.0"
47
47
  },
48
- "gitHead": "8ebeeeca4b5b6564eff954d6582d0d6760464e51"
48
+ "gitHead": "1ad98437e7600769bf66f870929feefbeef16edf"
49
49
  }
@@ -80,6 +80,24 @@ export const OverlayFocusMixin = (superClass) =>
80
80
  return this;
81
81
  }
82
82
 
83
+ /**
84
+ * Override to specify another element used as a focus trap root,
85
+ * e.g. the overlay's owner element, rather than overlay part.
86
+ * @protected
87
+ */
88
+ get _focusTrapRoot() {
89
+ return this.$.overlay;
90
+ }
91
+
92
+ /**
93
+ * Override not use a controller for setting `aria-hidden` on
94
+ * elements outside the overlay, e.g. when using `aria-modal`.
95
+ * @protected
96
+ */
97
+ _useAriaHidden() {
98
+ return true;
99
+ }
100
+
83
101
  /**
84
102
  * Release focus and restore focus after the overlay is closed.
85
103
  *
@@ -87,7 +105,9 @@ export const OverlayFocusMixin = (superClass) =>
87
105
  */
88
106
  _resetFocus() {
89
107
  if (this.focusTrap) {
90
- this.__ariaModalController.close();
108
+ if (this._useAriaHidden) {
109
+ this.__ariaModalController.close();
110
+ }
91
111
  this.__focusTrapController.releaseFocus();
92
112
  }
93
113
 
@@ -115,8 +135,10 @@ export const OverlayFocusMixin = (superClass) =>
115
135
  */
116
136
  _trapFocus() {
117
137
  if (this.focusTrap) {
118
- this.__ariaModalController.showModal();
119
- this.__focusTrapController.trapFocus(this.$.overlay);
138
+ if (this._useAriaHidden) {
139
+ this.__ariaModalController.showModal();
140
+ }
141
+ this.__focusTrapController.trapFocus(this._focusTrapRoot);
120
142
  }
121
143
  }
122
144
 
@@ -183,7 +183,7 @@ export const OverlayMixin = (superClass) =>
183
183
  const event = new CustomEvent('vaadin-overlay-close', {
184
184
  bubbles: true,
185
185
  cancelable: true,
186
- detail: { sourceEvent },
186
+ detail: { overlay: this, sourceEvent },
187
187
  });
188
188
  this.dispatchEvent(event);
189
189
  // To allow listening for the event globally, also dispatch it on the document body
@@ -237,8 +237,25 @@ export const OverlayMixin = (superClass) =>
237
237
  }
238
238
  }
239
239
 
240
+ /**
241
+ * Whether to add global listeners for closing on outside click.
242
+ * By default, listeners are not added for a modeless overlay.
243
+ *
244
+ * @return {boolean}
245
+ * @protected
246
+ */
247
+ _shouldAddGlobalListeners() {
248
+ return !this.modeless;
249
+ }
250
+
240
251
  /** @private */
241
252
  _addGlobalListeners() {
253
+ if (this.__hasGlobalListeners) {
254
+ return;
255
+ }
256
+
257
+ this.__hasGlobalListeners = true;
258
+
242
259
  document.addEventListener('mousedown', this._boundMouseDownListener);
243
260
  document.addEventListener('mouseup', this._boundMouseUpListener);
244
261
  // Firefox leaks click to document on contextmenu even if prevented
@@ -248,6 +265,12 @@ export const OverlayMixin = (superClass) =>
248
265
 
249
266
  /** @private */
250
267
  _removeGlobalListeners() {
268
+ if (!this.__hasGlobalListeners) {
269
+ return;
270
+ }
271
+
272
+ this.__hasGlobalListeners = false;
273
+
251
274
  document.removeEventListener('mousedown', this._boundMouseDownListener);
252
275
  document.removeEventListener('mouseup', this._boundMouseUpListener);
253
276
  document.documentElement.removeEventListener('click', this._boundOutsideClickListener, true);
@@ -281,13 +304,20 @@ export const OverlayMixin = (superClass) =>
281
304
 
282
305
  /** @private */
283
306
  _modelessChanged(modeless) {
307
+ if (this.opened) {
308
+ // Add / remove listeners if modeless is changed while opened
309
+ if (this._shouldAddGlobalListeners()) {
310
+ this._addGlobalListeners();
311
+ } else {
312
+ this._removeGlobalListeners();
313
+ }
314
+ }
315
+
284
316
  if (!modeless) {
285
317
  if (this.opened) {
286
- this._addGlobalListeners();
287
318
  this._enterModalState();
288
319
  }
289
320
  } else {
290
- this._removeGlobalListeners();
291
321
  this._exitModalState();
292
322
  }
293
323
  setOverlayStateAttribute(this, 'modeless', modeless);
@@ -317,7 +347,7 @@ export const OverlayMixin = (superClass) =>
317
347
 
318
348
  // Dispatch the event on the overlay. Not using composed, as propagating the event through shadow roots
319
349
  // could have side effects when nesting overlays
320
- const event = new CustomEvent('vaadin-overlay-open', { bubbles: true });
350
+ const event = new CustomEvent('vaadin-overlay-open', { detail: { overlay: this }, bubbles: true });
321
351
  this.dispatchEvent(event);
322
352
  // To allow listening for the event globally, also dispatch it on the document body
323
353
  document.body.dispatchEvent(event);
@@ -326,7 +356,7 @@ export const OverlayMixin = (superClass) =>
326
356
 
327
357
  document.addEventListener('keydown', this._boundKeydownListener);
328
358
 
329
- if (!this.modeless) {
359
+ if (this._shouldAddGlobalListeners()) {
330
360
  this._addGlobalListeners();
331
361
  }
332
362
  } else if (wasOpened) {
@@ -341,7 +371,7 @@ export const OverlayMixin = (superClass) =>
341
371
 
342
372
  document.removeEventListener('keydown', this._boundKeydownListener);
343
373
 
344
- if (!this.modeless) {
374
+ if (this._shouldAddGlobalListeners()) {
345
375
  this._removeGlobalListeners();
346
376
  }
347
377
  }
@@ -522,7 +552,7 @@ export const OverlayMixin = (superClass) =>
522
552
  }
523
553
 
524
554
  // Only close modeless overlay on Esc press when it contains focus
525
- if (this.modeless && !event.composedPath().includes(this.$.overlay)) {
555
+ if (!this._shouldAddGlobalListeners() && !event.composedPath().includes(this.$.overlay)) {
526
556
  return;
527
557
  }
528
558
 
@@ -17,13 +17,13 @@ export type OverlayOpenedChangedEvent = CustomEvent<{ value: boolean }>;
17
17
  /**
18
18
  * Fired after the overlay is opened.
19
19
  */
20
- export type OverlayOpenEvent = CustomEvent;
20
+ export type OverlayOpenEvent = CustomEvent<{ overlay: HTMLElement }>;
21
21
 
22
22
  /**
23
23
  * Fired when the opened overlay is about to be closed.
24
24
  * Calling `preventDefault()` on the event cancels the closing.
25
25
  */
26
- export type OverlayCloseEvent = CustomEvent;
26
+ export type OverlayCloseEvent = CustomEvent<{ overlay: HTMLElement }>;
27
27
 
28
28
  /**
29
29
  * Fired after the overlay is closed.