@vaadin/dialog 25.1.0-alpha9 → 25.1.0-beta2

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/dialog",
3
- "version": "25.1.0-alpha9",
3
+ "version": "25.1.0-beta2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -37,19 +37,19 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@open-wc/dedupe-mixin": "^1.3.0",
40
- "@vaadin/component-base": "25.1.0-alpha9",
41
- "@vaadin/lit-renderer": "25.1.0-alpha9",
42
- "@vaadin/overlay": "25.1.0-alpha9",
43
- "@vaadin/vaadin-themable-mixin": "25.1.0-alpha9",
40
+ "@vaadin/component-base": "25.1.0-beta2",
41
+ "@vaadin/lit-renderer": "25.1.0-beta2",
42
+ "@vaadin/overlay": "25.1.0-beta2",
43
+ "@vaadin/vaadin-themable-mixin": "25.1.0-beta2",
44
44
  "lit": "^3.0.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@vaadin/a11y-base": "25.1.0-alpha9",
48
- "@vaadin/aura": "25.1.0-alpha9",
49
- "@vaadin/chai-plugins": "25.1.0-alpha9",
50
- "@vaadin/test-runner-commands": "25.1.0-alpha9",
47
+ "@vaadin/a11y-base": "25.1.0-beta2",
48
+ "@vaadin/aura": "25.1.0-beta2",
49
+ "@vaadin/chai-plugins": "25.1.0-beta2",
50
+ "@vaadin/test-runner-commands": "25.1.0-beta2",
51
51
  "@vaadin/testing-helpers": "^2.0.0",
52
- "@vaadin/vaadin-lumo-styles": "25.1.0-alpha9",
52
+ "@vaadin/vaadin-lumo-styles": "25.1.0-beta2",
53
53
  "sinon": "^21.0.0"
54
54
  },
55
55
  "customElements": "custom-elements.json",
@@ -57,5 +57,5 @@
57
57
  "web-types.json",
58
58
  "web-types.lit.json"
59
59
  ],
60
- "gitHead": "ef432311376ba3dac4233cb23d393a49a425e0a4"
60
+ "gitHead": "ffbedbae08a5160d13bcd1c6fcaa328df5103a05"
61
61
  }
@@ -124,6 +124,9 @@ const dialogResizableOverlay = css`
124
124
 
125
125
  :host([has-bounds-set]) [part='overlay'] {
126
126
  min-width: 0;
127
+ }
128
+
129
+ :host([has-bounds-set]:not([keep-in-viewport])) [part='overlay'] {
127
130
  max-width: none;
128
131
  max-height: none;
129
132
  }
@@ -138,7 +141,7 @@ const dialogResizableOverlay = css`
138
141
  }
139
142
 
140
143
  [part='header'],
