@vaadin/master-detail-layout 24.8.0-alpha14 → 24.8.0-alpha16

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/master-detail-layout",
3
- "version": "24.8.0-alpha14",
3
+ "version": "24.8.0-alpha16",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -34,15 +34,15 @@
34
34
  "web-component"
35
35
  ],
36
36
  "dependencies": {
37
- "@vaadin/a11y-base": "24.8.0-alpha14",
38
- "@vaadin/component-base": "24.8.0-alpha14",
39
- "@vaadin/vaadin-lumo-styles": "24.8.0-alpha14",
40
- "@vaadin/vaadin-material-styles": "24.8.0-alpha14",
41
- "@vaadin/vaadin-themable-mixin": "24.8.0-alpha14",
37
+ "@vaadin/a11y-base": "24.8.0-alpha16",
38
+ "@vaadin/component-base": "24.8.0-alpha16",
39
+ "@vaadin/vaadin-lumo-styles": "24.8.0-alpha16",
40
+ "@vaadin/vaadin-material-styles": "24.8.0-alpha16",
41
+ "@vaadin/vaadin-themable-mixin": "24.8.0-alpha16",
42
42
  "lit": "^3.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@vaadin/chai-plugins": "24.8.0-alpha14",
45
+ "@vaadin/chai-plugins": "24.8.0-alpha16",
46
46
  "@vaadin/testing-helpers": "^1.1.0",
47
47
  "sinon": "^18.0.0"
48
48
  },
@@ -50,5 +50,5 @@
50
50
  "web-types.json",
51
51
  "web-types.lit.json"
52
52
  ],
53
- "gitHead": "c8a33608cf1ab377529afd0650360e349886384c"
53
+ "gitHead": "ac26cb142cd3d6374423ca699677d47557399d47"
54
54
  }
@@ -8,6 +8,14 @@ import { ResizeMixin } from '@vaadin/component-base/src/resize-mixin.js';
8
8
  import { SlotStylesMixin } from '@vaadin/component-base/src/slot-styles-mixin.js';
9
9
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
10
 
11
+ export interface MasterDetailLayoutCustomEventMap {
12
+ 'backdrop-click': Event;
13
+
14
+ 'detail-escape-press': Event;
15
+ }
16
+
17
+ export interface MasterDetailLayoutEventMap extends HTMLElementEventMap, MasterDetailLayoutCustomEventMap {}
18
+
11
19
  /**
12
20
  * `<vaadin-master-detail-layout>` is a web component for building UIs with a master
13
21
  * (or primary) area and a detail (or secondary) area that is displayed next to, or
@@ -41,6 +49,9 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
41
49
  * `stack` | Set when the layout is using the stack mode.
42
50
  *
43
51
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
52
+ *
53
+ * @fires {CustomEvent} backdrop-click - Fired when the user clicks the backdrop in the overlay mode.
54
+ * @fires {CustomEvent} detail-escape-press - Fired when the user presses Escape in the detail area.
44
55
  */
45
56
  declare class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ThemableMixin(ElementMixin(HTMLElement)))) {
46
57
  /**
@@ -96,6 +107,9 @@ declare class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ThemableMix
96
107
  * there is enough space for master and detail to be shown next to
97
108
  * each other using the default (split) mode.
98
109
  *
110
+ * In order to enforce the stack mode, use this property together with
111
+ * `stackOverlay` property and set both to `true`.
112
+ *
99
113
  * @attr {boolean} force-overlay
100
114
  */
101
115
  forceOverlay: boolean;
@@ -109,12 +123,15 @@ declare class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ThemableMix
109
123
  containment: 'layout' | 'viewport';
110
124
 
111
125
  /**
112
- * The threshold (in CSS length units) at which the layout switches to
113
- * the "stack" mode, making detail area fully cover the master area.
126
+ * When true, the layout in the overlay mode is rendered as a "stack",
127
+ * making detail area fully cover the master area.
128
+ *
129
+ * In order to enforce the stack mode, use this property together with
130
+ * `forceOverlay` property and set both to `true`.
114
131
  *
115
132
  * @attr {string} stack-threshold
116
133
  */
117
- stackThreshold: string | null | undefined;
134
+ stackOverlay: boolean;
118
135
 
119
136
  /**
120
137
  * When true, the layout does not use animated transitions for the detail area.
@@ -122,6 +139,18 @@ declare class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ThemableMix
122
139
  * @attr {boolean} no-animation
123
140
  */
124
141
  noAnimation: boolean;
142
+
143
+ addEventListener<K extends keyof MasterDetailLayoutEventMap>(
144
+ type: K,
145
+ listener: (this: MasterDetailLayout, ev: MasterDetailLayoutEventMap[K]) => void,
146
+ options?: AddEventListenerOptions | boolean,
147
+ ): void;
148
+
149
+ removeEventListener<K extends keyof MasterDetailLayoutEventMap>(
150
+ type: K,
151
+ listener: (this: MasterDetailLayout, ev: MasterDetailLayoutEventMap[K]) => void,
152
+ options?: EventListenerOptions | boolean,
153
+ ): void;
125
154
  }
