@momentum-design/components 0.144.2 → 0.144.3
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/dist/browser/index.js +158 -158
- package/dist/browser/index.js.map +3 -3
- package/dist/components/dialog/dialog.component.js +1 -3
- package/dist/components/menupopover/menupopover.component.d.ts +1 -1
- package/dist/components/menupopover/menupopover.component.js +8 -9
- package/dist/components/popover/popover.component.js +7 -12
- package/dist/custom-elements.json +1 -1
- package/dist/utils/controllers/DepthManager.d.ts +0 -8
- package/dist/utils/controllers/DepthManager.js +0 -32
- package/package.json +1 -1
|
@@ -183,9 +183,7 @@ class Dialog extends KeyDownHandledMixin(KeyToActionMixin(BackdropMixin(PreventS
|
|
|
183
183
|
* @param event - The keyboard event.
|
|
184
184
|
*/
|
|
185
185
|
this.onEscapeKeydown = (event) => {
|
|
186
|
-
if (!this.visible ||
|
|
187
|
-
this.getActionForKeyEvent(event) !== ACTIONS.ESCAPE ||
|
|
188
|
-
!this.depthManager.isHostEscapeTarget()) {
|
|
186
|
+
if (!this.visible || this.getActionForKeyEvent(event) !== ACTIONS.ESCAPE || !this.depthManager.isHostOnTop()) {
|
|
189
187
|
return;
|
|
190
188
|
}
|
|
191
189
|
event.preventDefault();
|
|
@@ -96,7 +96,7 @@ declare class MenuPopover extends Popover {
|
|
|
96
96
|
* Handles outside click events to close the popover.
|
|
97
97
|
* This method checks if the click occurred outside the popover and its trigger element.
|
|
98
98
|
* If so, it closes the popover by calling `closeAllMenuPopovers`.
|
|
99
|
-
*
|
|
99
|
+
* It also checks if the click was on the backdrop element (if present) to close the popover.
|
|
100
100
|
* @param event - The mouse event that triggered the outside click.
|
|
101
101
|
*/
|
|
102
102
|
onOutsidePopoverClick: (event: MouseEvent) => void;
|
|
@@ -60,21 +60,20 @@ class MenuPopover extends Popover {
|
|
|
60
60
|
* Handles outside click events to close the popover.
|
|
61
61
|
* This method checks if the click occurred outside the popover and its trigger element.
|
|
62
62
|
* If so, it closes the popover by calling `closeAllMenuPopovers`.
|
|
63
|
-
*
|
|
63
|
+
* It also checks if the click was on the backdrop element (if present) to close the popover.
|
|
64
64
|
* @param event - The mouse event that triggered the outside click.
|
|
65
65
|
*/
|
|
66
66
|
this.onOutsidePopoverClick = (event) => {
|
|
67
|
-
const path = event.composedPath();
|
|
68
|
-
if (path[0] === this.backdropElement && this.depthManager.has(this)) {
|
|
69
|
-
this.depthManager.popHost();
|
|
70
|
-
event.stopPropagation();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
67
|
if (!this.depthManager.isHostOnTop())
|
|
74
68
|
return;
|
|
69
|
+
const path = event.composedPath();
|
|
75
70
|
const insidePopoverClick = this.contains(event.target) || path.includes(this.triggerElement) || path.includes(this);
|
|
76
|
-
|
|
71
|
+
const clickedOnBackdrop = this.backdropElement ? path.includes(this.backdropElement) : false;
|
|
72
|
+
if (!insidePopoverClick || clickedOnBackdrop) {
|
|
77
73
|
this.closeAllMenuPopovers();
|
|
74
|
+
if (clickedOnBackdrop) {
|
|
75
|
+
event.stopPropagation();
|
|
76
|
+
}
|
|
78
77
|
}
|
|
79
78
|
};
|
|
80
79
|
/**
|
|
@@ -196,7 +195,7 @@ class MenuPopover extends Popover {
|
|
|
196
195
|
break;
|
|
197
196
|
}
|
|
198
197
|
case ACTIONS.ESCAPE: {
|
|
199
|
-
if (this.depthManager.
|
|
198
|
+
if (this.depthManager.isHostOnTop()) {
|
|
200
199
|
this.resetTabIndexAndSetFocus(0, currentIndex);
|
|
201
200
|
isKeyHandled = true;
|
|
202
201
|
}
|
|
@@ -466,20 +466,17 @@ class Popover extends KeyDownHandledMixin(KeyToActionMixin(BackdropMixin(Prevent
|
|
|
466
466
|
* @internal
|
|
467
467
|
*/
|
|
468
468
|
this.onOutsidePopoverClick = (event) => {
|
|
469
|
-
const path = event.composedPath();
|
|
470
|
-
// A backdrop click closes its owner even when a later overlay is on top.
|
|
471
|
-
if (path[0] === this.backdropElement && this.depthManager.has(this)) {
|
|
472
|
-
this.hide();
|
|
473
|
-
PopoverEventManager.onClickOutside(this);
|
|
474
|
-
event.stopPropagation();
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
469
|
if (!this.depthManager.isHostOnTop())
|
|
478
470
|
return;
|
|
471
|
+
const path = event.composedPath();
|
|
479
472
|
const insidePopoverClick = this.contains(event.target) || path.includes(this.triggerElement) || path.includes(this);
|
|
480
|
-
|
|
473
|
+
const clickedOnBackdrop = this.backdropElement ? path.includes(this.backdropElement) : false;
|
|
474
|
+
if (!insidePopoverClick || clickedOnBackdrop) {
|
|
481
475
|
this.hide();
|
|
482
476
|
PopoverEventManager.onClickOutside(this);
|
|
477
|
+
if (clickedOnBackdrop) {
|
|
478
|
+
event.stopPropagation();
|
|
479
|
+
}
|
|
483
480
|
}
|
|
484
481
|
};
|
|
485
482
|
/**
|
|
@@ -491,9 +488,7 @@ class Popover extends KeyDownHandledMixin(KeyToActionMixin(BackdropMixin(Prevent
|
|
|
491
488
|
* @internal
|
|
492
489
|
*/
|
|
493
490
|
this.onEscapeKeydown = (event) => {
|
|
494
|
-
if (!this.visible ||
|
|
495
|
-
this.getActionForKeyEvent(event) !== ACTIONS.ESCAPE ||
|
|
496
|
-
!this.depthManager.isHostEscapeTarget()) {
|
|
491
|
+
if (!this.visible || this.getActionForKeyEvent(event) !== ACTIONS.ESCAPE || !this.depthManager.isHostOnTop()) {
|
|
497
492
|
return;
|
|
498
493
|
}
|
|
499
494
|
if (!this.propagateEventOnEscape) {
|
|
@@ -30312,7 +30312,7 @@
|
|
|
30312
30312
|
{
|
|
30313
30313
|
"kind": "field",
|
|
30314
30314
|
"name": "onOutsidePopoverClick",
|
|
30315
|
-
"description": "Handles outside click events to close the popover.\nThis method checks if the click occurred outside the popover and its trigger element.\nIf so, it closes the popover by calling `closeAllMenuPopovers`.\
|
|
30315
|
+
"description": "Handles outside click events to close the popover.\nThis method checks if the click occurred outside the popover and its trigger element.\nIf so, it closes the popover by calling `closeAllMenuPopovers`.\nIt also checks if the click was on the backdrop element (if present) to close the popover.",
|
|
30316
30316
|
"parameters": [
|
|
30317
30317
|
{
|
|
30318
30318
|
"description": "The mouse event that triggered the outside click.",
|
|
@@ -41,7 +41,6 @@ type PopPredicateFn = (item: StackedOverlayComponent, idx: number) => true | fal
|
|
|
41
41
|
export declare const OVERLAY_BACKDROP_Z_INDEX_OFFSET = -2;
|
|
42
42
|
export declare const OVERLAY_TRIGGER_Z_INDEX_OFFSET = -1;
|
|
43
43
|
/**
|
|
44
|
-
* @remarks
|
|
45
44
|
* DepthManager is a controller that manages a stack of elements to control their depth (z-index).
|
|
46
45
|
*
|
|
47
46
|
* It uses a global stack to keep track of the order of elements, allowing for proper layering of overlays.
|
|
@@ -200,13 +199,6 @@ export declare class DepthManager implements ReactiveController {
|
|
|
200
199
|
* @returns True if host is on top, false otherwise
|
|
201
200
|
*/
|
|
202
201
|
isHostOnTop(): boolean;
|
|
203
|
-
/**
|
|
204
|
-
* Checks whether the nearest overlay or trigger containing focus belongs to the host.
|
|
205
|
-
* Falls back to the top of the stack when focus is outside all registered overlays and triggers.
|
|
206
|
-
*
|
|
207
|
-
* @returns True if the host should handle Escape
|
|
208
|
-
*/
|
|
209
|
-
isHostEscapeTarget(): boolean;
|
|
210
202
|
/**
|
|
211
203
|
* Clears the stack
|
|
212
204
|
*
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getDomActiveElement } from '../dom';
|
|
2
1
|
/**
|
|
3
2
|
* Global stack of elements managed by DepthManager
|
|
4
3
|
* @internal
|
|
@@ -19,7 +18,6 @@ const NUMBER_OF_Z_INDEX_LEVELS_PER_ELEMENT = 3;
|
|
|
19
18
|
export const OVERLAY_BACKDROP_Z_INDEX_OFFSET = -2;
|
|
20
19
|
export const OVERLAY_TRIGGER_Z_INDEX_OFFSET = -1;
|
|
21
20
|
/**
|
|
22
|
-
* @remarks
|
|
23
21
|
* DepthManager is a controller that manages a stack of elements to control their depth (z-index).
|
|
24
22
|
*
|
|
25
23
|
* It uses a global stack to keep track of the order of elements, allowing for proper layering of overlays.
|
|
@@ -260,36 +258,6 @@ export class DepthManager {
|
|
|
260
258
|
isHostOnTop() {
|
|
261
259
|
return this.peek() === this.host;
|
|
262
260
|
}
|
|
263
|
-
/**
|
|
264
|
-
* Checks whether the nearest overlay or trigger containing focus belongs to the host.
|
|
265
|
-
* Falls back to the top of the stack when focus is outside all registered overlays and triggers.
|
|
266
|
-
*
|
|
267
|
-
* @returns True if the host should handle Escape
|
|
268
|
-
*/
|
|
269
|
-
isHostEscapeTarget() {
|
|
270
|
-
const latestFirst = [...elementStack].reverse();
|
|
271
|
-
let focused = getDomActiveElement();
|
|
272
|
-
while (focused) {
|
|
273
|
-
const target = focused;
|
|
274
|
-
const overlay = latestFirst.find(element => element === target ||
|
|
275
|
-
(target instanceof Element &&
|
|
276
|
-
!!element.triggerID &&
|
|
277
|
-
target.id === element.triggerID &&
|
|
278
|
-
target.getRootNode() === element.getRootNode()));
|
|
279
|
-
if (overlay)
|
|
280
|
-
return overlay === this.host;
|
|
281
|
-
if (focused instanceof Element && focused.assignedSlot) {
|
|
282
|
-
focused = focused.assignedSlot;
|
|
283
|
-
}
|
|
284
|
-
else if (focused instanceof ShadowRoot) {
|
|
285
|
-
focused = focused.host;
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
focused = focused.parentNode;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return this.isHostOnTop();
|
|
292
|
-
}
|
|
293
261
|
/**
|
|
294
262
|
* Clears the stack
|
|
295
263
|
*
|