141
- :host(:not([has-header])) [part='content'] {
144
+ :host(:not([has-title], [has-header])) [part='content'] {
142
145
  border-top-left-radius: inherit;
143
146
  border-top-right-radius: inherit;
144
147
  }
@@ -63,4 +63,14 @@ export declare class DialogBaseMixinClass {
63
63
  * additional spacing, which can be overridden by the theme.
64
64
  */
65
65
  left: string;
66
+
67
+ /**
68
+ * Set to true to prevent the dialog from moving outside the viewport bounds.
69
+ * When enabled, all four edges of the dialog will remain visible, for example
70
+ * when dragging the dialog or when the viewport is resized. Note that the
71
+ * dialog will also adjust any programmatically configured size and position
72
+ * so that it stays within the viewport.
73
+ * @attr {boolean} keep-in-viewport
74
+ */
75
+ keepInViewport: boolean;
66
76
  }
@@ -13,7 +13,6 @@ export const DialogBaseMixin = (superClass) =>
13
13
  return {
14
14
  /**
15
15
  * True if the dialog is visible and available for interaction.
16
- * @type {boolean}
17
16
  */
18
17
  opened: {
19
18
  type: Boolean,
@@ -26,7 +25,6 @@ export const DialogBaseMixin = (superClass) =>
26
25
  /**
27
26
  * Set to true to disable closing dialog on outside click
28
27
  * @attr {boolean} no-close-on-outside-click
29
- * @type {boolean}
30
28
  */
31
29
  noCloseOnOutsideClick: {
32
30
  type: Boolean,
@@ -36,7 +34,6 @@ export const DialogBaseMixin = (superClass) =>
36
34
  /**
37
35
  * Set to true to disable closing dialog on Escape press
38
36
  * @attr {boolean} no-close-on-esc
39
- * @type {boolean}
40
37
  */
41
38
  noCloseOnEsc: {
42
39
  type: Boolean,
@@ -45,7 +42,6 @@ export const DialogBaseMixin = (superClass) =>
45
42
 
46
43
  /**
47
44
  * Set to true to remove backdrop and allow click events on background elements.
48
- * @type {boolean}
49
45
  */
50
46
  modeless: {
51
47
  type: Boolean,
@@ -55,7 +51,6 @@ export const DialogBaseMixin = (superClass) =>
55
51
  /**
56
52
  * Set to true to disable focus trapping.
57
53
  * @attr {boolean} no-focus-trap
58
- * @type {boolean}
59
54
  */
60
55
  noFocusTrap: {
61
56
  type: Boolean,
@@ -93,6 +88,20 @@ export const DialogBaseMixin = (superClass) =>
93
88
  overlayRole: {
94
89
  type: String,
95
90
  },
91
+
92
+ /**
93
+ * Set to true to prevent the dialog from moving outside the viewport bounds.
94
+ * When enabled, all four edges of the dialog will remain visible, for example
95
+ * when dragging the dialog or when the viewport is resized. Note that the
96
+ * dialog will also adjust any programmatically configured size and position
97
+ * so that it stays within the viewport.
98
+ * @attr {boolean} keep-in-viewport
99
+ */
100
+ keepInViewport: {
101
+ type: Boolean,
102
+ value: false,
103
+ reflectToAttribute: true,
104
+ },
96
105
  };
97
106
  }
98
107
 
@@ -21,12 +21,4 @@ export declare class DialogDraggableMixinClass {
21
21
  * "`draggable-leaf-only`" class name.
22
22
  */
23
23
  draggable: boolean;
24
-
25
- /**
26
- * Set to true to prevent dragging the dialog outside the viewport bounds.
27
- * When enabled, all four edges of the dialog will remain visible during dragging.
28
- * The dialog may still become partially hidden when the viewport is resized.
29
- * @attr {boolean} keep-in-viewport
30
- */
31
- keepInViewport: boolean;
32
24
  }
@@ -23,7 +23,6 @@ export const DialogDraggableMixin = (superClass) =>
23
23
  * but still have its children non-draggable (by default), mark it with
24
24
  * "`draggable-leaf-only`" class name.
25
25
  *
26
- * @type {boolean}
27
26
  */
28
27
  draggable: {
29
28
  type: Boolean,
@@ -31,19 +30,6 @@ export const DialogDraggableMixin = (superClass) =>
31
30
  reflectToAttribute: true,
32
31
  },
33
32
 
34
- /**
35
- * Set to true to prevent dragging the dialog outside the viewport bounds.
36
- * When enabled, all four edges of the dialog will remain visible during dragging.
37
- * The dialog may still become partially hidden when the viewport is resized.
38
- * @attr {boolean} keep-in-viewport
39
- * @type {boolean}
40
- */
41
- keepInViewport: {
42
- type: Boolean,
43
- value: false,
44
- reflectToAttribute: true,
45
- },
46
-
47
33
  /** @private */
48
34
  _touchDevice: {
49
35
  type: Boolean,
@@ -132,16 +118,14 @@ export const DialogDraggableMixin = (superClass) =>
132
118
  let left = this._originalBounds.left + (event.pageX - this._originalMouseCoords.left);
133
119
 
134
120
  if (this.keepInViewport) {
121
+ // Constrain the dialog position so that it stays within the overlay host bounds,
122
+ // respecting the `--vaadin-overlay-viewport-inset` (offset from the viewport edges).
135
123
  const { width, height } = this._originalBounds;
136
- // Get the overlay container's position to account for its offset from the viewport
137
- const containerBounds = this.$.overlay.getBoundingClientRect();
138
- // Calculate bounds so the dialog's visual edges stay within the viewport
139
- const minLeft = -containerBounds.left;
140
- const maxLeft = window.innerWidth - containerBounds.left - width;
141
- const minTop = -containerBounds.top;
142
- const maxTop = window.innerHeight - containerBounds.top - height;
143
- left = Math.max(minLeft, Math.min(left, maxLeft));
144
- top = Math.max(minTop, Math.min(top, maxTop));
124
+ const overlayHostBounds = this.$.overlay.getBoundingClientRect();
125
+ const maxLeft = overlayHostBounds.right - overlayHostBounds.left - width;
126
+ const maxTop = overlayHostBounds.bottom - overlayHostBounds.top - height;
127
+ left = Math.max(0, Math.min(left, maxLeft));
128
+ top = Math.max(0, Math.min(top, maxTop));
145
129
  }
146
130
 
147
131
  this.top = top;
@@ -25,6 +25,11 @@ export declare class DialogOverlayMixinClass {
25
25
  */
26
26
  headerTitle: string;
27
27
 
28
+ /**
29
+ * Whether to keep the overlay within the viewport.
30
+ */
31
+ keepInViewport: boolean;
32
+
28
33
  /**
29
34
  * Custom function for rendering the dialog header.
30
35
  */
@@ -35,6 +35,14 @@ export const DialogOverlayMixin = (superClass) =>
35
35
  footerRenderer: {
36
36
  type: Object,
37
37
  },
38
+
39
+ /**
40
+ * Whether to keep the overlay within the viewport.
41
+ */
42
+ keepInViewport: {
43
+ type: Boolean,
44
+ reflectToAttribute: true,
45
+ },
38
46
  };
39
47
  }
40
48
 
@@ -77,6 +85,7 @@ export const DialogOverlayMixin = (superClass) =>
77
85
  // Update overflow attribute on resize
78
86
  this.__resizeObserver = new ResizeObserver(() => {
79
87
  requestAnimationFrame(() => {
88
+ this.__adjustPosition();
80
89
  this.__updateOverflow();
81
90
  });
82
91
  });
@@ -104,6 +113,20 @@ export const DialogOverlayMixin = (superClass) =>
104
113
  setOverlayStateAttribute(this, 'has-footer', currentNodes.length > 0);
105
114
  this.__updateOverflow();
106
115
  });
116
+
117
+ this.__handleWindowResize = this.__handleWindowResize.bind(this);
118
+ }
119
+
120
+ updated(props) {
121
+ super.updated(props);
122
+
123
+ if (props.has('opened') || props.has('keepInViewport')) {
124
+ if (this.opened && this.keepInViewport) {
125
+ window.addEventListener('resize', this.__handleWindowResize);
126
+ } else {
127
+ window.removeEventListener('resize', this.__handleWindowResize);
128
+ }
129
+ }
107
130
  }
108
131
 
109
132
  /** @private */
@@ -233,6 +256,15 @@ export const DialogOverlayMixin = (superClass) =>
233
256
  return { top, left, width, height };
234
257
  }
235
258
 
259
+ /**
260
+ * Override method from OverlayMixin to adjust the position of the overlay if `keepInViewport` is true.
261
+ * @override
262
+ */
263
+ setBounds(bounds, absolute = true) {
264
+ super.setBounds(bounds, absolute);
265
+ this.__adjustPosition();
266
+ }
267
+
236
268
  /** @private */
237
269
  __updateOverflow() {
238
270
  let overflow = '';
@@ -254,4 +286,45 @@ export const DialogOverlayMixin = (superClass) =>
254
286
  setOverlayStateAttribute(this, 'overflow', null);
255
287
  }
256
288
  }