126
155
 
127
156
  declare global {
@@ -47,6 +47,9 @@ import { transitionStyles } from './vaadin-master-detail-layout-transition-style
47
47
  *
48
48
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
49
49
  *
50
+ * @fires {CustomEvent} backdrop-click - Fired when the user clicks the backdrop in the overlay mode.
51
+ * @fires {CustomEvent} detail-escape-press - Fired when the user presses Escape in the detail area.
52
+ *
50
53
  * @customElement
51
54
  * @extends HTMLElement
52
55
  * @mixes ThemableMixin
@@ -207,10 +210,6 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
207
210
  :host([stack]) [part='detail'] {
208
211
  inset: 0;
209
212
  }
210
-
211
- [part='master']::before {
212
- background-position-y: var(--_stack-threshold);
213
- }
214
213
  `;
215
214
  }
216
215
 
@@ -291,6 +290,9 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
291
290
  * there is enough space for master and detail to be shown next to
292
291
  * each other using the default (split) mode.
293
292
  *
293
+ * In order to enforce the stack mode, use this property together with
294
+ * `stackOverlay` property and set both to `true`.
295
+ *
294
296
  * @attr {boolean} force-overlay
295
297
  */
296
298
  forceOverlay: {
@@ -314,14 +316,18 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
314
316
  },
315
317
 
316
318
  /**
317
- * The threshold (in CSS length units) at which the layout switches to
318
- * the "stack" mode, making detail area fully cover the master area.
319
+ * When true, the layout in the overlay mode is rendered as a "stack",
320
+ * making detail area fully cover the master area.
321
+ *
322
+ * In order to enforce the stack mode, use this property together with
323
+ * `forceOverlay` property and set both to `true`.
319
324
  *
320
325
  * @attr {string} stack-threshold
321
326
  */
322
- stackThreshold: {
323
- type: String,
324
- observer: '__stackThresholdChanged',
327
+ stackOverlay: {
328
+ type: Boolean,
329
+ value: false,
330
+ observer: '__stackOverlayChanged',
325
331
  sync: true,
326
332
  },
327
333
 
@@ -337,7 +343,6 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
337
343
 
338
344
  /**
339
345
  * When true, the component uses the overlay mode. This property is read-only.
340
- * In order to enforce the overlay mode, use `forceOverlay` property.
341
346
  * @protected
342
347
  */
343
348
  _overlay: {
@@ -349,7 +354,6 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
349
354
 
350
355
  /**
351
356
  * When true, the component uses the stack mode. This property is read-only.
352
- * In order to enforce the stack mode, use `stackThreshold` property.
353
357
  * @protected
354
358
  */
355
359
  _stack: {
@@ -384,7 +388,7 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
384
388
  /** @protected */
385
389
  render() {
386
390
  return html`
387
- <div part="backdrop"></div>
391
+ <div part="backdrop" @click="${this.__onBackdropClick}"></div>
388
392
  <div id="master" part="master" ?inert="${this._hasDetail && this._overlay && this.containment === 'layout'}">
389
393
  <slot></slot>
390
394
  </div>
@@ -393,6 +397,7 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
393
397
  part="detail"
394
398
  role="${this._overlay || this._stack ? 'dialog' : nothing}"
395
399
  aria-modal="${this._overlay && this.containment === 'viewport' ? 'true' : nothing}"
400
+ @keydown="${this.__onDetailKeydown}"
396
401
  >
397
402
  <slot name="detail" @slotchange="${this.__onDetailSlotChange}"></slot>
398
403
  </div>
@@ -416,6 +421,20 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
416
421
  }
417
422
  }
418
423
 
424
+ /** @private */
425
+ __onBackdropClick() {
426
+ this.dispatchEvent(new CustomEvent('backdrop-click'));
427
+ }
428
+
429
+ /** @private */
430
+ __onDetailKeydown(event) {
431
+ if (event.key === 'Escape') {
432
+ // Prevent firing on parent layout when using nested layouts
433
+ event.stopPropagation();
434
+ this.dispatchEvent(new CustomEvent('detail-escape-press'));
435
+ }
436
+ }
437
+
419
438
  /**
420
439
  * @protected
421
440
  * @override
@@ -463,14 +482,8 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
463
482
  }
464
483
 
465
484
  /** @private */
