@momentum-design/components 0.143.2 → 0.143.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 +168 -158
- package/dist/browser/index.js.map +3 -3
- package/dist/components/dialog/dialog.component.js +3 -1
- package/dist/components/input/input.styles.js +10 -0
- package/dist/components/menupopover/menupopover.component.d.ts +1 -1
- package/dist/components/menupopover/menupopover.component.js +9 -8
- package/dist/components/popover/popover.component.js +12 -7
- package/dist/custom-elements.json +1 -1
- package/dist/utils/controllers/DepthManager.d.ts +8 -0
- package/dist/utils/controllers/DepthManager.js +32 -0
- package/package.json +2 -2
|
@@ -183,7 +183,9 @@ 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 ||
|
|
186
|
+
if (!this.visible ||
|
|
187
|
+
this.getActionForKeyEvent(event) !== ACTIONS.ESCAPE ||
|
|
188
|
+
!this.depthManager.isHostEscapeTarget()) {
|
|
187
189
|
return;
|
|
188
190
|
}
|
|
189
191
|
event.preventDefault();
|
|
@@ -142,6 +142,16 @@ const styles = [
|
|
|
142
142
|
:host([disabled])::part(character-counter) {
|
|
143
143
|
color: var(--mds-color-theme-text-primary-disabled);
|
|
144
144
|
}
|
|
145
|
+
|
|
146
|
+
input[part='input-text']::-webkit-contacts-auto-fill-button {
|
|
147
|
+
background-color: var(--mdc-input-text-color);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* On hover, and on Safari's yellow autofilled background, use Safari's own icon color. */
|
|
151
|
+
input[part='input-text']::-webkit-contacts-auto-fill-button:hover,
|
|
152
|
+
input[part='input-text']:-webkit-autofill::-webkit-contacts-auto-fill-button {
|
|
153
|
+
background-color: revert;
|
|
154
|
+
}
|
|
145
155
|
`,
|
|
146
156
|
...hostFocusRingStyles(true),
|
|
147
157
|
];
|
|
@@ -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
|
+
* A click on its own backdrop closes this menu and later same-group overlays, even when it is not on top.
|
|
100
100
|
* @param event - The mouse event that triggered the outside click.
|
|
101
101
|
*/
|
|
102
102
|
onOutsidePopoverClick: (event: MouseEvent) => void;
|
|
@@ -60,20 +60,21 @@ 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
|
+
* A click on its own backdrop closes this menu and later same-group overlays, even when it is not on top.
|
|
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
|
+
}
|
|
67
73
|
if (!this.depthManager.isHostOnTop())
|
|
68
74
|
return;
|
|
69
|
-
const path = event.composedPath();
|
|
70
75
|
const insidePopoverClick = this.contains(event.target) || path.includes(this.triggerElement) || path.includes(this);
|
|
71
|
-
|
|
72
|
-
if (!insidePopoverClick || clickedOnBackdrop) {
|
|
76
|
+
if (!insidePopoverClick) {
|
|
73
77
|
this.closeAllMenuPopovers();
|
|
74
|
-
if (clickedOnBackdrop) {
|
|
75
|
-
event.stopPropagation();
|
|
76
|
-
}
|
|
77
78
|
}
|
|
78
79
|
};
|
|
79
80
|
/**
|
|
@@ -195,7 +196,7 @@ class MenuPopover extends Popover {
|
|
|
195
196
|
break;
|
|
196
197
|
}
|
|
197
198
|
case ACTIONS.ESCAPE: {
|
|
198
|
-
if (this.depthManager.
|
|
199
|
+
if (this.depthManager.isHostEscapeTarget()) {
|
|
199
200
|
this.resetTabIndexAndSetFocus(0, currentIndex);
|
|
200
201
|
isKeyHandled = true;
|
|
201
202
|
}
|
|
@@ -466,17 +466,20 @@ 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
|
+
}
|
|
469
477
|
if (!this.depthManager.isHostOnTop())
|
|
470
478
|
return;
|
|
471
|
-
const path = event.composedPath();
|
|
472
479
|
const insidePopoverClick = this.contains(event.target) || path.includes(this.triggerElement) || path.includes(this);
|
|
473
|
-
|
|
474
|
-
if (!insidePopoverClick || clickedOnBackdrop) {
|
|
480
|
+
if (!insidePopoverClick) {
|
|
475
481
|
this.hide();
|
|
476
482
|
PopoverEventManager.onClickOutside(this);
|
|
477
|
-
if (clickedOnBackdrop) {
|
|
478
|
-
event.stopPropagation();
|
|
479
|
-
}
|
|
480
483
|
}
|
|
481
484
|
};
|
|
482
485
|
/**
|
|
@@ -488,7 +491,9 @@ class Popover extends KeyDownHandledMixin(KeyToActionMixin(BackdropMixin(Prevent
|
|
|
488
491
|
* @internal
|
|
489
492
|
*/
|
|
490
493
|
this.onEscapeKeydown = (event) => {
|
|
491
|
-
if (!this.visible ||
|
|
494
|
+
if (!this.visible ||
|
|
495
|
+
this.getActionForKeyEvent(event) !== ACTIONS.ESCAPE ||
|
|
496
|
+
!this.depthManager.isHostEscapeTarget()) {
|
|
492
497
|
return;
|
|
493
498
|
}
|
|
494
499
|
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`.\nA click on its own backdrop closes this menu and later same-group overlays, even when it is not on top.",
|
|
30316
30316
|
"parameters": [
|
|
30317
30317
|
{
|
|
30318
30318
|
"description": "The mouse event that triggered the outside click.",
|
|
@@ -41,6 +41,7 @@ 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
|
|
44
45
|
* DepthManager is a controller that manages a stack of elements to control their depth (z-index).
|
|
45
46
|
*
|
|
46
47
|
* It uses a global stack to keep track of the order of elements, allowing for proper layering of overlays.
|
|
@@ -199,6 +200,13 @@ export declare class DepthManager implements ReactiveController {
|
|
|
199
200
|
* @returns True if host is on top, false otherwise
|
|
200
201
|
*/
|
|
201
202
|
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;
|
|
202
210
|
/**
|
|
203
211
|
* Clears the stack
|
|
204
212
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getDomActiveElement } from '../dom';
|
|
1
2
|
/**
|
|
2
3
|
* Global stack of elements managed by DepthManager
|
|
3
4
|
* @internal
|
|
@@ -18,6 +19,7 @@ const NUMBER_OF_Z_INDEX_LEVELS_PER_ELEMENT = 3;
|
|
|
18
19
|
export const OVERLAY_BACKDROP_Z_INDEX_OFFSET = -2;
|
|
19
20
|
export const OVERLAY_TRIGGER_Z_INDEX_OFFSET = -1;
|
|
20
21
|
/**
|
|
22
|
+
* @remarks
|
|
21
23
|
* DepthManager is a controller that manages a stack of elements to control their depth (z-index).
|
|
22
24
|
*
|
|
23
25
|
* It uses a global stack to keep track of the order of elements, allowing for proper layering of overlays.
|
|
@@ -258,6 +260,36 @@ export class DepthManager {
|
|
|
258
260
|
isHostOnTop() {
|
|
259
261
|
return this.peek() === this.host;
|
|
260
262
|
}
|
|
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
|
+
}
|
|
261
293
|
/**
|
|
262
294
|
* Clears the stack
|
|
263
295
|
*
|