289
+
290
+ /** @private */
291
+ __handleWindowResize() {
292
+ this.__adjustPosition();
293
+ }
294
+
295
+ /**
296
+ * Adjusts the position of the overlay to keep it within the viewport if `keepInViewport` is true.
297
+ * @private
298
+ */
299
+ __adjustPosition() {
300
+ if (!this.opened || !this.keepInViewport) {
301
+ return;
302
+ }
303
+
304
+ // Centered dialogs do not use absolute positioning and automatically adjust their position / size to fit the viewport
305
+ const style = getComputedStyle(this.$.overlay);
306
+ if (style.position !== 'absolute') {
307
+ return;
308
+ }
309
+
310
+ const overlayHostBounds = this.getBoundingClientRect();
311
+ const bounds = this.getBounds();
312
+ // Prefer dimensions from getComputedStyle, as bounding rect is affected
313
+ // by scale transform applied by opening animation in Lumo
314
+ const width = parseFloat(style.width) || bounds.width;
315
+ const height = parseFloat(style.height) || bounds.height;
316
+
317
+ const maxLeft = overlayHostBounds.right - overlayHostBounds.left - width;
318
+ const maxTop = overlayHostBounds.bottom - overlayHostBounds.top - height;
319
+
320
+ if (bounds.left > maxLeft || bounds.top > maxTop) {
321
+ const left = Math.max(0, Math.min(bounds.left, maxLeft));
322
+ const top = Math.max(0, Math.min(bounds.top, maxTop));
323
+
324
+ Object.assign(this.$.overlay.style, {
325
+ left: `${left}px`,
326
+ top: `${top}px`,
327
+ });
328
+ }
329
+ }
257
330
  };