466
- __stackThresholdChanged(threshold, oldThreshold) {
467
- if (threshold || oldThreshold) {
468
- if (threshold) {
469
- this.$.master.style.setProperty('--_stack-threshold', threshold);
470
- } else {
471
- this.$.master.style.removeProperty('--_stack-threshold');
472
- }
473
-
485
+ __stackOverlayChanged(stackOverlay, oldStackOverlay) {
486
+ if (stackOverlay || oldStackOverlay) {
474
487
  this.__detectLayoutMode();
475
488
  }
476
489
  }
@@ -486,30 +499,25 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
486
499
  this.toggleAttribute(`has-${prop}`, !!size);
487
500
  }
488
501
 
502
+ /** @private */
503
+ __setOverlayMode(value) {
504
+ if (this.stackOverlay) {
505
+ this._stack = value;
506
+ } else {
507
+ this._overlay = value;
508
+ }
509
+ }
510
+
489
511
  /** @private */
490
512
  __detectLayoutMode() {
491
513
  this._overlay = false;
492
514
  this._stack = false;
493
515
 
494
516
  if (this.forceOverlay) {
495
- this._overlay = true;
517
+ this.__setOverlayMode(true);
496
518
  return;
497
519
  }
498
520
 
499
- if (this.stackThreshold != null) {
500
- // Set stack to true to disable masterMinSize and detailMinSize
501
- // that would affect size measurements below when in split mode
502
- this._stack = true;
503
-
504
- const threshold = this.__getStackThresholdInPixels();
505
- const size = this.orientation === 'vertical' ? this.offsetHeight : this.offsetWidth;
506
- if (size > threshold) {
507
- this._stack = false;
508
- } else {
509
- return;
510
- }
511
- }
512
-
513
521
  if (!this._hasDetail) {
514
522
  return;
515
523
  }
@@ -535,38 +543,28 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
535
543
 
536
544
  // If the combined minimum size of both the master and the detail content
537
545
  // exceeds the size of the layout, the layout changes to the overlay mode.
538
- this._overlay = this.offsetWidth < masterWidth + detailWidth;
546
+ this.__setOverlayMode(this.offsetWidth < masterWidth + detailWidth);
539
547
 
540
548
  // Toggling the overlay resizes master content, which can cause document
541
549
  // scroll bar to appear or disappear, and trigger another resize of the
542
550
  // layout which can affect previous measurements and end up in horizontal
543
551
  // scroll. Check if that is the case and if so, preserve the overlay mode.
544
552
  if (this.offsetWidth < this.scrollWidth) {
545
- this._overlay = true;
553
+ this.__setOverlayMode(true);
546
554
  }
547
555
  }
548
556
 
549
557
  /** @private */
550
558
  __detectVerticalMode() {
551
- // Remove overlay attribute temporarily to detect if there is enough space
552
- // for both areas so that layout could switch back to the split mode.
553
- this._overlay = false;
554
-
555
559
  const masterHeight = this.$.master.clientHeight;
556
560
 
557
561
  // If the combined minimum size of both the master and the detail content
558
562
  // exceeds the available height, the layout changes to the overlay mode.
559
563
  if (this.offsetHeight < masterHeight + this.$.detail.clientHeight) {
560
- this._overlay = true;
564
+ this.__setOverlayMode(true);
561
565
  }
562
566
  }
563
567
 
564
- /** @private */
565
- __getStackThresholdInPixels() {
566
- const { backgroundPositionY } = getComputedStyle(this.$.master, '::before');
567
- return parseFloat(backgroundPositionY);
568
- }
569
-
570
568
  /**
571
569
  * Sets the detail element to be displayed in the detail area and starts a
572
570
  * view transition that animates adding, replacing or removing the detail
@@ -675,6 +673,16 @@ class MasterDetailLayout extends SlotStylesMixin(ResizeMixin(ElementMixin(Themab
675
673
  this.__transition = null;
676
674
  this.__resolveUpdateCallback = null;
677
675
  }
676
+
677
+ /**
678
+ * @event backdrop-click
679
+ * Fired when the user clicks the backdrop in the overlay mode.
680
+ */
681
+
682
+ /**
683
+ * @event detail-escape-press
684
+ * Fired when the user presses Escape in the detail area.
685
+ */
678
686
  }
679
687
 
680
688
  defineCustomElement(MasterDetailLayout);
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/master-detail-layout",
4
- "version": "24.8.0-alpha14",
4
+ "version": "24.8.0-alpha16",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -67,7 +67,7 @@
67
67
  },
