@vaadin/vaadin-overlay 23.3.0-alpha2 → 23.3.0-alpha3
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/vaadin-overlay",
|
|
3
|
-
"version": "23.3.0-
|
|
3
|
+
"version": "23.3.0-alpha3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -35,20 +35,20 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@polymer/polymer": "^3.0.0",
|
|
38
|
-
"@vaadin/component-base": "23.3.0-
|
|
39
|
-
"@vaadin/vaadin-lumo-styles": "23.3.0-
|
|
40
|
-
"@vaadin/vaadin-material-styles": "23.3.0-
|
|
41
|
-
"@vaadin/vaadin-themable-mixin": "23.3.0-
|
|
38
|
+
"@vaadin/component-base": "23.3.0-alpha3",
|
|
39
|
+
"@vaadin/vaadin-lumo-styles": "23.3.0-alpha3",
|
|
40
|
+
"@vaadin/vaadin-material-styles": "23.3.0-alpha3",
|
|
41
|
+
"@vaadin/vaadin-themable-mixin": "23.3.0-alpha3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@esm-bundle/chai": "^4.3.4",
|
|
45
45
|
"@polymer/iron-overlay-behavior": "^3.0.0",
|
|
46
|
-
"@vaadin/button": "23.3.0-
|
|
47
|
-
"@vaadin/radio-group": "23.3.0-
|
|
46
|
+
"@vaadin/button": "23.3.0-alpha3",
|
|
47
|
+
"@vaadin/radio-group": "23.3.0-alpha3",
|
|
48
48
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
49
|
-
"@vaadin/text-field": "23.3.0-
|
|
49
|
+
"@vaadin/text-field": "23.3.0-alpha3",
|
|
50
50
|
"lit": "^2.0.0",
|
|
51
51
|
"sinon": "^13.0.2"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "e86cd2abf3e28bade37711291331415d92c454ec"
|
|
54
54
|
}
|
|
@@ -98,6 +98,7 @@ export const PositionMixin = (superClass) =>
|
|
|
98
98
|
constructor() {
|
|
99
99
|
super();
|
|
100
100
|
|
|
101
|
+
this.__onScroll = this.__onScroll.bind(this);
|
|
101
102
|
this._updatePosition = this._updatePosition.bind(this);
|
|
102
103
|
}
|
|
103
104
|
|
|
@@ -122,7 +123,7 @@ export const PositionMixin = (superClass) =>
|
|
|
122
123
|
|
|
123
124
|
this.__positionTargetAncestorRootNodes = getAncestorRootNodes(this.positionTarget);
|
|
124
125
|
this.__positionTargetAncestorRootNodes.forEach((node) => {
|
|
125
|
-
node.addEventListener('scroll', this.
|
|
126
|
+
node.addEventListener('scroll', this.__onScroll, true);
|
|
126
127
|
});
|
|
127
128
|
}
|
|
128
129
|
|
|
@@ -132,7 +133,7 @@ export const PositionMixin = (superClass) =>
|
|
|
132
133
|
|
|
133
134
|
if (this.__positionTargetAncestorRootNodes) {
|
|
134
135
|
this.__positionTargetAncestorRootNodes.forEach((node) => {
|
|
135
|
-
node.removeEventListener('scroll', this.
|
|
136
|
+
node.removeEventListener('scroll', this.__onScroll, true);
|
|
136
137
|
});
|
|
137
138
|
this.__positionTargetAncestorRootNodes = null;
|
|
138
139
|
}
|
|
@@ -177,22 +178,19 @@ export const PositionMixin = (superClass) =>
|
|
|
177
178
|
this._updatePosition();
|
|
178
179
|
}
|
|
179
180
|
|
|
181
|
+
/** @private */
|
|
182
|
+
__onScroll(e) {
|
|
183
|
+
// If the scroll event occurred inside the overlay, ignore it.
|
|
184
|
+
if (!this.contains(e.target)) {
|
|
185
|
+
this._updatePosition();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
180
189
|
_updatePosition() {
|
|
181
190
|
if (!this.positionTarget || !this.opened) {
|
|
182
191
|
return;
|
|
183
192
|
}
|
|
184
193
|
|
|
185
|
-
// Cleanup styles to avoid wrong values after window resize
|
|
186
|
-
// See https://github.com/vaadin/web-components/issues/4604
|
|
187
|
-
Object.assign(this.style, {
|
|
188
|
-
top: '',
|
|
189
|
-
right: '',
|
|
190
|
-
bottom: '',
|
|
191
|
-
left: '',
|
|
192
|
-
justifyContent: '',
|
|
193
|
-
alignItems: '',
|
|
194
|
-
});
|
|
195
|
-
|
|
196
194
|
const targetRect = this.positionTarget.getBoundingClientRect();
|
|
197
195
|
|
|
198
196
|
// Detect the desired alignment and update the layout accordingly
|
|
@@ -292,6 +290,44 @@ export const PositionMixin = (superClass) =>
|
|
|
292
290
|
return defaultAlignStart === shouldGoToDefaultSide;
|
|
293
291
|
}
|
|
294
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Returns an adjusted value after resizing the browser window,
|
|
295
|
+
* to avoid wrong calculations when e.g. previously set `bottom`
|
|
296
|
+
* CSS property value is larger than the updated viewport height.
|
|
297
|
+
* See https://github.com/vaadin/web-components/issues/4604
|
|
298
|
+
*/
|
|
299
|
+
__adjustBottomProperty(cssPropNameToSet, propNames, currentValue) {
|
|
300
|
+
let adjustedProp;
|
|
301
|
+
|
|
302
|
+
if (cssPropNameToSet === propNames.end) {
|
|
303
|
+
// Adjust horizontally
|
|
304
|
+
if (propNames.end === PROP_NAMES_VERTICAL.end) {
|
|
305
|
+
const viewportHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
|
|
306
|
+
|
|
307
|
+
if (currentValue > viewportHeight && this.__oldViewportHeight) {
|
|
308
|
+
const heightDiff = this.__oldViewportHeight - viewportHeight;
|
|
309
|
+
adjustedProp = currentValue - heightDiff;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
this.__oldViewportHeight = viewportHeight;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Adjust vertically
|
|
316
|
+
if (propNames.end === PROP_NAMES_HORIZONTAL.end) {
|
|
317
|
+
const viewportWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
|
|
318
|
+
|
|
319
|
+
if (currentValue > viewportWidth && this.__oldViewportWidth) {
|
|
320
|
+
const widthDiff = this.__oldViewportWidth - viewportWidth;
|
|
321
|
+
adjustedProp = currentValue - widthDiff;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
this.__oldViewportWidth = viewportWidth;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return adjustedProp;
|
|
329
|
+
}
|
|
330
|
+
|
|
295
331
|
/**
|
|
296
332
|
* Returns an object with CSS position properties to set,
|
|
297
333
|
* e.g. { top: "100px" }
|
|
@@ -299,15 +335,22 @@ export const PositionMixin = (superClass) =>
|
|
|
299
335
|
// eslint-disable-next-line max-params
|
|
300
336
|
__calculatePositionInOneDimension(targetRect, overlayRect, noOverlap, propNames, overlay, shouldAlignStart) {
|
|
301
337
|
const cssPropNameToSet = shouldAlignStart ? propNames.start : propNames.end;
|
|
338
|
+
const cssPropNameToClear = shouldAlignStart ? propNames.end : propNames.start;
|
|
302
339
|
|
|
303
340
|
const currentValue = parseFloat(overlay.style[cssPropNameToSet] || getComputedStyle(overlay)[cssPropNameToSet]);
|
|
341
|
+
const adjustedValue = this.__adjustBottomProperty(cssPropNameToSet, propNames, currentValue);
|
|
304
342
|
|
|
305
343
|
const diff =
|
|
306
344
|
overlayRect[shouldAlignStart ? propNames.start : propNames.end] -
|
|
307
345
|
targetRect[noOverlap === shouldAlignStart ? propNames.end : propNames.start];
|
|
308
346
|
|
|
347
|
+
const valueToSet = adjustedValue
|
|
348
|
+
? `${adjustedValue}px`
|
|
349
|
+
: `${currentValue + diff * (shouldAlignStart ? -1 : 1)}px`;
|
|
350
|
+
|
|
309
351
|
return {
|
|
310
|
-
[cssPropNameToSet]:
|
|
352
|
+
[cssPropNameToSet]: valueToSet,
|
|
353
|
+
[cssPropNameToClear]: '',
|
|
311
354
|
};
|
|
312
355
|
}
|
|
313
356
|
};
|