@@ -13,7 +13,6 @@ export const DialogResizableMixin = (superClass) =>
13
13
  return {
14
14
  /**
15
15
  * Set to true to enable resizing the dialog by dragging the corners and edges.
16
- * @type {boolean}
17
16
  */
18
17
  resizable: {
19
18
  type: Boolean,
@@ -148,6 +148,7 @@ class Dialog extends DialogSizeMixin(
148
148
  .renderer="${this.renderer}"
149
149
  .headerRenderer="${this.headerRenderer}"
150
150
  .footerRenderer="${this.footerRenderer}"
151
+ .keepInViewport="${this.keepInViewport}"
151
152
  @opened-changed="${this._onOverlayOpened}"
152
153
  @mousedown="${this._bringOverlayToFront}"
153
154
  @touchstart="${this._bringOverlayToFront}"
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/dialog",
4
- "version": "25.1.0-alpha9",
4
+ "version": "25.1.0-beta2",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -15,7 +15,9 @@
15
15
  "description": "Set to true to enable repositioning the dialog by clicking and dragging.\n\nBy default, only the overlay area can be used to drag the element. But,\na child element can be marked as a draggable area by adding a\n\"`draggable`\" class to it, this will by default make all of its children draggable also.\nIf you want a child element to be draggable\nbut still have its children non-draggable (by default), mark it with\n\"`draggable-leaf-only`\" class name.",
16
16
  "value": {
17
17
  "type": [
18
- "boolean"
18
+ "boolean",
19
+ "null",
20
+ "undefined"
19
21
  ]
20
22
  }
21
23
  },
@@ -43,10 +45,12 @@
43
45
  },
44
46
  {
45
47
  "name": "keep-in-viewport",
46
- "description": "Set to true to prevent dragging the dialog outside the viewport bounds.\nWhen enabled, all four edges of the dialog will remain visible during dragging.\nThe dialog may still become partially hidden when the viewport is resized.",
48
+ "description": "Set to true to prevent the dialog from moving outside the viewport bounds.\nWhen enabled, all four edges of the dialog will remain visible, for example\nwhen dragging the dialog or when the viewport is resized. Note that the\ndialog will also adjust any programmatically configured size and position\nso that it stays within the viewport.",
47
49
  "value": {
48
50
  "type": [
49
- "boolean"
51
+ "boolean",
52
+ "null",
53
+ "undefined"
50
54
  ]
51
55
  }
52
56
  },
@@ -66,7 +70,9 @@
66
70
  "description": "Set to true to remove backdrop and allow click events on background elements.",
67
71
  "value": {
68
72
  "type": [
69
- "boolean"
73
+ "boolean",
74
+ "null",
75
+ "undefined"
70
76
  ]
71
77
  }
72
78
  },
@@ -75,7 +81,9 @@
75
81
  "description": "Set to true to disable closing dialog on Escape press",
76
82
  "value": {
77
83
  "type": [
78
- "boolean"
84
+ "boolean",
85
+ "null",
86
+ "undefined"
79
87
  ]
80
88
  }
81
89
  },
@@ -84,7 +92,9 @@
84
92
  "description": "Set to true to disable closing dialog on outside click",
85
93
  "value": {
86
94
  "type": [
87
- "boolean"
95
+ "boolean",
96
+ "null",
97
+ "undefined"
88
98
  ]
89
99
  }
90
100
  },
@@ -93,7 +103,9 @@
93
103
  "description": "Set to true to disable focus trapping.",
94
104
  "value": {
95
105
  "type": [
96
- "boolean"
106
+ "boolean",
107
+ "null",
108
+ "undefined"
97
109
  ]
98
110
  }
99
111
  },
@@ -102,7 +114,9 @@
102
114
  "description": "True if the dialog is visible and available for interaction.",
103
115
  "value": {
104
116
  "type": [
105
- "boolean"
117
+ "boolean",
118
+ "null",
119
+ "undefined"
106
120
  ]
107
121
  }
108
122
  },
