@vaadin/vaadin-overlay 23.1.0-rc2 → 23.1.1

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.1.0-rc2",
3
+ "version": "23.1.1",
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.1.0-rc2",
39
- "@vaadin/vaadin-lumo-styles": "23.1.0-rc2",
40
- "@vaadin/vaadin-material-styles": "23.1.0-rc2",
41
- "@vaadin/vaadin-themable-mixin": "23.1.0-rc2"
38
+ "@vaadin/component-base": "^23.1.1",
39
+ "@vaadin/vaadin-lumo-styles": "^23.1.1",
40
+ "@vaadin/vaadin-material-styles": "^23.1.1",
41
+ "@vaadin/vaadin-themable-mixin": "^23.1.1"
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.1.0-rc2",
47
- "@vaadin/radio-group": "23.1.0-rc2",
46
+ "@vaadin/button": "^23.1.1",
47
+ "@vaadin/radio-group": "^23.1.1",
48
48
  "@vaadin/testing-helpers": "^0.3.2",
49
- "@vaadin/text-field": "23.1.0-rc2",
49
+ "@vaadin/text-field": "^23.1.1",
50
50
  "lit": "^2.0.0",
51
51
  "sinon": "^13.0.2"
52
52
  },
53
- "gitHead": "154c6782c42145fed21e443559fbe2d781ad3ec7"
53
+ "gitHead": "390458d6519433a2dd502cef90da48e84573a275"
54
54
  }
@@ -3,6 +3,7 @@
3
3
  * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { getAncestorRootNodes } from '@vaadin/component-base/src/dom-utils.js';
6
7
 
7
8
  const PROP_NAMES_VERTICAL = {
8
9
  start: 'top',
@@ -79,26 +80,61 @@ export const PositionMixin = (superClass) =>
79
80
 
80
81
  static get observers() {
81
82
  return [
82
- '__positionSettingsChanged(positionTarget, horizontalAlign, verticalAlign, noHorizontalOverlap, noVerticalOverlap)',
83
- '__overlayOpenedChanged(opened)',
83
+ '__positionSettingsChanged(horizontalAlign, verticalAlign, noHorizontalOverlap, noVerticalOverlap)',
84
+ '__overlayOpenedChanged(opened, positionTarget)',
84
85
  ];
85
86
  }
86
87
 
87
88
  constructor() {
88
89
  super();
89
90
 
90
- this.__boundUpdatePosition = this._updatePosition.bind(this);
91
+ this._updatePosition = this._updatePosition.bind(this);
91
92
  }
92
93
 
93
- __overlayOpenedChanged(opened) {
94
- // Toggle the event listeners that cause the overlay to update its position
95
- ['scroll', 'resize'].forEach((eventName) => {
96
- if (opened) {
97
- window.addEventListener(eventName, this.__boundUpdatePosition);
98
- } else {
99
- window.removeEventListener(eventName, this.__boundUpdatePosition);
100
- }
94
+ /** @protected */
95
+ connectedCallback() {
96
+ super.connectedCallback();
97
+
98
+ if (this.opened) {
99
+ this.__addUpdatePositionEventListeners();
100
+ }
101
+ }
102
+
103
+ /** @protected */
104
+ disconnectedCallback() {
105
+ super.disconnectedCallback();
106
+ this.__removeUpdatePositionEventListeners();
107
+ }
108
+
109
+ /** @private */
110
+ __addUpdatePositionEventListeners() {
111
+ window.addEventListener('resize', this._updatePosition);
112
+
113
+ this.__positionTargetAncestorRootNodes = getAncestorRootNodes(this.positionTarget);
114
+ this.__positionTargetAncestorRootNodes.forEach((node) => {
115
+ node.addEventListener('scroll', this._updatePosition, true);
101
116
  });
117
+ }
118
+
119
+ /** @private */
120
+ __removeUpdatePositionEventListeners() {
121
+ window.removeEventListener('resize', this._updatePosition);
122
+
123
+ if (this.__positionTargetAncestorRootNodes) {
124
+ this.__positionTargetAncestorRootNodes.forEach((node) => {
125
+ node.removeEventListener('scroll', this._updatePosition, true);
126
+ });
127
+ this.__positionTargetAncestorRootNodes = null;
128
+ }
129
+ }
130
+
131
+ /** @private */
132
+ __overlayOpenedChanged(opened, positionTarget) {
133
+ this.__removeUpdatePositionEventListeners();
134
+
135
+ if (opened && positionTarget) {
136
+ this.__addUpdatePositionEventListeners();
137
+ }
102
138
 
103
139
  if (opened) {
104
140
  const computedStyle = getComputedStyle(this);