@vaadin/overlay 25.0.0-alpha1 → 25.0.0-alpha10
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 +11 -11
- package/src/styles/vaadin-overlay-base-styles.js +87 -0
- package/src/{vaadin-overlay-core-styles.js → styles/vaadin-overlay-core-styles.js} +8 -1
- package/src/vaadin-overlay-focus-mixin.js +23 -5
- package/src/vaadin-overlay-mixin.d.ts +12 -0
- package/src/vaadin-overlay-mixin.js +72 -24
- package/src/vaadin-overlay-position-mixin.js +5 -5
- package/src/vaadin-overlay-stack-mixin.js +59 -44
- package/src/vaadin-overlay-utils.d.ts +6 -0
- package/src/vaadin-overlay-utils.js +29 -0
- package/src/vaadin-overlay.js +3 -2
- package/src/vaadin-overlay-base-styles.js +0 -82
- package/src/vaadin-overlay-styles.js +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/overlay",
|
|
3
|
-
"version": "25.0.0-
|
|
3
|
+
"version": "25.0.0-alpha10",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"type": "module",
|
|
22
22
|
"files": [
|
|
23
23
|
"src",
|
|
24
|
-
"!src/*-base-styles.d.ts",
|
|
25
|
-
"!src/*-base-styles.js",
|
|
24
|
+
"!src/styles/*-base-styles.d.ts",
|
|
25
|
+
"!src/styles/*-base-styles.js",
|
|
26
26
|
"theme",
|
|
27
27
|
"vaadin-*.d.ts",
|
|
28
28
|
"vaadin-*.js"
|
|
@@ -36,17 +36,17 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
39
|
-
"@vaadin/a11y-base": "25.0.0-
|
|
40
|
-
"@vaadin/component-base": "25.0.0-
|
|
41
|
-
"@vaadin/vaadin-lumo-styles": "25.0.0-
|
|
42
|
-
"@vaadin/vaadin-themable-mixin": "25.0.0-
|
|
39
|
+
"@vaadin/a11y-base": "25.0.0-alpha10",
|
|
40
|
+
"@vaadin/component-base": "25.0.0-alpha10",
|
|
41
|
+
"@vaadin/vaadin-lumo-styles": "25.0.0-alpha10",
|
|
42
|
+
"@vaadin/vaadin-themable-mixin": "25.0.0-alpha10",
|
|
43
43
|
"lit": "^3.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@vaadin/chai-plugins": "25.0.0-
|
|
47
|
-
"@vaadin/test-runner-commands": "25.0.0-
|
|
48
|
-
"@vaadin/testing-helpers": "^
|
|
46
|
+
"@vaadin/chai-plugins": "25.0.0-alpha10",
|
|
47
|
+
"@vaadin/test-runner-commands": "25.0.0-alpha10",
|
|
48
|
+
"@vaadin/testing-helpers": "^2.0.0",
|
|
49
49
|
"sinon": "^18.0.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "6cc6c94079e805fa5b2f0af4dbf3b2a7485e57d0"
|
|
52
52
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2017 - 2025 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import '@vaadin/component-base/src/style-props.js';
|
|
7
|
+
import { css } from 'lit';
|
|
8
|
+
|
|
9
|
+
export const overlayStyles = css`
|
|
10
|
+
:host {
|
|
11
|
+
z-index: 200;
|
|
12
|
+
position: fixed;
|
|
13
|
+
|
|
14
|
+
/* Despite of what the names say, <vaadin-overlay> is just a container
|
|
15
|
+
for position/sizing/alignment. The actual overlay is the overlay part. */
|
|
16
|
+
|
|
17
|
+
/* Default position constraints. Themes can
|
|
18
|
+
override this to adjust the gap between the overlay and the viewport. */
|
|
19
|
+
inset: 8px;
|
|
20
|
+
bottom: var(--vaadin-overlay-viewport-bottom);
|
|
21
|
+
|
|
22
|
+
/* Override native [popover] user agent styles */
|
|
23
|
+
width: auto;
|
|
24
|
+
height: auto;
|
|
25
|
+
border: none;
|
|
26
|
+
padding: 0;
|
|
27
|
+
background-color: transparent;
|
|
28
|
+
overflow: visible;
|
|
29
|
+
|
|
30
|
+
/* Use flexbox alignment for the overlay part. */
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-direction: column; /* makes dropdowns sizing easier */
|
|
33
|
+
/* Align to center by default. */
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: center;
|
|
36
|
+
|
|
37
|
+
/* Allow centering when max-width/max-height applies. */
|
|
38
|
+
margin: auto;
|
|
39
|
+
|
|
40
|
+
/* The host is not clickable, only the overlay part is. */
|
|
41
|
+
pointer-events: none;
|
|
42
|
+
|
|
43
|
+
/* Remove tap highlight on touch devices. */
|
|
44
|
+
-webkit-tap-highlight-color: transparent;
|
|
45
|
+
|
|
46
|
+
/* CSS API for host */
|
|
47
|
+
--vaadin-overlay-viewport-bottom: 8px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
:host([hidden]),
|
|
51
|
+
:host(:not([opened]):not([closing])),
|
|
52
|
+
:host(:not([opened]):not([closing])) [part='overlay'] {
|
|
53
|
+
display: none !important;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
[part='overlay'] {
|
|
57
|
+
background: var(--vaadin-overlay-background, var(--vaadin-background-color));
|
|
58
|
+
border: var(--vaadin-overlay-border-width, 1px) solid var(--vaadin-overlay-border-color, var(--vaadin-border-color));
|
|
59
|
+
border-radius: var(--vaadin-overlay-border-radius, var(--vaadin-radius-m));
|
|
60
|
+
box-shadow: var(--vaadin-overlay-box-shadow, 0 8px 24px -4px rgba(0, 0, 0, 0.3));
|
|
61
|
+
box-sizing: border-box;
|
|
62
|
+
max-width: 100%;
|
|
63
|
+
overflow: auto;
|
|
64
|
+
overscroll-behavior: contain;
|
|
65
|
+
pointer-events: auto;
|
|
66
|
+
-webkit-tap-highlight-color: initial;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
[part='backdrop'] {
|
|
70
|
+
background: var(--vaadin-overlay-backdrop-background, rgba(0, 0, 0, 0.5));
|
|
71
|
+
content: '';
|
|
72
|
+
inset: 0;
|
|
73
|
+
pointer-events: auto;
|
|
74
|
+
position: fixed;
|
|
75
|
+
z-index: -1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
[part='overlay']:focus-visible {
|
|
79
|
+
outline: var(--vaadin-focus-ring-width) solid var(--vaadin-focus-ring-color);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@media (forced-colors: active) {
|
|
83
|
+
[part='overlay'] {
|
|
84
|
+
border: 3px solid;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
@@ -18,6 +18,14 @@ export const overlayStyles = css`
|
|
|
18
18
|
inset: 0;
|
|
19
19
|
bottom: var(--vaadin-overlay-viewport-bottom);
|
|
20
20
|
|
|
21
|
+
/* Override native [popover] user agent styles */
|
|
22
|
+
width: auto;
|
|
23
|
+
height: auto;
|
|
24
|
+
border: none;
|
|
25
|
+
padding: 0;
|
|
26
|
+
background-color: transparent;
|
|
27
|
+
overflow: visible;
|
|
28
|
+
|
|
21
29
|
/* Use flexbox alignment for the overlay part. */
|
|
22
30
|
display: flex;
|
|
23
31
|
flex-direction: column; /* makes dropdowns sizing easier */
|
|
@@ -45,7 +53,6 @@ export const overlayStyles = css`
|
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
[part='overlay'] {
|
|
48
|
-
-webkit-overflow-scrolling: touch;
|
|
49
56
|
overflow: auto;
|
|
50
57
|
pointer-events: auto;
|
|
51
58
|
|
|
@@ -48,11 +48,20 @@ export const OverlayFocusMixin = (superClass) =>
|
|
|
48
48
|
constructor() {
|
|
49
49
|
super();
|
|
50
50
|
|
|
51
|
-
this.__ariaModalController = new AriaModalController(this);
|
|
51
|
+
this.__ariaModalController = new AriaModalController(this, () => this._modalRoot);
|
|
52
52
|
this.__focusTrapController = new FocusTrapController(this);
|
|
53
53
|
this.__focusRestorationController = new FocusRestorationController();
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Override to specify another element used as a content root,
|
|
58
|
+
* e.g. slotted into the overlay, rather than overlay itself.
|
|
59
|
+
* @protected
|
|
60
|
+
*/
|
|
61
|
+
get _contentRoot() {
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
56
65
|
/** @protected */
|
|
57
66
|
ready() {
|
|
58
67
|
super.ready();
|
|
@@ -62,6 +71,15 @@ export const OverlayFocusMixin = (superClass) =>
|
|
|
62
71
|
this.addController(this.__focusRestorationController);
|
|
63
72
|
}
|
|
64
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Override to specify another element used as a modality root,
|
|
76
|
+
* e.g. the overlay's owner element, rather than overlay itself.
|
|
77
|
+
* @protected
|
|
78
|
+
*/
|
|
79
|
+
get _modalRoot() {
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
65
83
|
/**
|
|
66
84
|
* Release focus and restore focus after the overlay is closed.
|
|
67
85
|
*
|
|
@@ -127,15 +145,15 @@ export const OverlayFocusMixin = (superClass) =>
|
|
|
127
145
|
* @protected
|
|
128
146
|
*/
|
|
129
147
|
_deepContains(node) {
|
|
130
|
-
if (this.contains(node)) {
|
|
148
|
+
if (this._contentRoot.contains(node)) {
|
|
131
149
|
return true;
|
|
132
150
|
}
|
|
133
151
|
let n = node;
|
|
134
152
|
const doc = node.ownerDocument;
|
|
135
|
-
// Walk from node to
|
|
136
|
-
while (n && n !== doc && n !== this) {
|
|
153
|
+
// Walk from node to content root or `document`
|
|
154
|
+
while (n && n !== doc && n !== this._contentRoot) {
|
|
137
155
|
n = n.parentNode || n.host;
|
|
138
156
|
}
|
|
139
|
-
return n === this;
|
|
157
|
+
return n === this._contentRoot;
|
|
140
158
|
}
|
|
141
159
|
};
|
|
@@ -7,6 +7,13 @@ import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
|
7
7
|
import type { OverlayFocusMixinClass } from './vaadin-overlay-focus-mixin.js';
|
|
8
8
|
import type { OverlayStackMixinClass } from './vaadin-overlay-stack-mixin.js';
|
|
9
9
|
|
|
10
|
+
export type OverlayBounds = {
|
|
11
|
+
top?: number | string;
|
|
12
|
+
left?: number | string;
|
|
13
|
+
width?: number | string;
|
|
14
|
+
height?: number | string;
|
|
15
|
+
};
|
|
16
|
+
|
|
10
17
|
export type OverlayRenderer = (root: HTMLElement, owner: HTMLElement, model?: object) => void;
|
|
11
18
|
|
|
12
19
|
export declare function OverlayMixin<T extends Constructor<HTMLElement>>(
|
|
@@ -58,6 +65,11 @@ export declare class OverlayMixinClass {
|
|
|
58
65
|
|
|
59
66
|
close(sourceEvent?: Event | null): void;
|
|
60
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Updates the coordinates of the overlay.
|
|
70
|
+
*/
|
|
71
|
+
setBounds(bounds: OverlayBounds, absolute?: boolean): void;
|
|
72
|
+
|
|
61
73
|
/**
|
|
62
74
|
* Requests an update for the content of the overlay.
|
|
63
75
|
* While performing the update, it invokes the renderer passed in the `renderer` property.
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { isIOS } from '@vaadin/component-base/src/browser-utils.js';
|
|
7
7
|
import { OverlayFocusMixin } from './vaadin-overlay-focus-mixin.js';
|
|
8
8
|
import { OverlayStackMixin } from './vaadin-overlay-stack-mixin.js';
|
|
9
|
+
import { setOverlayStateAttribute } from './vaadin-overlay-utils.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @polymerMixin
|
|
@@ -91,6 +92,7 @@ export const OverlayMixin = (superClass) =>
|
|
|
91
92
|
type: Boolean,
|
|
92
93
|
value: false,
|
|
93
94
|
reflectToAttribute: true,
|
|
95
|
+
observer: '_withBackdropChanged',
|
|
94
96
|
sync: true,
|
|
95
97
|
},
|
|
96
98
|
};
|
|
@@ -115,15 +117,20 @@ export const OverlayMixin = (superClass) =>
|
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
/** @protected */
|
|
118
|
-
|
|
119
|
-
super.
|
|
120
|
+
firstUpdated() {
|
|
121
|
+
super.firstUpdated();
|
|
122
|
+
|
|
123
|
+
// Set popover in firstUpdated before opened observers are called
|
|
124
|
+
this.popover = 'manual';
|
|
120
125
|
|
|
121
126
|
// Need to add dummy click listeners to this and the backdrop or else
|
|
122
127
|
// the document click event listener (_outsideClickListener) may never
|
|
123
128
|
// get invoked on iOS Safari (reproducible in <vaadin-dialog>
|
|
124
129
|
// and <vaadin-context-menu>).
|
|
125
130
|
this.addEventListener('click', () => {});
|
|
126
|
-
this.$.backdrop
|
|
131
|
+
if (this.$.backdrop) {
|
|
132
|
+
this.$.backdrop.addEventListener('click', () => {});
|
|
133
|
+
}
|
|
127
134
|
|
|
128
135
|
this.addEventListener('mouseup', () => {
|
|
129
136
|
// In Chrome, focus moves to body on overlay content mousedown
|
|
@@ -163,7 +170,7 @@ export const OverlayMixin = (superClass) =>
|
|
|
163
170
|
*/
|
|
164
171
|
requestContentUpdate() {
|
|
165
172
|
if (this.renderer) {
|
|
166
|
-
this.renderer.call(this.owner, this, this.owner, this.model);
|
|
173
|
+
this.renderer.call(this.owner, this._contentRoot, this.owner, this.model);
|
|
167
174
|
}
|
|
168
175
|
}
|
|
169
176
|
|
|
@@ -171,17 +178,44 @@ export const OverlayMixin = (superClass) =>
|
|
|
171
178
|
* @param {Event=} sourceEvent
|
|
172
179
|
*/
|
|
173
180
|
close(sourceEvent) {
|
|
174
|
-
|
|
181
|
+
// Dispatch the event on the overlay. Not using composed, as propagating the event through shadow roots could have
|
|
182
|
+
// side effects when nesting overlays
|
|
183
|
+
const event = new CustomEvent('vaadin-overlay-close', {
|
|
175
184
|
bubbles: true,
|
|
176
185
|
cancelable: true,
|
|
177
186
|
detail: { sourceEvent },
|
|
178
187
|
});
|
|
179
|
-
this.dispatchEvent(
|
|
180
|
-
|
|
188
|
+
this.dispatchEvent(event);
|
|
189
|
+
// To allow listening for the event globally, also dispatch it on the document body
|
|
190
|
+
document.body.dispatchEvent(event);
|
|
191
|
+
if (!event.defaultPrevented) {
|
|
181
192
|
this.opened = false;
|
|
182
193
|
}
|
|
183
194
|
}
|
|
184
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Updates the coordinates of the overlay.
|
|
198
|
+
* @param {!OverlayBoundsParam} bounds
|
|
199
|
+
* @param {boolean} absolute
|
|
200
|
+
*/
|
|
201
|
+
setBounds(bounds, absolute = true) {
|
|
202
|
+
const overlay = this.$.overlay;
|
|
203
|
+
const parsedBounds = { ...bounds };
|
|
204
|
+
|
|
205
|
+
if (absolute && overlay.style.position !== 'absolute') {
|
|
206
|
+
overlay.style.position = 'absolute';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
Object.keys(parsedBounds).forEach((arg) => {
|
|
210
|
+
// Allow setting width or height to `null`
|
|
211
|
+
if (parsedBounds[arg] !== null && !isNaN(parsedBounds[arg])) {
|
|
212
|
+
parsedBounds[arg] = `${parsedBounds[arg]}px`;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
Object.assign(overlay.style, parsedBounds);
|
|
217
|
+
}
|
|
218
|
+
|
|
185
219
|
/** @private */
|
|
186
220
|
_detectIosNavbar() {
|
|
187
221
|
/* c8 ignore next 15 */
|
|
@@ -233,11 +267,11 @@ export const OverlayMixin = (superClass) =>
|
|
|
233
267
|
this._oldOpened = opened;
|
|
234
268
|
|
|
235
269
|
if (rendererChanged && hasOldRenderer) {
|
|
236
|
-
this.innerHTML = '';
|
|
270
|
+
this._contentRoot.innerHTML = '';
|
|
237
271
|
// Whenever a Lit-based renderer is used, it assigns a Lit part to the node it was rendered into.
|
|
238
272
|
// When clearing the rendered content, this part needs to be manually disposed of.
|
|
239
273
|
// Otherwise, using a Lit-based renderer on the same node will throw an exception or render nothing afterward.
|
|
240
|
-
delete this._$litPart$;
|
|
274
|
+
delete this._contentRoot._$litPart$;
|
|
241
275
|
}
|
|
242
276
|
|
|
243
277
|
if (opened && renderer && (rendererChanged || openedChanged || ownerOrModelChanged)) {
|
|
@@ -256,11 +290,23 @@ export const OverlayMixin = (superClass) =>
|
|
|
256
290
|
this._removeGlobalListeners();
|
|
257
291
|
this._exitModalState();
|
|
258
292
|
}
|
|
293
|
+
setOverlayStateAttribute(this, 'modeless', modeless);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** @private */
|
|
297
|
+
_withBackdropChanged(withBackdrop) {
|
|
298
|
+
setOverlayStateAttribute(this, 'with-backdrop', withBackdrop);
|
|
259
299
|
}
|
|
260
300
|
|
|
261
301
|
/** @private */
|
|
262
302
|
_openedChanged(opened, wasOpened) {
|
|
263
303
|
if (opened) {
|
|
304
|
+
// Prevent possible errors on setting `opened` to `true` while disconnected
|
|
305
|
+
if (!this.isConnected) {
|
|
306
|
+
this.opened = false;
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
264
310
|
this._saveFocus();
|
|
265
311
|
|
|
266
312
|
this._animatedOpening();
|
|
@@ -269,7 +315,12 @@ export const OverlayMixin = (superClass) =>
|
|
|
269
315
|
setTimeout(() => {
|
|
270
316
|
this._trapFocus();
|
|
271
317
|
|
|
272
|
-
|
|
318
|
+
// Dispatch the event on the overlay. Not using composed, as propagating the event through shadow roots
|
|
319
|
+
// could have side effects when nesting overlays
|
|
320
|
+
const event = new CustomEvent('vaadin-overlay-open', { bubbles: true });
|
|
321
|
+
this.dispatchEvent(event);
|
|
322
|
+
// To allow listening for the event globally, also dispatch it on the document body
|
|
323
|
+
document.body.dispatchEvent(event);
|
|
273
324
|
});
|
|
274
325
|
});
|
|
275
326
|
|
|
@@ -346,14 +397,16 @@ export const OverlayMixin = (superClass) =>
|
|
|
346
397
|
|
|
347
398
|
/** @private */
|
|
348
399
|
_animatedOpening() {
|
|
349
|
-
if (this.
|
|
400
|
+
if (this._isAttached && this.hasAttribute('closing')) {
|
|
350
401
|
this._flushAnimation('closing');
|
|
351
402
|
}
|
|
352
403
|
this._attachOverlay();
|
|
404
|
+
this._appendAttachedInstance();
|
|
405
|
+
this.bringToFront();
|
|
353
406
|
if (!this.modeless) {
|
|
354
407
|
this._enterModalState();
|
|
355
408
|
}
|
|
356
|
-
this
|
|
409
|
+
setOverlayStateAttribute(this, 'opening', true);
|
|
357
410
|
|
|
358
411
|
if (this._shouldAnimate()) {
|
|
359
412
|
this._enqueueAnimation('opening', () => {
|
|
@@ -366,22 +419,20 @@ export const OverlayMixin = (superClass) =>
|
|
|
366
419
|
|
|
367
420
|
/** @private */
|
|
368
421
|
_attachOverlay() {
|
|
369
|
-
this.
|
|
370
|
-
this.parentNode.insertBefore(this._placeholder, this);
|
|
371
|
-
document.body.appendChild(this);
|
|
372
|
-
this.bringToFront();
|
|
422
|
+
this.showPopover();
|
|
373
423
|
}
|
|
374
424
|
|
|
375
425
|
/** @private */
|
|
376
426
|
_finishOpening() {
|
|
377
|
-
this
|
|
427
|
+
setOverlayStateAttribute(this, 'opening', false);
|
|
378
428
|
}
|
|
379
429
|
|
|
380
430
|
/** @private */
|
|
381
431
|
_finishClosing() {
|
|
382
432
|
this._detachOverlay();
|
|
433
|
+
this._removeAttachedInstance();
|
|
383
434
|
this.$.overlay.style.removeProperty('pointer-events');
|
|
384
|
-
this
|
|
435
|
+
setOverlayStateAttribute(this, 'closing', false);
|
|
385
436
|
this.dispatchEvent(new CustomEvent('vaadin-overlay-closed'));
|
|
386
437
|
}
|
|
387
438
|
|
|
@@ -390,9 +441,9 @@ export const OverlayMixin = (superClass) =>
|
|
|
390
441
|
if (this.hasAttribute('opening')) {
|
|
391
442
|
this._flushAnimation('opening');
|
|
392
443
|
}
|
|
393
|
-
if (this.
|
|
444
|
+
if (this._isAttached) {
|
|
394
445
|
this._exitModalState();
|
|
395
|
-
this
|
|
446
|
+
setOverlayStateAttribute(this, 'closing', true);
|
|
396
447
|
this.dispatchEvent(new CustomEvent('vaadin-overlay-closing'));
|
|
397
448
|
|
|
398
449
|
if (this._shouldAnimate()) {
|
|
@@ -407,8 +458,7 @@ export const OverlayMixin = (superClass) =>
|
|
|
407
458
|
|
|
408
459
|
/** @private */
|
|
409
460
|
_detachOverlay() {
|
|
410
|
-
this.
|
|
411
|
-
this._placeholder.parentNode.removeChild(this._placeholder);
|
|
461
|
+
this.hidePopover();
|
|
412
462
|
}
|
|
413
463
|
|
|
414
464
|
/** @private */
|
|
@@ -452,7 +502,6 @@ export const OverlayMixin = (superClass) =>
|
|
|
452
502
|
}
|
|
453
503
|
|
|
454
504
|
const evt = new CustomEvent('vaadin-overlay-outside-click', {
|
|
455
|
-
bubbles: true,
|
|
456
505
|
cancelable: true,
|
|
457
506
|
detail: { sourceEvent: event },
|
|
458
507
|
});
|
|
@@ -479,7 +528,6 @@ export const OverlayMixin = (superClass) =>
|
|
|
479
528
|
|
|
480
529
|
if (event.key === 'Escape') {
|
|
481
530
|
const evt = new CustomEvent('vaadin-overlay-escape-press', {
|
|
482
|
-
bubbles: true,
|
|
483
531
|
cancelable: true,
|
|
484
532
|
detail: { sourceEvent: event },
|
|
485
533
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { getAncestorRootNodes } from '@vaadin/component-base/src/dom-utils.js';
|
|
7
|
-
import { observeMove } from './vaadin-overlay-utils.js';
|
|
7
|
+
import { observeMove, setOverlayStateAttribute } from './vaadin-overlay-utils.js';
|
|
8
8
|
|
|
9
9
|
const PROP_NAMES_VERTICAL = {
|
|
10
10
|
start: 'top',
|
|
@@ -271,11 +271,11 @@ export const PositionMixin = (superClass) =>
|
|
|
271
271
|
// Apply the positioning properties to the overlay
|
|
272
272
|
Object.assign(this.style, verticalProps, horizontalProps);
|
|
273
273
|
|
|
274
|
-
this
|
|
275
|
-
this
|
|
274
|
+
setOverlayStateAttribute(this, 'bottom-aligned', !shouldAlignStartVertically);
|
|
275
|
+
setOverlayStateAttribute(this, 'top-aligned', shouldAlignStartVertically);
|
|
276
276
|
|
|
277
|
-
this
|
|
278
|
-
this
|
|
277
|
+
setOverlayStateAttribute(this, 'end-aligned', !flexStart);
|
|
278
|
+
setOverlayStateAttribute(this, 'start-aligned', flexStart);
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
__shouldAlignStartHorizontally(targetRect, rtl) {
|
|
@@ -4,45 +4,43 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
/** @type {Set<HTMLElement>} */
|
|
8
|
+
const attachedInstances = new Set();
|
|
9
|
+
|
|
7
10
|
/**
|
|
8
11
|
* Returns all attached overlays in visual stacking order.
|
|
9
12
|
* @private
|
|
10
13
|
*/
|
|
11
|
-
const getAttachedInstances = () =>
|
|
12
|
-
Array.from(document.body.children)
|
|
13
|
-
.filter((el) => el instanceof HTMLElement && el._hasOverlayStackMixin && !el.hasAttribute('closing'))
|
|
14
|
-
.sort((a, b) => a.__zIndex - b.__zIndex || 0);
|
|
14
|
+
const getAttachedInstances = () => [...attachedInstances].filter((el) => !el.hasAttribute('closing'));
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Returns all
|
|
18
|
-
* which only needs to be in the stack for zIndex but not pointer-events.
|
|
17
|
+
* Returns true if all the instances on top of the overlay are nested overlays.
|
|
19
18
|
* @private
|
|
20
19
|
*/
|
|
21
|
-
const
|
|
20
|
+
const hasOnlyNestedOverlays = (overlay) => {
|
|
21
|
+
const instances = getAttachedInstances();
|
|
22
|
+
const next = instances[instances.indexOf(overlay) + 1];
|
|
23
|
+
if (!next) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!overlay._deepContains(next)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return hasOnlyNestedOverlays(next);
|
|
32
|
+
};
|
|
22
33
|
|
|
23
34
|
/**
|
|
24
35
|
* Returns true if the overlay is the last one in the opened overlays stack.
|
|
25
36
|
* @param {HTMLElement} overlay
|
|
37
|
+
* @param {function(HTMLElement): boolean} filter
|
|
26
38
|
* @return {boolean}
|
|
27
39
|
* @protected
|
|
28
40
|
*/
|
|
29
|
-
export const isLastOverlay = (overlay) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Stores the reference to the nested overlay for given parent,
|
|
35
|
-
* or removes it when the nested overlay is null.
|
|
36
|
-
* @param {HTMLElement} parent
|
|
37
|
-
* @param {HTMLElement} nested
|
|
38
|
-
* @protected
|
|
39
|
-
*/
|
|
40
|
-
export const setNestedOverlay = (parent, nested) => {
|
|
41
|
-
if (nested != null) {
|
|
42
|
-
overlayMap.set(parent, nested);
|
|
43
|
-
} else {
|
|
44
|
-
overlayMap.delete(parent);
|
|
45
|
-
}
|
|
41
|
+
export const isLastOverlay = (overlay, filter = (_overlay) => true) => {
|
|
42
|
+
const filteredOverlays = getAttachedInstances().filter(filter);
|
|
43
|
+
return overlay === filteredOverlays.pop();
|
|
46
44
|
};
|
|
47
45
|
|
|
48
46
|
/**
|
|
@@ -50,12 +48,6 @@ export const setNestedOverlay = (parent, nested) => {
|
|
|
50
48
|
*/
|
|
51
49
|
export const OverlayStackMixin = (superClass) =>
|
|
52
50
|
class OverlayStackMixin extends superClass {
|
|
53
|
-
constructor() {
|
|
54
|
-
super();
|
|
55
|
-
|
|
56
|
-
this._hasOverlayStackMixin = true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
51
|
/**
|
|
60
52
|
* Returns true if this is the last one in the opened overlays stack.
|
|
61
53
|
*
|
|
@@ -66,25 +58,36 @@ export const OverlayStackMixin = (superClass) =>
|
|
|
66
58
|
return isLastOverlay(this);
|
|
67
59
|
}
|
|
68
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Returns true if this is overlay is attached.
|
|
63
|
+
*
|
|
64
|
+
* @return {boolean}
|
|
65
|
+
* @protected
|
|
66
|
+
*/
|
|
67
|
+
get _isAttached() {
|
|
68
|
+
return attachedInstances.has(this);
|
|
69
|
+
}
|
|
70
|
+
|
|
69
71
|
/**
|
|
70
72
|
* Brings the overlay as visually the frontmost one.
|
|
71
73
|
*/
|
|
72
74
|
bringToFront() {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const frontmostZIndex = frontmost.__zIndex;
|
|
79
|
-
zIndex = frontmostZIndex + 1;
|
|
75
|
+
// If the overlay is the last one, or if all other overlays shown above
|
|
76
|
+
// are nested overlays (e.g. date-picker inside a dialog), do not call
|
|
77
|
+
// `showPopover()` unnecessarily to avoid scroll position being reset.
|
|
78
|
+
if (isLastOverlay(this) || hasOnlyNestedOverlays(this)) {
|
|
79
|
+
return;
|
|
80
80
|
}
|
|
81
|
-
this.style.zIndex = zIndex;
|
|
82
|
-
this.__zIndex = zIndex || parseFloat(getComputedStyle(this).zIndex);
|
|
83
81
|
|
|
84
|
-
//
|
|
85
|
-
if (
|
|
86
|
-
|
|
82
|
+
// Update stacking order of native popover-based overlays
|
|
83
|
+
if (this.matches(':popover-open')) {
|
|
84
|
+
this.hidePopover();
|
|
85
|
+
this.showPopover();
|
|
87
86
|
}
|
|
87
|
+
|
|
88
|
+
// Update order of attached instances
|
|
89
|
+
this._removeAttachedInstance();
|
|
90
|
+
this._appendAttachedInstance();
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
/** @protected */
|
|
@@ -97,7 +100,7 @@ export const OverlayStackMixin = (superClass) =>
|
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
// Disable pointer events in other attached overlays
|
|
100
|
-
|
|
103
|
+
getAttachedInstances().forEach((el) => {
|
|
101
104
|
if (el !== this) {
|
|
102
105
|
el.$.overlay.style.pointerEvents = 'none';
|
|
103
106
|
}
|
|
@@ -113,7 +116,7 @@ export const OverlayStackMixin = (superClass) =>
|
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
// Restore pointer events in the previous overlay(s)
|
|
116
|
-
const instances =
|
|
119
|
+
const instances = getAttachedInstances();
|
|
117
120
|
|
|
118
121
|
let el;
|
|
119
122
|
// Use instances.pop() to ensure the reverse order
|
|
@@ -129,4 +132,16 @@ export const OverlayStackMixin = (superClass) =>
|
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
}
|
|
135
|
+
|
|
136
|
+
/** @protected */
|
|
137
|
+
_appendAttachedInstance() {
|
|
138
|
+
attachedInstances.add(this);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** @protected */
|
|
142
|
+
_removeAttachedInstance() {
|
|
143
|
+
if (this._isAttached) {
|
|
144
|
+
attachedInstances.delete(this);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
132
147
|
};
|
|
@@ -11,3 +11,9 @@
|
|
|
11
11
|
* https://github.com/floating-ui/floating-ui/blob/58ed169/packages/dom/src/autoUpdate.ts#L45
|
|
12
12
|
*/
|
|
13
13
|
export function observeMove(element: HTMLElement, callback: () => void): () => void;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Toggle the state attribute on the overlay element and also its owner element. This allows targeting state attributes
|
|
17
|
+
* in the light DOM in case the overlay is in the shadow DOM of its owner.
|
|
18
|
+
*/
|
|
19
|
+
export function setOverlayStateAttribute(overlay: HTMLElement, name: string, value: string | boolean): void;
|
|
@@ -87,3 +87,32 @@ export function observeMove(element, callback) {
|
|
|
87
87
|
|
|
88
88
|
return cleanup;
|
|
89
89
|
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Toggle the state attribute on the overlay element and also its owner element. This allows targeting state attributes
|
|
93
|
+
* in the light DOM in case the overlay is in the shadow DOM of its owner.
|
|
94
|
+
* @param {HTMLElement} overlay The overlay element on which to toggle the attribute.
|
|
95
|
+
* @param {string} name The name of the attribute to toggle.
|
|
96
|
+
* @param {string|boolean} value The value of the attribute. If a string is provided, it will be set as the attribute
|
|
97
|
+
* value. Otherwise, the attribute will be added or removed depending on whether `value` is truthy or falsy.
|
|
98
|
+
*/
|
|
99
|
+
export function setOverlayStateAttribute(overlay, name, value) {
|
|
100
|
+
const elements = [overlay];
|
|
101
|
+
if (overlay.owner) {
|
|
102
|
+
elements.push(overlay.owner);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (typeof value === 'string') {
|
|
106
|
+
elements.forEach((element) => {
|
|
107
|
+
element.setAttribute(name, value);
|
|
108
|
+
});
|
|
109
|
+
} else if (value) {
|
|
110
|
+
elements.forEach((element) => {
|
|
111
|
+
element.setAttribute(name, '');
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
elements.forEach((element) => {
|
|
115
|
+
element.removeAttribute(name);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
package/src/vaadin-overlay.js
CHANGED
|
@@ -7,9 +7,10 @@ import { html, LitElement } from 'lit';
|
|
|
7
7
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
8
8
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
9
9
|
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
10
|
+
import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
|
|
10
11
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
12
|
+
import { overlayStyles } from './styles/vaadin-overlay-core-styles.js';
|
|
11
13
|
import { OverlayMixin } from './vaadin-overlay-mixin.js';
|
|
12
|
-
import { overlayStyles } from './vaadin-overlay-styles.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* `<vaadin-overlay>` is a Web Component for creating overlays. The content of the overlay
|
|
@@ -76,7 +77,7 @@ import { overlayStyles } from './vaadin-overlay-styles.js';
|
|
|
76
77
|
* @mixes DirMixin
|
|
77
78
|
* @mixes OverlayMixin
|
|
78
79
|
*/
|
|
79
|
-
class Overlay extends OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LitElement)))) {
|
|
80
|
+
class Overlay extends OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LumoInjectionMixin(LitElement))))) {
|
|
80
81
|
static get is() {
|
|
81
82
|
return 'vaadin-overlay';
|
|
82
83
|
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2017 - 2025 Vaadin Ltd.
|
|
4
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
-
*/
|
|
6
|
-
import '@vaadin/component-base/src/style-props.js';
|
|
7
|
-
import { css } from 'lit';
|
|
8
|
-
|
|
9
|
-
export const overlayStyles = css`
|
|
10
|
-
@layer base {
|
|
11
|
-
:host {
|
|
12
|
-
z-index: 200;
|
|
13
|
-
position: fixed;
|
|
14
|
-
|
|
15
|
-
/* Despite of what the names say, <vaadin-overlay> is just a container
|
|
16
|
-
for position/sizing/alignment. The actual overlay is the overlay part. */
|
|
17
|
-
|
|
18
|
-
/* Default position constraints. Themes can
|
|
19
|
-
override this to adjust the gap between the overlay and the viewport. */
|
|
20
|
-
inset: 8px;
|
|
21
|
-
bottom: var(--vaadin-overlay-viewport-bottom);
|
|
22
|
-
|
|
23
|
-
/* Use flexbox alignment for the overlay part. */
|
|
24
|
-
display: flex;
|
|
25
|
-
flex-direction: column; /* makes dropdowns sizing easier */
|
|
26
|
-
/* Align to center by default. */
|
|
27
|
-
align-items: center;
|
|
28
|
-
justify-content: center;
|
|
29
|
-
|
|
30
|
-
/* Allow centering when max-width/max-height applies. */
|
|
31
|
-
margin: auto;
|
|
32
|
-
|
|
33
|
-
/* The host is not clickable, only the overlay part is. */
|
|
34
|
-
pointer-events: none;
|
|
35
|
-
|
|
36
|
-
/* Remove tap highlight on touch devices. */
|
|
37
|
-
-webkit-tap-highlight-color: transparent;
|
|
38
|
-
|
|
39
|
-
/* CSS API for host */
|
|
40
|
-
--vaadin-overlay-viewport-bottom: 8px;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
:host([hidden]),
|
|
44
|
-
:host(:not([opened]):not([closing])),
|
|
45
|
-
:host(:not([opened]):not([closing])) [part='overlay'] {
|
|
46
|
-
display: none !important;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
[part='overlay'] {
|
|
50
|
-
background: var(--vaadin-overlay-background, var(--_vaadin-background));
|
|
51
|
-
border: var(--vaadin-overlay-border, 1px solid var(--_vaadin-border-color));
|
|
52
|
-
border-radius: var(--vaadin-overlay-border-radius, var(--_vaadin-radius-m));
|
|
53
|
-
box-shadow: var(--vaadin-overlay-box-shadow, 0 8px 24px -4px hsl(0 0 0 / 0.3));
|
|
54
|
-
box-sizing: border-box;
|
|
55
|
-
max-width: 100%;
|
|
56
|
-
overflow: auto;
|
|
57
|
-
overscroll-behavior: contain;
|
|
58
|
-
pointer-events: auto;
|
|
59
|
-
-webkit-tap-highlight-color: initial;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
[part='backdrop'] {
|
|
63
|
-
background: var(--vaadin-overlay-backdrop-background, rgba(0, 0, 0, 0.5));
|
|
64
|
-
content: '';
|
|
65
|
-
inset: 0;
|
|
66
|
-
pointer-events: auto;
|
|
67
|
-
position: fixed;
|
|
68
|
-
z-index: -1;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@media (forced-colors: active) {
|
|
72
|
-
[part='overlay'] {
|
|
73
|
-
border: 3px solid;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
[part='overlay']:focus-visible {
|
|
77
|
-
outline: var(--vaadin-focus-ring-width) solid;
|
|
78
|
-
outline-offset: 1px;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
`;
|