68
68
  {
69
69
  "name": "force-overlay",
70
- "description": "When specified, forces the layout to use overlay mode, even if\nthere is enough space for master and detail to be shown next to\neach other using the default (split) mode.",
70
+ "description": "When specified, forces the layout to use overlay mode, even if\nthere is enough space for master and detail to be shown next to\neach other using the default (split) mode.\n\nIn order to enforce the stack mode, use this property together with\n`stackOverlay` property and set both to `true`.",
71
71
  "value": {
72
72
  "type": [
73
73
  "boolean",
@@ -88,11 +88,11 @@
88
88
  }
89
89
  },
90
90
  {
91
- "name": "stack-threshold",
92
- "description": "The threshold (in CSS length units) at which the layout switches to\nthe \"stack\" mode, making detail area fully cover the master area.",
91
+ "name": "stack-overlay",
92
+ "description": "When true, the layout in the overlay mode is rendered as a \"stack\",\nmaking detail area fully cover the master area.\n\nIn order to enforce the stack mode, use this property together with\n`forceOverlay` property and set both to `true`.",
93
93
  "value": {
94
94
  "type": [
95
- "string",
95
+ "boolean",
96
96
  "null",
97
97
  "undefined"
98
98
  ]
@@ -180,7 +180,7 @@
180
180
  },
181
181
  {
182
182
  "name": "forceOverlay",
183
- "description": "When specified, forces the layout to use overlay mode, even if\nthere is enough space for master and detail to be shown next to\neach other using the default (split) mode.",
183
+ "description": "When specified, forces the layout to use overlay mode, even if\nthere is enough space for master and detail to be shown next to\neach other using the default (split) mode.\n\nIn order to enforce the stack mode, use this property together with\n`stackOverlay` property and set both to `true`.",
184
184
  "value": {
185
185
  "type": [
186
186
  "boolean",
@@ -201,11 +201,11 @@
201
201
  }
202
202
  },
203
203
  {
204
- "name": "stackThreshold",
205
- "description": "The threshold (in CSS length units) at which the layout switches to\nthe \"stack\" mode, making detail area fully cover the master area.",
204
+ "name": "stackOverlay",
205
+ "description": "When true, the layout in the overlay mode is rendered as a \"stack\",\nmaking detail area fully cover the master area.\n\nIn order to enforce the stack mode, use this property together with\n`forceOverlay` property and set both to `true`.",
206
206
  "value": {
207
207
  "type": [
208
- "string",
208
+ "boolean",
209
209
  "null",
210
210
  "undefined"
211
211
  ]
@@ -223,7 +223,16 @@
223
223
  }
224
224
  }
225
225
  ],
226
- "events": []
226
+ "events": [
227
+ {
228
+ "name": "backdrop-click",
229
+ "description": "backdrop-click\nFired when the user clicks the backdrop in the overlay mode."
230
+ },
231
+ {
232
+ "name": "detail-escape-press",
233
+ "description": "detail-escape-press\nFired when the user presses Escape in the detail area."
234
+ }
235
+ ]
227
236
  }
228
237
  }
229
238
  ]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/master-detail-layout",
4
- "version": "24.8.0-alpha14",
4
+ "version": "24.8.0-alpha16",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -21,7 +21,14 @@
21
21
  "attributes": [
22
22
  {
23
23
  "name": "?forceOverlay",
24
- "description": "When specified, forces the layout to use overlay mode, even if\nthere is enough space for master and detail to be shown next to\neach other using the default (split) mode.",
24
+ "description": "When specified, forces the layout to use overlay mode, even if\nthere is enough space for master and detail to be shown next to\neach other using the default (split) mode.\n\nIn order to enforce the stack mode, use this property together with\n`stackOverlay` property and set both to `true`.",
25
+ "value": {
26
+ "kind": "expression"
27
+ }
28
+ },
29
+ {
30
+ "name": "?stackOverlay",
31
+ "description": "When true, the layout in the overlay mode is rendered as a \"stack\",\nmaking detail area fully cover the master area.\n\nIn order to enforce the stack mode, use this property together with\n`forceOverlay` property and set both to `true`.",
25
32
  "value": {
26
33
  "kind": "expression"
27
34
  }
@@ -76,8 +83,15 @@
76
83
  }
77
84
  },
78
85
  {
79
- "name": ".stackThreshold",
80
- "description": "The threshold (in CSS length units) at which the layout switches to\nthe \"stack\" mode, making detail area fully cover the master area.",
86
+ "name": "@backdrop-click",
87
+ "description": "backdrop-click\nFired when the user clicks the backdrop in the overlay mode.",
88
+ "value": {
89
+ "kind": "expression"
90
+ }
91
+ },
92
+ {
93
+ "name": "@detail-escape-press",
94
+ "description": "detail-escape-press\nFired when the user presses Escape in the detail area.",
81
95
  "value": {
82
96
  "kind": "expression"
83
97
  }