@@ -122,7 +136,9 @@
122
136
  "description": "Set to true to enable resizing the dialog by dragging the corners and edges.",
123
137
  "value": {
124
138
  "type": [
125
- "boolean"
139
+ "boolean",
140
+ "null",
141
+ "undefined"
126
142
  ]
127
143
  }
128
144
  },
@@ -167,7 +183,9 @@
167
183
  "description": "Set to true to enable repositioning the dialog by clicking and dragging.\n\nBy default, only the overlay area can be used to drag the element. But,\na child element can be marked as a draggable area by adding a\n\"`draggable`\" class to it, this will by default make all of its children draggable also.\nIf you want a child element to be draggable\nbut still have its children non-draggable (by default), mark it with\n\"`draggable-leaf-only`\" class name.",
168
184
  "value": {
169
185
  "type": [
170
- "boolean"
186
+ "boolean",
187
+ "null",
188
+ "undefined"
171
189
  ]
172
190
  }
173
191
  },
@@ -215,10 +233,12 @@
215
233
  },
216
234
  {
217
235
  "name": "keepInViewport",
218
- "description": "Set to true to prevent dragging the dialog outside the viewport bounds.\nWhen enabled, all four edges of the dialog will remain visible during dragging.\nThe dialog may still become partially hidden when the viewport is resized.",
236
+ "description": "Set to true to prevent the dialog from moving outside the viewport bounds.\nWhen enabled, all four edges of the dialog will remain visible, for example\nwhen dragging the dialog or when the viewport is resized. Note that the\ndialog will also adjust any programmatically configured size and position\nso that it stays within the viewport.",
219
237
  "value": {
220
238
  "type": [
221
- "boolean"
239
+ "boolean",
240
+ "null",
241
+ "undefined"
222
242
  ]
223
243
  }
224
244
  },
@@ -238,7 +258,9 @@
238
258
  "description": "Set to true to remove backdrop and allow click events on background elements.",
239
259
  "value": {
240
260
  "type": [
241
- "boolean"
261
+ "boolean",
262
+ "null",
263
+ "undefined"
242
264
  ]
243
265
  }
244
266
  },
@@ -247,7 +269,9 @@
247
269
  "description": "Set to true to disable closing dialog on Escape press",
248
270
  "value": {
249
271
  "type": [
250
- "boolean"
272
+ "boolean",
273
+ "null",
274
+ "undefined"
251
275
  ]
252
276
  }
253
277
  },
@@ -256,7 +280,9 @@
256
280
  "description": "Set to true to disable closing dialog on outside click",
257
281
  "value": {
258
282
  "type": [
259
- "boolean"
283
+ "boolean",
284
+ "null",
285
+ "undefined"
260
286
  ]
261
287
  }
262
288
  },
@@ -265,7 +291,9 @@
265
291
  "description": "Set to true to disable focus trapping.",
266
292
  "value": {
267
293
  "type": [
268
- "boolean"
294
+ "boolean",
295
+ "null",
296
+ "undefined"
269
297
  ]
270
298
  }
271
299
  },
@@ -274,7 +302,9 @@
274
302
  "description": "True if the dialog is visible and available for interaction.",
275
303
  "value": {
276
304
  "type": [
277
- "boolean"
305
+ "boolean",
306
+ "null",
307
+ "undefined"
278
308
  ]
279
309
  }
280
310
  },
@@ -304,7 +334,9 @@
304
334
  "description": "Set to true to enable resizing the dialog by dragging the corners and edges.",
305
335
  "value": {
306
336
  "type": [
307
- "boolean"
337
+ "boolean",
338
+ "null",
339
+ "undefined"
308
340
  ]
309
341
  }
310
342
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/dialog",
4
- "version": "25.1.0-alpha9",
4
+ "version": "25.1.0-beta2",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  {
30
30
  "name": "?keepInViewport",
31
- "description": "Set to true to prevent dragging the dialog outside the viewport bounds.\nWhen enabled, all four edges of the dialog will remain visible during dragging.\nThe dialog may still become partially hidden when the viewport is resized.",
31
+ "description": "Set to true to prevent the dialog from moving outside the viewport bounds.\nWhen enabled, all four edges of the dialog will remain visible, for example\nwhen dragging the dialog or when the viewport is resized. Note that the\ndialog will also adjust any programmatically configured size and position\nso that it stays within the viewport.",
32
32
  "value": {
33
33
  "kind": "expression"
34
34
  }