@ngrdt/menu 0.0.11 → 0.0.14
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/README.md +157 -3
- package/esm2022/index.mjs +2 -2
- package/esm2022/lib/menu/rdt-menu.component.mjs +57 -32
- package/esm2022/lib/menu-bar/rdt-menu-bar.component.mjs +13 -6
- package/esm2022/lib/menu-base/rdt-menu-base.component.mjs +106 -31
- package/esm2022/lib/menu-overlay/rdt-menu-overlay.component.mjs +36 -33
- package/esm2022/lib/private-models.mjs +8 -1
- package/esm2022/lib/rdt-menu.module.mjs +5 -5
- package/fesm2022/ngrdt-menu.mjs +309 -194
- package/fesm2022/ngrdt-menu.mjs.map +1 -1
- package/index.d.ts +1 -1
- package/lib/menu/rdt-menu.component.d.ts +15 -9
- package/lib/menu-bar/rdt-menu-bar.component.d.ts +3 -0
- package/lib/menu-base/rdt-menu-base.component.d.ts +24 -6
- package/lib/menu-overlay/rdt-menu-overlay.component.d.ts +9 -6
- package/lib/private-models.d.ts +17 -7
- package/package.json +2 -2
package/fesm2022/ngrdt-menu.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, inject, ElementRef, DestroyRef, Renderer2, ChangeDetectorRef, Component, ChangeDetectionStrategy, ViewChildren, ViewChild, Input, HostBinding, HostListener, EnvironmentInjector, booleanAttribute, Directive, ViewEncapsulation,
|
|
3
|
-
import * as i2$1 from '@ngrdt/button';
|
|
4
|
-
import { RDT_BUTTON_BASE_PROVIDER, RdtButtonOutletDirective } from '@ngrdt/button';
|
|
2
|
+
import { InjectionToken, inject, ElementRef, DestroyRef, Renderer2, ChangeDetectorRef, Component, ChangeDetectionStrategy, ViewChildren, ViewChild, Input, HostBinding, HostListener, EnvironmentInjector, booleanAttribute, numberAttribute, Directive, ViewEncapsulation, QueryList, NgModule } from '@angular/core';
|
|
5
3
|
import * as i1 from '@angular/common';
|
|
6
4
|
import { DOCUMENT, CommonModule } from '@angular/common';
|
|
7
5
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
@@ -11,8 +9,9 @@ import * as i3 from '@ngrdt/router';
|
|
|
11
9
|
import { RdtRouterService, RdtAnyRouteActiveDirective } from '@ngrdt/router';
|
|
12
10
|
import * as i4 from '@ngrdt/shortcuts';
|
|
13
11
|
import { RdtShortcutService, RdtShortcut, RdtKeyListenerDirective } from '@ngrdt/shortcuts';
|
|
14
|
-
import { KB_CODE, RdtObjectUtils
|
|
12
|
+
import { RdtStringUtils, KB_CODE, RdtObjectUtils } from '@ngrdt/utils';
|
|
15
13
|
import { delay, of, map, first, Subscription, fromEvent, throttleTime, animationFrameScheduler } from 'rxjs';
|
|
14
|
+
import { RDT_BUTTON_BASE_PROVIDER, RdtButtonOutletDirective } from '@ngrdt/button';
|
|
16
15
|
|
|
17
16
|
var RdtMenuShortcutMode;
|
|
18
17
|
(function (RdtMenuShortcutMode) {
|
|
@@ -28,6 +27,78 @@ const DEFAULT_MENU_VERTICAL_DIR = 'down';
|
|
|
28
27
|
const RDT_MENU_HORIZONTAL_DIR_PROVIDER = new InjectionToken('RDT_MENU_HORIZONTAL_DIR');
|
|
29
28
|
const RDT_MENU_VERTICAL_DIR_PROVIDER = new InjectionToken('RDT_MENU_VERTICAL_DIR');
|
|
30
29
|
|
|
30
|
+
function parseMenuItems(items, injector, prefix = '') {
|
|
31
|
+
return items
|
|
32
|
+
.map((item) => {
|
|
33
|
+
let newPrefix;
|
|
34
|
+
if (item.dataTestId) {
|
|
35
|
+
newPrefix = item.dataTestId;
|
|
36
|
+
}
|
|
37
|
+
else if (prefix) {
|
|
38
|
+
newPrefix = RdtStringUtils.getDataTestId(item.label, prefix);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
newPrefix = RdtStringUtils.getDataTestId(item.label);
|
|
42
|
+
}
|
|
43
|
+
const newDataTestId = RdtStringUtils.getDataTestId(newPrefix, null, 'menu-item');
|
|
44
|
+
const res = {
|
|
45
|
+
label: item.label,
|
|
46
|
+
icon: item.icon,
|
|
47
|
+
shortcut: item.shortcut,
|
|
48
|
+
command: item.command,
|
|
49
|
+
visible: item.visible,
|
|
50
|
+
queryParams: item.queryParams,
|
|
51
|
+
requiredParent: item.requiredParent,
|
|
52
|
+
dataTestId: newDataTestId,
|
|
53
|
+
};
|
|
54
|
+
if (item.items) {
|
|
55
|
+
const childrenRes = res;
|
|
56
|
+
const parsedChildren = parseMenuItems(item.items, injector, newPrefix);
|
|
57
|
+
if (parsedChildren.length > 0) {
|
|
58
|
+
childrenRes.items = parsedChildren;
|
|
59
|
+
}
|
|
60
|
+
return childrenRes;
|
|
61
|
+
}
|
|
62
|
+
else if (item.routerLink) {
|
|
63
|
+
const linkRes = res;
|
|
64
|
+
linkRes.target = item.target ?? '_self';
|
|
65
|
+
if (item.routerLink) {
|
|
66
|
+
linkRes.routerLink = [item.routerLink.createAbsoluteUrl()];
|
|
67
|
+
if (!res.visible && item.routerLink.hasCanBeEnteredGuard) {
|
|
68
|
+
const canBeEntered = item.routerLink.canBeEntered.bind(item.routerLink);
|
|
69
|
+
linkRes.visible = () => canBeEntered(injector);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return linkRes;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const linkRes = res;
|
|
76
|
+
if (item.externalLink) {
|
|
77
|
+
if (item.queryParams) {
|
|
78
|
+
linkRes.externalLink = RdtStringUtils.appendQueryParams(item.externalLink, item.queryParams);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
linkRes.externalLink = item.externalLink;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
linkRes.target = item.target ?? '_blank';
|
|
85
|
+
return linkRes;
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
.filter((item) => !item.visible || item.visible())
|
|
89
|
+
.filter((item) => item.externalLink ||
|
|
90
|
+
item['routerLink'] ||
|
|
91
|
+
item.command ||
|
|
92
|
+
(item['items']?.length ?? 0) > 0);
|
|
93
|
+
}
|
|
94
|
+
var RdtMenuExpandSource;
|
|
95
|
+
(function (RdtMenuExpandSource) {
|
|
96
|
+
RdtMenuExpandSource[RdtMenuExpandSource["Click"] = 0] = "Click";
|
|
97
|
+
RdtMenuExpandSource[RdtMenuExpandSource["Hover"] = 1] = "Hover";
|
|
98
|
+
RdtMenuExpandSource[RdtMenuExpandSource["Shortcut"] = 2] = "Shortcut";
|
|
99
|
+
RdtMenuExpandSource[RdtMenuExpandSource["Focus"] = 3] = "Focus";
|
|
100
|
+
})(RdtMenuExpandSource || (RdtMenuExpandSource = {}));
|
|
101
|
+
|
|
31
102
|
const INVISIBLE_CLASS = 'invisible';
|
|
32
103
|
const FOCUS_VISIBLE = 'focus-visible';
|
|
33
104
|
function getChildRoutesMapRec(item, map) {
|
|
@@ -160,7 +231,7 @@ class RdtMenuOverlayComponent {
|
|
|
160
231
|
keyActions = {
|
|
161
232
|
[KB_CODE.ARROW.UP]: (index) => this.focusPrevItem(index),
|
|
162
233
|
[KB_CODE.ARROW.DOWN]: (index) => this.focusNextItem(index),
|
|
163
|
-
[KB_CODE.ARROW.RIGHT]: (index) => this.openSubmenu(index, 'first'),
|
|
234
|
+
[KB_CODE.ARROW.RIGHT]: (index) => this.openSubmenu(index, 'first', RdtMenuExpandSource.Shortcut),
|
|
164
235
|
[KB_CODE.ARROW.LEFT]: () => this.closeSelf(),
|
|
165
236
|
[KB_CODE.HOME]: () => this.focusItem(0),
|
|
166
237
|
[KB_CODE.END]: () => this.focusItem(this.item.items.length - 1),
|
|
@@ -168,6 +239,17 @@ class RdtMenuOverlayComponent {
|
|
|
168
239
|
[KB_CODE.ENTER]: (index) => this.invokeItemClickByIndex(index),
|
|
169
240
|
[KB_CODE.SPACEBAR]: (index) => this.invokeItemClickByIndex(index),
|
|
170
241
|
};
|
|
242
|
+
get selfExpandSrc() {
|
|
243
|
+
if (this.expanded) {
|
|
244
|
+
if (this.parentMenu) {
|
|
245
|
+
return this.parentMenu.expandedChild?.src;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
return this.topLevelMenu.expandedChild?.src;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
171
253
|
ngOnInit() {
|
|
172
254
|
this.setClasses();
|
|
173
255
|
this.listenTabKeyPress();
|
|
@@ -273,35 +355,26 @@ class RdtMenuOverlayComponent {
|
|
|
273
355
|
this.recalculateChildren();
|
|
274
356
|
}
|
|
275
357
|
onItemPointerEnter(item) {
|
|
276
|
-
if (this.topLevelMenu.openOnHover
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
358
|
+
if (this.topLevelMenu.openOnHover &&
|
|
359
|
+
this.expandedChild?.src !== RdtMenuExpandSource.Click) {
|
|
360
|
+
this.autofocusSubmenuItem = null;
|
|
361
|
+
if (menuItemHasChildren(item)) {
|
|
362
|
+
this.expandedChild = { item, src: RdtMenuExpandSource.Hover };
|
|
363
|
+
this.expanded = true;
|
|
280
364
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
menu.expandedChild = item2;
|
|
285
|
-
menu.expanded = true;
|
|
286
|
-
item2 = menu.item;
|
|
287
|
-
menu = menu.parentMenu;
|
|
365
|
+
else {
|
|
366
|
+
//console.log('expanded child', this.expandedChild);
|
|
367
|
+
this.expandedChild = null;
|
|
288
368
|
}
|
|
289
369
|
}
|
|
290
370
|
}
|
|
291
|
-
onItemPointerLeave(item) {
|
|
292
|
-
if (this.expandedChild &&
|
|
293
|
-
this.topLevelMenu.openOnHover &&
|
|
294
|
-
this.expandedChild === item &&
|
|
295
|
-
menuItemHasChildren(item)) {
|
|
296
|
-
this.autofocusSubmenuItem = null;
|
|
297
|
-
this.expandedChild = null;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
371
|
onItemClick(item) {
|
|
301
372
|
const hasChildren = menuItemHasChildren(item);
|
|
302
|
-
if (hasChildren && this.expandedChild !== item)
|
|
373
|
+
if ((hasChildren && this.expandedChild?.item !== item) ||
|
|
374
|
+
(this.topLevelMenu.openOnHover &&
|
|
375
|
+
this.expandedChild?.src === RdtMenuExpandSource.Hover)) {
|
|
303
376
|
this.autofocusSubmenuItem = null;
|
|
304
|
-
this.expandedChild = item;
|
|
377
|
+
this.expandedChild = { item, src: RdtMenuExpandSource.Click };
|
|
305
378
|
}
|
|
306
379
|
else {
|
|
307
380
|
this.expandedChild = null;
|
|
@@ -327,7 +400,7 @@ class RdtMenuOverlayComponent {
|
|
|
327
400
|
}
|
|
328
401
|
closeSubmenus(focusExpanded = false) {
|
|
329
402
|
if (focusExpanded && this.expandedChild) {
|
|
330
|
-
this.focusItem(this.expandedChild);
|
|
403
|
+
this.focusItem(this.expandedChild.item);
|
|
331
404
|
}
|
|
332
405
|
this.expandedChild = null;
|
|
333
406
|
this.cd.markForCheck();
|
|
@@ -338,7 +411,7 @@ class RdtMenuOverlayComponent {
|
|
|
338
411
|
this.autofocusSubmenuItem = null;
|
|
339
412
|
this.autofocusItem = null;
|
|
340
413
|
if (children.length > 0) {
|
|
341
|
-
this.expandAndGetChild(thisItem)
|
|
414
|
+
this.expandAndGetChild(thisItem, RdtMenuExpandSource.Focus)
|
|
342
415
|
.pipe(delay(1))
|
|
343
416
|
.subscribe((overlay) => {
|
|
344
417
|
overlay.focusItemRecursively(children);
|
|
@@ -355,11 +428,11 @@ class RdtMenuOverlayComponent {
|
|
|
355
428
|
setTimeout(() => this.focusItem(thisItem), 1);
|
|
356
429
|
}
|
|
357
430
|
}
|
|
358
|
-
expandAndGetChild(item) {
|
|
431
|
+
expandAndGetChild(item, src) {
|
|
359
432
|
if (this.item.items.indexOf(item) < 0) {
|
|
360
433
|
throw new Error('Attempting to expand item that is not child item of this.item');
|
|
361
434
|
}
|
|
362
|
-
this.expandedChild = item;
|
|
435
|
+
this.expandedChild = { item, src };
|
|
363
436
|
this.cd.markForCheck();
|
|
364
437
|
const child = this.children.find((child) => child.item === item);
|
|
365
438
|
if (child) {
|
|
@@ -439,10 +512,10 @@ class RdtMenuOverlayComponent {
|
|
|
439
512
|
const prev = (itemIndex - 1 + this.item.items.length) % this.item.items.length;
|
|
440
513
|
this.focusItem(prev);
|
|
441
514
|
}
|
|
442
|
-
openSubmenu(itemIndex, visibleFocus) {
|
|
515
|
+
openSubmenu(itemIndex, visibleFocus, src) {
|
|
443
516
|
if (itemIndex < this.item.items.length &&
|
|
444
517
|
menuItemHasChildren(this.item.items[itemIndex])) {
|
|
445
|
-
this.expandedChild = this.item.items[itemIndex];
|
|
518
|
+
this.expandedChild = { item: this.item.items[itemIndex], src };
|
|
446
519
|
this.autofocusSubmenuItem = visibleFocus;
|
|
447
520
|
}
|
|
448
521
|
}
|
|
@@ -455,7 +528,7 @@ class RdtMenuOverlayComponent {
|
|
|
455
528
|
}
|
|
456
529
|
}
|
|
457
530
|
checkActiveElement(event) {
|
|
458
|
-
if (this.topLevelMenu.closeOnFocusOut) {
|
|
531
|
+
if (this.topLevelMenu.closeOnFocusOut && !this.topLevelMenu.openOnHover) {
|
|
459
532
|
const thisEl = this.elRef.nativeElement;
|
|
460
533
|
const target = event.relatedTarget;
|
|
461
534
|
if (!(target instanceof HTMLElement) || !thisEl.contains(target)) {
|
|
@@ -641,11 +714,11 @@ class RdtMenuOverlayComponent {
|
|
|
641
714
|
.subscribe((event) => this.onTabKeyPress(event));
|
|
642
715
|
}
|
|
643
716
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuOverlayComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
644
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.7", type: RdtMenuOverlayComponent, selector: "rdt-menu-overlay", inputs: { item: "item", level: "level", preferredHorizontalDir: "preferredHorizontalDir", preferredVerticalDir: "preferredVerticalDir", expanded: "expanded", autofocusItem: "autofocusItem", anchorElement: "anchorElement" }, host: { listeners: { "window:focusout": "checkActiveElement($event)" }, properties: { "class.expanded": "this.expanded", "attr.role": "this.roleAttr", "attr.tabindex": "this.tabindexAttr", "style.z-index": "this.zIndex" } }, viewQueries: [{ propertyName: "menuItemContainer", first: true, predicate: ["menuItemContainer"], descendants: true }, { propertyName: "children", predicate: RdtMenuOverlayComponent, descendants: true }, { propertyName: "focusableElements", predicate: ["focusableItem"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<ul class=\"menu-item-container\" role=\"presentation\" #menuItemContainer>\r\n <li\r\n *ngFor=\"let item of item.items; let i = index\"\r\n role=\"presentation\"\r\n class=\"menu-item\"\r\n (rdtKeyListener)=\"onKeyDown(i, $event)\"\r\n rdtAnyRouteActive=\"menu-item-route-active\"\r\n [watchedRoutes]=\"getChildRoutes(item)\"\r\n
|
|
717
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.7", type: RdtMenuOverlayComponent, selector: "rdt-menu-overlay", inputs: { item: "item", level: "level", preferredHorizontalDir: "preferredHorizontalDir", preferredVerticalDir: "preferredVerticalDir", expanded: "expanded", autofocusItem: "autofocusItem", anchorElement: "anchorElement" }, host: { listeners: { "window:focusout": "checkActiveElement($event)" }, properties: { "class.expanded": "this.expanded", "attr.role": "this.roleAttr", "attr.tabindex": "this.tabindexAttr", "style.z-index": "this.zIndex" } }, viewQueries: [{ propertyName: "menuItemContainer", first: true, predicate: ["menuItemContainer"], descendants: true }, { propertyName: "children", predicate: RdtMenuOverlayComponent, descendants: true }, { propertyName: "focusableElements", predicate: ["focusableItem"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<ul class=\"menu-item-container\" role=\"presentation\" #menuItemContainer>\r\n <li\r\n *ngFor=\"let item of item.items; let i = index\"\r\n role=\"presentation\"\r\n class=\"menu-item\"\r\n (rdtKeyListener)=\"onKeyDown(i, $event)\"\r\n (pointerenter)=\"onItemPointerEnter(item)\"\r\n rdtAnyRouteActive=\"menu-item-route-active\"\r\n [watchedRoutes]=\"getChildRoutes(item)\"\r\n #anchorEl\r\n >\r\n <ng-container *ngIf=\"!item.routerLink && !item.externalLink\">\r\n <button\r\n #focusableItem\r\n class=\"menu-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n [attr.aria-haspopup]=\"item.items ? 'menu' : null\"\r\n [attr.aria-expanded]=\"item === expandedChild?.item\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n {{ item.label }}\r\n\r\n <div class=\"menu-item-right-content\">\r\n <span *ngIf=\"item.shortcut\" class=\"menu-item-shortcut\">\r\n {{ item.shortcut.label }}\r\n </span>\r\n <!-- TODO:\r\n <rdt-icon\r\n *ngIf=\"item.items\"\r\n name=\"chevron_right\"\r\n class=\"menu-item-icon\"\r\n />\r\n <rdt-icon\r\n *ngIf=\"item.icon\"\r\n [name]=\"item.icon\"\r\n class=\"menu-item-icon\"\r\n />\r\n -->\r\n <span\r\n class=\"menu-item-icon rdt-menu-icon-right\"\r\n *ngIf=\"item.items\"\r\n ></span>\r\n </div>\r\n </button>\r\n </ng-container>\r\n\r\n <ng-template #linkBody let-item>\r\n {{ item.label }}\r\n\r\n <div class=\"menu-item-right-content\">\r\n <span *ngIf=\"item.shortcut\" class=\"menu-item-shortcut\">\r\n {{ item.shortcut.label }}\r\n </span>\r\n <!-- TODO:\r\n <rdt-icon\r\n *ngIf=\"item.icon\"\r\n [name]=\"item.icon\"\r\n class=\"menu-item-icon\"\r\n />\r\n --></div>\r\n </ng-template>\r\n\r\n <ng-container *ngIf=\"item.routerLink\">\r\n <a\r\n #focusableItem\r\n class=\"menu-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n [routerLink]=\"item.routerLink\"\r\n [queryParams]=\"item.queryParams\"\r\n [target]=\"item.target\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n <ng-container\r\n *ngTemplateOutlet=\"linkBody; context: { $implicit: item }\"\r\n />\r\n </a>\r\n </ng-container>\r\n\r\n <ng-container *ngIf=\"item.externalLink\">\r\n <a\r\n #focusableItem\r\n class=\"menu-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n [href]=\"item.externalLink\"\r\n [target]=\"item.target\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n <ng-container\r\n *ngTemplateOutlet=\"linkBody; context: { $implicit: item }\"\r\n />\r\n </a>\r\n </ng-container>\r\n\r\n <!-- Child menus exist only if this menu is expanded. -->\r\n <!-- Only one invisible level is always attached to DOM, the rest does not exist. -->\r\n <rdt-menu-overlay\r\n *ngIf=\"item.items && expanded\"\r\n [item]=\"$any(item)\"\r\n [expanded]=\"item === expandedChild?.item\"\r\n [autofocusItem]=\"autofocusSubmenuItem\"\r\n [preferredHorizontalDir]=\"horizontalDir?.dir!\"\r\n [preferredVerticalDir]=\"verticalDir?.dir!\"\r\n [level]=\"level + 1\"\r\n [anchorElement]=\"anchorEl\"\r\n />\r\n </li>\r\n</ul>\r\n", styles: [":host{visibility:hidden;position:fixed;min-width:var(--rdt-menu-min-width);box-shadow:var(--rdt-menu-box-shadow);border-radius:var(--rdt-menu-border-radius);overflow-x:hidden;overflow-y:auto;max-height:calc(100vh - var(--rdt-menu-margin-top, 0px) - var(--rdt-menu-margin-bottom, 0px))}:host.expanded{visibility:visible}ul.menu-item-container{list-style-type:none;padding:var(--rdt-menu-padding-horizontal-padding) 0;border-radius:var(--rdt-menu-border-radius);background-color:var(--rdt-menu-background);margin-top:0;margin-bottom:0;margin-block-start:0;margin-block-end:0}.menu-item-content{cursor:pointer;display:flex;align-items:center;width:100%;padding:var(--rdt-menu-item-padding);background-color:var(--rdt-menu-item-background);color:var(--rdt-menu-item-text-color);border:var(--rdt-menu-item-border);outline:var(--rdt-menu-item-outline)}.menu-item{position:relative;box-sizing:border-box}.menu-item.menu-item-route-active>.menu-item-content{--rdt-menu-item-background: var(--rdt-menu-item-route-active-background);--rdt-menu-item-text-color: var(--rdt-menu-item-route-active-text-color);--rdt-menu-item-border: var(--rdt-menu-item-route-active-border);--rdt-menu-item-outline: var(--rdt-menu-item-route-active-outline)}.menu-item .menu-item-content:hover{--rdt-menu-item-background: var(--rdt-menu-item-hover-background);--rdt-menu-item-text-color: var(--rdt-menu-item-hover-text-color);--rdt-menu-item-border: var(--rdt-menu-item-hover-border);--rdt-menu-item-outline: var(--rdt-menu-item-hover-outline)}.menu-item [aria-expanded=true].menu-item-content{--rdt-menu-item-background: var(--rdt-menu-item-expanded-background);--rdt-menu-item-text-color: var(--rdt-menu-item-expanded-text-color);--rdt-menu-item-border: var(--rdt-menu-item-expanded-border);--rdt-menu-item-outline: var(--rdt-menu-item-expanded-outline)}.menu-item .menu-item-content.focus-visible:focus,.menu-item .menu-item-content:focus-visible{--rdt-menu-item-background: var(--rdt-menu-item-focus-background);--rdt-menu-item-text-color: var(--rdt-menu-item-focus-text-color);--rdt-menu-item-border: var(--rdt-menu-item-focus-border);--rdt-menu-item-outline: var(--rdt-menu-item-focus-outline)}.menu-item-icon.rdt-menu-icon-right{width:0;height:0;border-top:var(--rdt-menu-default-icon-size) solid transparent;border-bottom:var(--rdt-menu-default-icon-size) solid transparent;border-left:var(--rdt-menu-default-icon-size) solid var(--rdt-menu-item-text-color)}\n"], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i2.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "directive", type: i3.RdtAnyRouteActiveDirective, selector: "[rdtAnyRouteActive]", inputs: ["rdtAnyRouteActive", "watchedRoutes", "anyRouteActiveOptions", "ariaCurrentWhenActive"] }, { kind: "directive", type: i4.RdtKeyListenerDirective, selector: "[rdtKeyListener]", outputs: ["rdtKeyListener"] }, { kind: "component", type: RdtMenuOverlayComponent, selector: "rdt-menu-overlay", inputs: ["item", "level", "preferredHorizontalDir", "preferredVerticalDir", "expanded", "autofocusItem", "anchorElement"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
645
718
|
}
|
|
646
719
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuOverlayComponent, decorators: [{
|
|
647
720
|
type: Component,
|
|
648
|
-
args: [{ selector: 'rdt-menu-overlay', changeDetection: ChangeDetectionStrategy.OnPush, template: "<ul class=\"menu-item-container\" role=\"presentation\" #menuItemContainer>\r\n <li\r\n *ngFor=\"let item of item.items; let i = index\"\r\n role=\"presentation\"\r\n class=\"menu-item\"\r\n (rdtKeyListener)=\"onKeyDown(i, $event)\"\r\n rdtAnyRouteActive=\"menu-item-route-active\"\r\n [watchedRoutes]=\"getChildRoutes(item)\"\r\n
|
|
721
|
+
args: [{ selector: 'rdt-menu-overlay', changeDetection: ChangeDetectionStrategy.OnPush, template: "<ul class=\"menu-item-container\" role=\"presentation\" #menuItemContainer>\r\n <li\r\n *ngFor=\"let item of item.items; let i = index\"\r\n role=\"presentation\"\r\n class=\"menu-item\"\r\n (rdtKeyListener)=\"onKeyDown(i, $event)\"\r\n (pointerenter)=\"onItemPointerEnter(item)\"\r\n rdtAnyRouteActive=\"menu-item-route-active\"\r\n [watchedRoutes]=\"getChildRoutes(item)\"\r\n #anchorEl\r\n >\r\n <ng-container *ngIf=\"!item.routerLink && !item.externalLink\">\r\n <button\r\n #focusableItem\r\n class=\"menu-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n [attr.aria-haspopup]=\"item.items ? 'menu' : null\"\r\n [attr.aria-expanded]=\"item === expandedChild?.item\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n {{ item.label }}\r\n\r\n <div class=\"menu-item-right-content\">\r\n <span *ngIf=\"item.shortcut\" class=\"menu-item-shortcut\">\r\n {{ item.shortcut.label }}\r\n </span>\r\n <!-- TODO:\r\n <rdt-icon\r\n *ngIf=\"item.items\"\r\n name=\"chevron_right\"\r\n class=\"menu-item-icon\"\r\n />\r\n <rdt-icon\r\n *ngIf=\"item.icon\"\r\n [name]=\"item.icon\"\r\n class=\"menu-item-icon\"\r\n />\r\n -->\r\n <span\r\n class=\"menu-item-icon rdt-menu-icon-right\"\r\n *ngIf=\"item.items\"\r\n ></span>\r\n </div>\r\n </button>\r\n </ng-container>\r\n\r\n <ng-template #linkBody let-item>\r\n {{ item.label }}\r\n\r\n <div class=\"menu-item-right-content\">\r\n <span *ngIf=\"item.shortcut\" class=\"menu-item-shortcut\">\r\n {{ item.shortcut.label }}\r\n </span>\r\n <!-- TODO:\r\n <rdt-icon\r\n *ngIf=\"item.icon\"\r\n [name]=\"item.icon\"\r\n class=\"menu-item-icon\"\r\n />\r\n --></div>\r\n </ng-template>\r\n\r\n <ng-container *ngIf=\"item.routerLink\">\r\n <a\r\n #focusableItem\r\n class=\"menu-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n [routerLink]=\"item.routerLink\"\r\n [queryParams]=\"item.queryParams\"\r\n [target]=\"item.target\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n <ng-container\r\n *ngTemplateOutlet=\"linkBody; context: { $implicit: item }\"\r\n />\r\n </a>\r\n </ng-container>\r\n\r\n <ng-container *ngIf=\"item.externalLink\">\r\n <a\r\n #focusableItem\r\n class=\"menu-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n [href]=\"item.externalLink\"\r\n [target]=\"item.target\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n <ng-container\r\n *ngTemplateOutlet=\"linkBody; context: { $implicit: item }\"\r\n />\r\n </a>\r\n </ng-container>\r\n\r\n <!-- Child menus exist only if this menu is expanded. -->\r\n <!-- Only one invisible level is always attached to DOM, the rest does not exist. -->\r\n <rdt-menu-overlay\r\n *ngIf=\"item.items && expanded\"\r\n [item]=\"$any(item)\"\r\n [expanded]=\"item === expandedChild?.item\"\r\n [autofocusItem]=\"autofocusSubmenuItem\"\r\n [preferredHorizontalDir]=\"horizontalDir?.dir!\"\r\n [preferredVerticalDir]=\"verticalDir?.dir!\"\r\n [level]=\"level + 1\"\r\n [anchorElement]=\"anchorEl\"\r\n />\r\n </li>\r\n</ul>\r\n", styles: [":host{visibility:hidden;position:fixed;min-width:var(--rdt-menu-min-width);box-shadow:var(--rdt-menu-box-shadow);border-radius:var(--rdt-menu-border-radius);overflow-x:hidden;overflow-y:auto;max-height:calc(100vh - var(--rdt-menu-margin-top, 0px) - var(--rdt-menu-margin-bottom, 0px))}:host.expanded{visibility:visible}ul.menu-item-container{list-style-type:none;padding:var(--rdt-menu-padding-horizontal-padding) 0;border-radius:var(--rdt-menu-border-radius);background-color:var(--rdt-menu-background);margin-top:0;margin-bottom:0;margin-block-start:0;margin-block-end:0}.menu-item-content{cursor:pointer;display:flex;align-items:center;width:100%;padding:var(--rdt-menu-item-padding);background-color:var(--rdt-menu-item-background);color:var(--rdt-menu-item-text-color);border:var(--rdt-menu-item-border);outline:var(--rdt-menu-item-outline)}.menu-item{position:relative;box-sizing:border-box}.menu-item.menu-item-route-active>.menu-item-content{--rdt-menu-item-background: var(--rdt-menu-item-route-active-background);--rdt-menu-item-text-color: var(--rdt-menu-item-route-active-text-color);--rdt-menu-item-border: var(--rdt-menu-item-route-active-border);--rdt-menu-item-outline: var(--rdt-menu-item-route-active-outline)}.menu-item .menu-item-content:hover{--rdt-menu-item-background: var(--rdt-menu-item-hover-background);--rdt-menu-item-text-color: var(--rdt-menu-item-hover-text-color);--rdt-menu-item-border: var(--rdt-menu-item-hover-border);--rdt-menu-item-outline: var(--rdt-menu-item-hover-outline)}.menu-item [aria-expanded=true].menu-item-content{--rdt-menu-item-background: var(--rdt-menu-item-expanded-background);--rdt-menu-item-text-color: var(--rdt-menu-item-expanded-text-color);--rdt-menu-item-border: var(--rdt-menu-item-expanded-border);--rdt-menu-item-outline: var(--rdt-menu-item-expanded-outline)}.menu-item .menu-item-content.focus-visible:focus,.menu-item .menu-item-content:focus-visible{--rdt-menu-item-background: var(--rdt-menu-item-focus-background);--rdt-menu-item-text-color: var(--rdt-menu-item-focus-text-color);--rdt-menu-item-border: var(--rdt-menu-item-focus-border);--rdt-menu-item-outline: var(--rdt-menu-item-focus-outline)}.menu-item-icon.rdt-menu-icon-right{width:0;height:0;border-top:var(--rdt-menu-default-icon-size) solid transparent;border-bottom:var(--rdt-menu-default-icon-size) solid transparent;border-left:var(--rdt-menu-default-icon-size) solid var(--rdt-menu-item-text-color)}\n"] }]
|
|
649
722
|
}], propDecorators: { children: [{
|
|
650
723
|
type: ViewChildren,
|
|
651
724
|
args: [RdtMenuOverlayComponent]
|
|
@@ -694,8 +767,9 @@ class RdtMenuBaseComponent {
|
|
|
694
767
|
// OPEN_SUBMENU will open its submenu and put focus on the first item in it
|
|
695
768
|
// If item has command or routerLink, it will always be activated and everything closed
|
|
696
769
|
shortcutMode = RdtMenuShortcutMode.OPEN_SUBMENU;
|
|
697
|
-
closeOnFocusOut =
|
|
770
|
+
closeOnFocusOut = false;
|
|
698
771
|
openOnHover = false;
|
|
772
|
+
hitboxMargin = 10;
|
|
699
773
|
cd = inject(ChangeDetectorRef);
|
|
700
774
|
destroyRef = inject(DestroyRef);
|
|
701
775
|
rdtRouter = inject(RdtRouterService);
|
|
@@ -708,7 +782,7 @@ class RdtMenuBaseComponent {
|
|
|
708
782
|
children;
|
|
709
783
|
focusableElements;
|
|
710
784
|
classes = 'rdt-menu-base';
|
|
711
|
-
|
|
785
|
+
expandedChild = null;
|
|
712
786
|
autofocusSubmenuItem = null;
|
|
713
787
|
parsedItems;
|
|
714
788
|
get clientSize() {
|
|
@@ -719,6 +793,10 @@ class RdtMenuBaseComponent {
|
|
|
719
793
|
return this._bodyMargin;
|
|
720
794
|
}
|
|
721
795
|
_bodyMargin;
|
|
796
|
+
get buttonContainerRect() {
|
|
797
|
+
return this._buttonContainerRect;
|
|
798
|
+
}
|
|
799
|
+
_buttonContainerRect;
|
|
722
800
|
allParsedItems;
|
|
723
801
|
childRoutesMap = new Map();
|
|
724
802
|
shortcutSub = new Subscription();
|
|
@@ -726,8 +804,8 @@ class RdtMenuBaseComponent {
|
|
|
726
804
|
keyActions = {
|
|
727
805
|
[KB_CODE.ARROW.LEFT]: (index) => this.focusPrevItem(index),
|
|
728
806
|
[KB_CODE.ARROW.RIGHT]: (index) => this.focusNextItem(index),
|
|
729
|
-
[KB_CODE.ARROW.DOWN]: (index) => this.openSubmenu(index, 'first'),
|
|
730
|
-
[KB_CODE.ARROW.UP]: (index) => this.openSubmenu(index, 'last'),
|
|
807
|
+
[KB_CODE.ARROW.DOWN]: (index) => this.openSubmenu(index, 'first', RdtMenuExpandSource.Shortcut),
|
|
808
|
+
[KB_CODE.ARROW.UP]: (index) => this.openSubmenu(index, 'last', RdtMenuExpandSource.Shortcut),
|
|
731
809
|
[KB_CODE.HOME]: () => this.focusItem(0),
|
|
732
810
|
[KB_CODE.END]: () => this.focusItem(this.parsedItems.length - 1),
|
|
733
811
|
[KB_CODE.ENTER]: (index) => this.invokeItemClickByIndex(index),
|
|
@@ -762,35 +840,36 @@ class RdtMenuBaseComponent {
|
|
|
762
840
|
});
|
|
763
841
|
}
|
|
764
842
|
closeSubmenus(focusExpanded = false) {
|
|
765
|
-
if (focusExpanded && this.
|
|
766
|
-
this.focusItem(this.
|
|
843
|
+
if (focusExpanded && this.expandedChild) {
|
|
844
|
+
this.focusItem(this.expandedChild.item);
|
|
767
845
|
}
|
|
768
|
-
this.
|
|
846
|
+
this.expandedChild = null;
|
|
769
847
|
this.cd.markForCheck();
|
|
770
848
|
}
|
|
771
849
|
onItemClick(item) {
|
|
772
|
-
if (menuItemHasChildren(item) && this.
|
|
850
|
+
if ((menuItemHasChildren(item) && this.expandedChild?.item !== item) ||
|
|
851
|
+
(this.openOnHover &&
|
|
852
|
+
this.expandedChild?.src === RdtMenuExpandSource.Hover)) {
|
|
773
853
|
this.autofocusSubmenuItem = null;
|
|
774
|
-
this.
|
|
854
|
+
this.expandedChild = { item, src: RdtMenuExpandSource.Click };
|
|
775
855
|
}
|
|
776
856
|
else {
|
|
777
|
-
this.
|
|
857
|
+
this.expandedChild = null;
|
|
778
858
|
}
|
|
779
859
|
if (typeof item.command === 'function') {
|
|
780
860
|
item.command();
|
|
781
861
|
}
|
|
782
862
|
}
|
|
783
863
|
onItemPointerEnter(item) {
|
|
784
|
-
if (this.openOnHover
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
this.expanded = null;
|
|
864
|
+
if (this.openOnHover) {
|
|
865
|
+
if (menuItemHasChildren(item) &&
|
|
866
|
+
this.expandedChild?.src !== RdtMenuExpandSource.Click) {
|
|
867
|
+
this.autofocusSubmenuItem = null;
|
|
868
|
+
this.expandedChild = { item, src: RdtMenuExpandSource.Hover };
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
this.expandedChild = null;
|
|
872
|
+
}
|
|
794
873
|
}
|
|
795
874
|
}
|
|
796
875
|
onKeyDown(itemIndex, event) {
|
|
@@ -879,12 +958,12 @@ class RdtMenuBaseComponent {
|
|
|
879
958
|
}
|
|
880
959
|
this.invokeItemClick(item);
|
|
881
960
|
}
|
|
882
|
-
openSubmenu(itemIndex, visibleFocus) {
|
|
961
|
+
openSubmenu(itemIndex, visibleFocus, src) {
|
|
883
962
|
if (itemIndex < this.parsedItems.length &&
|
|
884
963
|
menuItemHasChildren(this.parsedItems[itemIndex])) {
|
|
885
964
|
const item = this.parsedItems[itemIndex];
|
|
886
965
|
this.autofocusSubmenuItem = visibleFocus;
|
|
887
|
-
this.
|
|
966
|
+
this.expandedChild = { item, src };
|
|
888
967
|
}
|
|
889
968
|
}
|
|
890
969
|
focusItem(item) {
|
|
@@ -918,13 +997,27 @@ class RdtMenuBaseComponent {
|
|
|
918
997
|
elRef.nativeElement.focus();
|
|
919
998
|
}
|
|
920
999
|
}
|
|
1000
|
+
onPointerMove(event) {
|
|
1001
|
+
if (this.openOnHover && this.expandedChild) {
|
|
1002
|
+
const hitboxes = this.getHitboxes();
|
|
1003
|
+
const isInside = hitboxes.some((hitbox) => this.isPointerInsideHitbox(hitbox.rect, event));
|
|
1004
|
+
for (let i = hitboxes.length - 1; i >= 0; i--) {
|
|
1005
|
+
const hitbox = hitboxes[i];
|
|
1006
|
+
if (!hitbox.fixed && !isInside) {
|
|
1007
|
+
hitbox.close();
|
|
1008
|
+
break;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
921
1013
|
// Closes menu if user navigates outside it using Tab.
|
|
922
1014
|
checkActiveElement(event) {
|
|
923
|
-
if (this.closeOnFocusOut) {
|
|
1015
|
+
if (this.closeOnFocusOut && !this.openOnHover) {
|
|
1016
|
+
console.log('focusout', event);
|
|
924
1017
|
const thisEl = this.elRef.nativeElement;
|
|
925
1018
|
const target = event.relatedTarget;
|
|
926
1019
|
if (!(target instanceof HTMLElement) || !thisEl.contains(target)) {
|
|
927
|
-
this.
|
|
1020
|
+
this.expandedChild = null;
|
|
928
1021
|
}
|
|
929
1022
|
}
|
|
930
1023
|
}
|
|
@@ -936,6 +1029,7 @@ class RdtMenuBaseComponent {
|
|
|
936
1029
|
}
|
|
937
1030
|
}
|
|
938
1031
|
measure() {
|
|
1032
|
+
this.measureButtonContainer();
|
|
939
1033
|
this.measureClientSize();
|
|
940
1034
|
this.readMargin();
|
|
941
1035
|
}
|
|
@@ -958,6 +1052,15 @@ class RdtMenuBaseComponent {
|
|
|
958
1052
|
height: this.document.body.clientHeight,
|
|
959
1053
|
};
|
|
960
1054
|
}
|
|
1055
|
+
measureButtonContainer() {
|
|
1056
|
+
const el = this.buttonContainer;
|
|
1057
|
+
if (el) {
|
|
1058
|
+
this._buttonContainerRect = el.getBoundingClientRect();
|
|
1059
|
+
}
|
|
1060
|
+
else {
|
|
1061
|
+
this._buttonContainerRect = undefined;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
961
1064
|
listenWindowResize() {
|
|
962
1065
|
fromEvent(window, 'resize')
|
|
963
1066
|
.pipe(throttleTime(0, animationFrameScheduler, { trailing: true }), takeUntilDestroyed(this.destroyRef))
|
|
@@ -1001,10 +1104,10 @@ class RdtMenuBaseComponent {
|
|
|
1001
1104
|
}
|
|
1002
1105
|
}
|
|
1003
1106
|
else {
|
|
1004
|
-
this.activateItemRecursively(path);
|
|
1107
|
+
this.activateItemRecursively(path, RdtMenuExpandSource.Shortcut);
|
|
1005
1108
|
}
|
|
1006
1109
|
}
|
|
1007
|
-
activateItemRecursively(path) {
|
|
1110
|
+
activateItemRecursively(path, src) {
|
|
1008
1111
|
const children = [...path];
|
|
1009
1112
|
if (this.shortcutMode === RdtMenuShortcutMode.OPEN_SUBMENU) {
|
|
1010
1113
|
const last = children[children.length - 1];
|
|
@@ -1014,17 +1117,55 @@ class RdtMenuBaseComponent {
|
|
|
1014
1117
|
}
|
|
1015
1118
|
const thisItem = children.shift();
|
|
1016
1119
|
if (children.length > 0) {
|
|
1017
|
-
this.
|
|
1120
|
+
this.expandedChild = { item: thisItem, src };
|
|
1018
1121
|
const overlay = this.children.find((child) => child.item === thisItem);
|
|
1019
1122
|
overlay.focusItemRecursively(children);
|
|
1020
1123
|
}
|
|
1021
1124
|
else {
|
|
1022
|
-
this.
|
|
1125
|
+
this.expandedChild = null;
|
|
1023
1126
|
this.focusItem(thisItem);
|
|
1024
1127
|
}
|
|
1025
1128
|
}
|
|
1129
|
+
isPointerInsideHitbox(hitbox, event) {
|
|
1130
|
+
const rect = hitbox;
|
|
1131
|
+
const x = event.clientX;
|
|
1132
|
+
const y = event.clientY;
|
|
1133
|
+
return (x >= rect.left - this.hitboxMargin &&
|
|
1134
|
+
x <= rect.right + this.hitboxMargin &&
|
|
1135
|
+
y >= rect.top - this.hitboxMargin &&
|
|
1136
|
+
y <= rect.bottom + this.hitboxMargin);
|
|
1137
|
+
}
|
|
1138
|
+
getHitboxes() {
|
|
1139
|
+
const boxes = this.getOpenMenuBoundingBoxes();
|
|
1140
|
+
const buttonContainerRect = this.buttonContainerRect;
|
|
1141
|
+
if (buttonContainerRect) {
|
|
1142
|
+
boxes.push({ rect: buttonContainerRect, fixed: true, close: () => { } });
|
|
1143
|
+
}
|
|
1144
|
+
return boxes;
|
|
1145
|
+
}
|
|
1146
|
+
getOpenMenuBoundingBoxes() {
|
|
1147
|
+
const boxes = [];
|
|
1148
|
+
this.children.forEach((overlay) => {
|
|
1149
|
+
this.getOpenMenuBoundingBoxesRec(overlay, boxes);
|
|
1150
|
+
});
|
|
1151
|
+
return boxes;
|
|
1152
|
+
}
|
|
1153
|
+
getOpenMenuBoundingBoxesRec(overlay, boxes) {
|
|
1154
|
+
if (overlay.expanded) {
|
|
1155
|
+
let someByClick = false;
|
|
1156
|
+
overlay.children.forEach((child) => (someByClick ||= this.getOpenMenuBoundingBoxesRec(child, boxes)));
|
|
1157
|
+
const fixed = someByClick || overlay.selfExpandSrc === RdtMenuExpandSource.Click;
|
|
1158
|
+
boxes.push({
|
|
1159
|
+
rect: overlay.box,
|
|
1160
|
+
fixed: fixed,
|
|
1161
|
+
close: () => overlay.closeSelf(),
|
|
1162
|
+
});
|
|
1163
|
+
return fixed;
|
|
1164
|
+
}
|
|
1165
|
+
return false;
|
|
1166
|
+
}
|
|
1026
1167
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuBaseComponent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1027
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "18.2.7", type: RdtMenuBaseComponent, inputs: { preferredVerticalDir: "preferredVerticalDir", preferredHorizontalDir: "preferredHorizontalDir", shortcutMode: "shortcutMode", closeOnFocusOut: ["closeOnFocusOut", "closeOnFocusOut", booleanAttribute], openOnHover: ["openOnHover", "openOnHover", booleanAttribute] }, host: { listeners: { "window:focusout": "checkActiveElement($event)", "document:click": "onDocumentClick($event)" }, properties: { "class": "this.classes" } }, viewQueries: [{ propertyName: "children", predicate: RdtMenuOverlayComponent, descendants: true }, { propertyName: "focusableElements", predicate: ["focusableItem"], descendants: true }], usesOnChanges: true, ngImport: i0 });
|
|
1168
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "18.2.7", type: RdtMenuBaseComponent, inputs: { preferredVerticalDir: "preferredVerticalDir", preferredHorizontalDir: "preferredHorizontalDir", shortcutMode: "shortcutMode", closeOnFocusOut: ["closeOnFocusOut", "closeOnFocusOut", booleanAttribute], openOnHover: ["openOnHover", "openOnHover", booleanAttribute], hitboxMargin: ["hitboxMargin", "hitboxMargin", numberAttribute] }, host: { listeners: { "window:pointermove": "onPointerMove($event)", "window:focusout": "checkActiveElement($event)", "document:click": "onDocumentClick($event)" }, properties: { "class": "this.classes" } }, viewQueries: [{ propertyName: "children", predicate: RdtMenuOverlayComponent, descendants: true }, { propertyName: "focusableElements", predicate: ["focusableItem"], descendants: true }], usesOnChanges: true, ngImport: i0 });
|
|
1028
1169
|
}
|
|
1029
1170
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuBaseComponent, decorators: [{
|
|
1030
1171
|
type: Directive
|
|
@@ -1040,6 +1181,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImpor
|
|
|
1040
1181
|
}], openOnHover: [{
|
|
1041
1182
|
type: Input,
|
|
1042
1183
|
args: [{ transform: booleanAttribute }]
|
|
1184
|
+
}], hitboxMargin: [{
|
|
1185
|
+
type: Input,
|
|
1186
|
+
args: [{ transform: numberAttribute }]
|
|
1043
1187
|
}], children: [{
|
|
1044
1188
|
type: ViewChildren,
|
|
1045
1189
|
args: [RdtMenuOverlayComponent]
|
|
@@ -1049,6 +1193,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImpor
|
|
|
1049
1193
|
}], classes: [{
|
|
1050
1194
|
type: HostBinding,
|
|
1051
1195
|
args: ['class']
|
|
1196
|
+
}], onPointerMove: [{
|
|
1197
|
+
type: HostListener,
|
|
1198
|
+
args: ['window:pointermove', ['$event']]
|
|
1052
1199
|
}], checkActiveElement: [{
|
|
1053
1200
|
type: HostListener,
|
|
1054
1201
|
args: ['window:focusout', ['$event']]
|
|
@@ -1057,132 +1204,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImpor
|
|
|
1057
1204
|
args: ['document:click', ['$event']]
|
|
1058
1205
|
}] } });
|
|
1059
1206
|
|
|
1060
|
-
function parseMenuItems(items, injector, prefix = '') {
|
|
1061
|
-
return items
|
|
1062
|
-
.map((item) => {
|
|
1063
|
-
let newPrefix;
|
|
1064
|
-
if (item.dataTestId) {
|
|
1065
|
-
newPrefix = item.dataTestId;
|
|
1066
|
-
}
|
|
1067
|
-
else if (prefix) {
|
|
1068
|
-
newPrefix = RdtStringUtils.getDataTestId(item.label, prefix);
|
|
1069
|
-
}
|
|
1070
|
-
else {
|
|
1071
|
-
newPrefix = RdtStringUtils.getDataTestId(item.label);
|
|
1072
|
-
}
|
|
1073
|
-
const newDataTestId = RdtStringUtils.getDataTestId(newPrefix, null, 'menu-item');
|
|
1074
|
-
const res = {
|
|
1075
|
-
label: item.label,
|
|
1076
|
-
icon: item.icon,
|
|
1077
|
-
shortcut: item.shortcut,
|
|
1078
|
-
command: item.command,
|
|
1079
|
-
visible: item.visible,
|
|
1080
|
-
queryParams: item.queryParams,
|
|
1081
|
-
requiredParent: item.requiredParent,
|
|
1082
|
-
dataTestId: newDataTestId,
|
|
1083
|
-
};
|
|
1084
|
-
if (item.items) {
|
|
1085
|
-
const childrenRes = res;
|
|
1086
|
-
const parsedChildren = parseMenuItems(item.items, injector, newPrefix);
|
|
1087
|
-
if (parsedChildren.length > 0) {
|
|
1088
|
-
childrenRes.items = parsedChildren;
|
|
1089
|
-
}
|
|
1090
|
-
return childrenRes;
|
|
1091
|
-
}
|
|
1092
|
-
else if (item.routerLink) {
|
|
1093
|
-
const linkRes = res;
|
|
1094
|
-
linkRes.target = item.target ?? '_self';
|
|
1095
|
-
if (item.routerLink) {
|
|
1096
|
-
linkRes.routerLink = [item.routerLink.createAbsoluteUrl()];
|
|
1097
|
-
if (!res.visible && item.routerLink.hasCanBeEnteredGuard) {
|
|
1098
|
-
const canBeEntered = item.routerLink.canBeEntered.bind(item.routerLink);
|
|
1099
|
-
linkRes.visible = () => canBeEntered(injector);
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
return linkRes;
|
|
1103
|
-
}
|
|
1104
|
-
else {
|
|
1105
|
-
const linkRes = res;
|
|
1106
|
-
if (item.externalLink) {
|
|
1107
|
-
if (item.queryParams) {
|
|
1108
|
-
linkRes.externalLink = RdtStringUtils.appendQueryParams(item.externalLink, item.queryParams);
|
|
1109
|
-
}
|
|
1110
|
-
else {
|
|
1111
|
-
linkRes.externalLink = item.externalLink;
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
linkRes.target = item.target ?? '_blank';
|
|
1115
|
-
return linkRes;
|
|
1116
|
-
}
|
|
1117
|
-
})
|
|
1118
|
-
.filter((item) => !item.visible || item.visible())
|
|
1119
|
-
.filter((item) => item.externalLink ||
|
|
1120
|
-
item['routerLink'] ||
|
|
1121
|
-
item.command ||
|
|
1122
|
-
(item['items']?.length ?? 0) > 0);
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
class RdtMenuComponent extends RdtMenuBaseComponent {
|
|
1126
|
-
buttonClass = inject(RDT_BUTTON_BASE_PROVIDER);
|
|
1127
|
-
dataTestId = '';
|
|
1128
|
-
get item() {
|
|
1129
|
-
return this._item;
|
|
1130
|
-
}
|
|
1131
|
-
set item(value) {
|
|
1132
|
-
this._item = value;
|
|
1133
|
-
this.allParsedItems = parseMenuItems([value], this.injector);
|
|
1134
|
-
this.filterItems();
|
|
1135
|
-
}
|
|
1136
|
-
_item;
|
|
1137
|
-
onPointerLeave() {
|
|
1138
|
-
this.onItemPointerLeave(this.parsedItem);
|
|
1139
|
-
}
|
|
1140
|
-
get parsedItem() {
|
|
1141
|
-
return this.parsedItems[0];
|
|
1142
|
-
}
|
|
1143
|
-
get buttonInputs() {
|
|
1144
|
-
return {
|
|
1145
|
-
tabIndex: 0,
|
|
1146
|
-
dataTestId: this.dataTestId,
|
|
1147
|
-
label: this.parsedItem.label,
|
|
1148
|
-
icon: this.parsedItem.icon,
|
|
1149
|
-
aria: {
|
|
1150
|
-
role: 'menuitem',
|
|
1151
|
-
'aria-haspopup': 'menu',
|
|
1152
|
-
'aria-expanded': this.expanded === this.parsedItem,
|
|
1153
|
-
},
|
|
1154
|
-
};
|
|
1155
|
-
}
|
|
1156
|
-
toggle() {
|
|
1157
|
-
this.onItemClick(this.parsedItem);
|
|
1158
|
-
}
|
|
1159
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
1160
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.7", type: RdtMenuComponent, selector: "rdt-menu", inputs: { dataTestId: "dataTestId", item: "item" }, host: { listeners: { "pointerleave": "onPointerLeave()" } }, providers: [
|
|
1161
|
-
{
|
|
1162
|
-
provide: RdtMenuBaseComponent,
|
|
1163
|
-
useExisting: RdtMenuComponent,
|
|
1164
|
-
},
|
|
1165
|
-
], usesInheritance: true, ngImport: i0, template: "<div\r\n class=\"menu-button-container\"\r\n (pointerenter)=\"onItemPointerEnter(parsedItem)\"\r\n>\r\n <ng-template\r\n rdtButtonOutlet\r\n [inputs]=\"buttonInputs\"\r\n (click$)=\"toggle()\"\r\n #outlet=\"rdtButtonOutlet\"\r\n />\r\n</div>\r\n\r\n<rdt-menu-overlay\r\n *ngIf=\"parsedItem\"\r\n [anchorElement]=\"outlet.instance?.anchorElement\"\r\n [item]=\"$any(parsedItem)\"\r\n [expanded]=\"expanded === parsedItem\"\r\n [autofocusItem]=\"autofocusSubmenuItem\"\r\n [preferredHorizontalDir]=\"preferredHorizontalDir\"\r\n [preferredVerticalDir]=\"preferredVerticalDir\"\r\n [level]=\"0\"\r\n/>\r\n", styles: ["a.menu-bar-item-content,a.menu-item-content,button.menu-bar-item-content,button.menu-item-content{white-space:nowrap;appearance:none;border:none;text-decoration:none}.menu-item-right-content,.menu-bar-item-right-content{margin-left:auto;display:flex;align-items:center}.menu-item-shortcut,.menu-bar-item-shortcut{margin-left:2rem}.menu-item-icon,.menu-bar-item-icon{margin-left:.5rem;font-size:1.2rem}.dp3-menu-base ul{margin-bottom:0}rdt-menu{display:block;position:relative}rdt-menu .menu-button-container{display:inline-block}\n"], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2$1.RdtButtonOutletDirective, selector: "[rdtButtonOutlet]", inputs: ["inputs"], outputs: ["click$"], exportAs: ["rdtButtonOutlet"] }, { kind: "component", type: RdtMenuOverlayComponent, selector: "rdt-menu-overlay", inputs: ["item", "level", "preferredHorizontalDir", "preferredVerticalDir", "expanded", "autofocusItem", "anchorElement"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
1166
|
-
}
|
|
1167
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuComponent, decorators: [{
|
|
1168
|
-
type: Component,
|
|
1169
|
-
args: [{ selector: 'rdt-menu', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [
|
|
1170
|
-
{
|
|
1171
|
-
provide: RdtMenuBaseComponent,
|
|
1172
|
-
useExisting: RdtMenuComponent,
|
|
1173
|
-
},
|
|
1174
|
-
], template: "<div\r\n class=\"menu-button-container\"\r\n (pointerenter)=\"onItemPointerEnter(parsedItem)\"\r\n>\r\n <ng-template\r\n rdtButtonOutlet\r\n [inputs]=\"buttonInputs\"\r\n (click$)=\"toggle()\"\r\n #outlet=\"rdtButtonOutlet\"\r\n />\r\n</div>\r\n\r\n<rdt-menu-overlay\r\n *ngIf=\"parsedItem\"\r\n [anchorElement]=\"outlet.instance?.anchorElement\"\r\n [item]=\"$any(parsedItem)\"\r\n [expanded]=\"expanded === parsedItem\"\r\n [autofocusItem]=\"autofocusSubmenuItem\"\r\n [preferredHorizontalDir]=\"preferredHorizontalDir\"\r\n [preferredVerticalDir]=\"preferredVerticalDir\"\r\n [level]=\"0\"\r\n/>\r\n", styles: ["a.menu-bar-item-content,a.menu-item-content,button.menu-bar-item-content,button.menu-item-content{white-space:nowrap;appearance:none;border:none;text-decoration:none}.menu-item-right-content,.menu-bar-item-right-content{margin-left:auto;display:flex;align-items:center}.menu-item-shortcut,.menu-bar-item-shortcut{margin-left:2rem}.menu-item-icon,.menu-bar-item-icon{margin-left:.5rem;font-size:1.2rem}.dp3-menu-base ul{margin-bottom:0}rdt-menu{display:block;position:relative}rdt-menu .menu-button-container{display:inline-block}\n"] }]
|
|
1175
|
-
}], propDecorators: { dataTestId: [{
|
|
1176
|
-
type: Input
|
|
1177
|
-
}], item: [{
|
|
1178
|
-
type: Input,
|
|
1179
|
-
args: [{ required: true }]
|
|
1180
|
-
}], onPointerLeave: [{
|
|
1181
|
-
type: HostListener,
|
|
1182
|
-
args: ['pointerleave']
|
|
1183
|
-
}] } });
|
|
1184
|
-
|
|
1185
1207
|
class RdtMenuBarComponent extends RdtMenuBaseComponent {
|
|
1208
|
+
buttonContainerRef;
|
|
1209
|
+
get buttonContainer() {
|
|
1210
|
+
return this.buttonContainerRef?.nativeElement;
|
|
1211
|
+
}
|
|
1186
1212
|
get items() {
|
|
1187
1213
|
return this._items;
|
|
1188
1214
|
}
|
|
@@ -1196,12 +1222,12 @@ class RdtMenuBarComponent extends RdtMenuBaseComponent {
|
|
|
1196
1222
|
footerHeight = 0;
|
|
1197
1223
|
roleAttr = 'menubar';
|
|
1198
1224
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuBarComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
1199
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "
|
|
1225
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.7", type: RdtMenuBarComponent, selector: "rdt-menu-bar", inputs: { items: "items", headerHeight: ["headerHeight", "headerHeight", numberAttribute], footerHeight: ["footerHeight", "footerHeight", numberAttribute] }, host: { properties: { "attr.role": "this.roleAttr" } }, providers: [
|
|
1200
1226
|
{
|
|
1201
1227
|
provide: RdtMenuBaseComponent,
|
|
1202
1228
|
useExisting: RdtMenuBarComponent,
|
|
1203
1229
|
},
|
|
1204
|
-
], usesInheritance: true, ngImport: i0, template: "<ul class=\"menu-bar-item-container\" role=\"presentation\">\r\n
|
|
1230
|
+
], viewQueries: [{ propertyName: "buttonContainerRef", first: true, predicate: ["buttonContainer"], descendants: true, static: true }], usesInheritance: true, ngImport: i0, template: "<ul class=\"menu-bar-item-container\" role=\"presentation\" #buttonContainer>\r\n @for(item of parsedItems; track item; let i = $index) {\r\n <li\r\n class=\"menu-bar-item\"\r\n role=\"presentation\"\r\n rdtAnyRouteActive=\"menu-bar-item-route-active\"\r\n [watchedRoutes]=\"getChildRoutes(item)\"\r\n (rdtKeyListener)=\"onKeyDown(i, $event)\"\r\n #anchorEl\r\n >\r\n @if(!item.routerLink && !item.externalLink) {\r\n <button\r\n #focusableItem\r\n class=\"menu-bar-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n (pointerenter)=\"onItemPointerEnter(item)\"\r\n [attr.aria-haspopup]=\"item.items ? 'menu' : null\"\r\n [attr.aria-expanded]=\"item === expandedChild?.item\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n {{ item.label }}\r\n\r\n <div class=\"menu-bar-item-right-content\">\r\n @if(item.shortcut) {\r\n <span class=\"menu-item-shortcut\">\r\n {{ item.shortcut.label }}\r\n </span>\r\n }\r\n <!-- TODO\r\n <rdt-icon\r\n *ngIf=\"item.items\"\r\n name=\"expand_more\"\r\n class=\"menu-bar-item-icon\"\r\n inverted\r\n />\r\n <rdt-icon\r\n *ngIf=\"item.icon\"\r\n [name]=\"item.icon\"\r\n class=\"menu-bar-item-icon\"\r\n inverted\r\n />\r\n -->\r\n @if(item.items) {\r\n <span class=\"menu-bar-item-icon rdt-menu-icon-down\"></span>\r\n }\r\n </div>\r\n </button>\r\n }\r\n\r\n <ng-template #linkBody let-item>\r\n {{ item.label }}\r\n\r\n <div class=\"menu-bar-item-right-content\">\r\n @if(item.shortcut) {\r\n <span class=\"menu-item-shortcut\">\r\n {{ item.shortcut.label }}\r\n </span>\r\n }\r\n <!--\r\n <rdt-icon\r\n *ngIf=\"item.icon\"\r\n [name]=\"item.icon\"\r\n class=\"menu-bar-item-icon\"\r\n inverted\r\n />\r\n --></div>\r\n </ng-template>\r\n\r\n @if(item.routerLink) {\r\n <a\r\n #focusableItem\r\n class=\"menu-bar-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n [routerLink]=\"item.routerLink\"\r\n [target]=\"item.target!\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n <ng-container\r\n *ngTemplateOutlet=\"linkBody; context: { $implicit: item }\"\r\n />\r\n </a>\r\n } @if(item.externalLink) {\r\n <a\r\n #focusableItem\r\n class=\"menu-bar-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n [href]=\"item.externalLink\"\r\n [target]=\"item.target\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n <ng-container\r\n *ngTemplateOutlet=\"linkBody; context: { $implicit: item }\"\r\n />\r\n </a>\r\n } @if (item.items) {\r\n <rdt-menu-overlay\r\n [item]=\"$any(item)\"\r\n [expanded]=\"item === expandedChild?.item\"\r\n [autofocusItem]=\"autofocusSubmenuItem\"\r\n [preferredHorizontalDir]=\"preferredHorizontalDir\"\r\n [preferredVerticalDir]=\"preferredVerticalDir\"\r\n [level]=\"0\"\r\n [anchorElement]=\"anchorEl\"\r\n />\r\n }\r\n </li>\r\n }\r\n</ul>\r\n", styles: ["a.menu-bar-item-content,a.menu-item-content,button.menu-bar-item-content,button.menu-item-content{white-space:nowrap;appearance:none;text-decoration:none;box-sizing:border-box}.menu-item-right-content,.menu-bar-item-right-content{margin-left:auto;display:flex;align-items:center}.menu-item-shortcut,.menu-bar-item-shortcut{margin-left:2rem}.menu-item-icon,.menu-bar-item-icon{margin-left:.5rem;font-size:1.2rem}.dp3-menu-base ul{margin-bottom:0}.rdt-menu-root{margin-left:0}.rdt-menu-root.rdt-overlay-down{margin-top:var(--rdt-menu-overlay-margin-y)}.rdt-menu-root.rdt-overlay-up{margin-top:calc(-1 * var(--rdt-menu-overlay-margin-y))}.rdt-menu-sub.rdt-overlay-left{margin-left:calc(-1 * var(--rdt-menu-overlay-margin-x))}.rdt-menu-sub.rdt-overlay-right{margin-left:var(--rdt-menu-overlay-margin-x)}rdt-menu-bar{-webkit-user-select:none;user-select:none;pointer-events:none;padding:var(--rdt-menu-bar-padding)}.menu-bar-item-container{display:flex;list-style-type:none;margin-bottom:0;margin-top:0;margin-block-start:0;margin-block-end:0;padding-left:0}.menu-bar-item{pointer-events:all;margin:var(--rdt-menu-bar-item-margin);position:relative;display:flex;align-items:center;justify-content:center}.menu-bar-item.menu-bar-item-route-active .menu-bar-item-content{--rdt-menu-bar-item-background: var( --rdt-menu-bar-item-route-active-background );--rdt-menu-bar-item-text-color: var( --rdt-menu-bar-item-route-active-text-color );--rdt-menu-bar-item-border: var(--rdt-menu-bar-item-route-active-border);--rdt-menu-bar-item-outline: var(--rdt-menu-bar-item-route-active-outline)}.menu-bar-item [aria-expanded=true].menu-bar-item-content{--rdt-menu-bar-item-background: var( --rdt-menu-bar-item-expanded-background );--rdt-menu-bar-item-text-color: var( --rdt-menu-bar-item-expanded-text-color );--rdt-menu-bar-item-border: var(--rdt-menu-bar-item-expanded-border);--rdt-menu-bar-item-outline: var(--rdt-menu-bar-item-expanded-outline)}.menu-bar-item-content{cursor:pointer;display:flex;align-items:center;overflow:hidden;padding:var(--rdt-menu-bar-item-padding);border-radius:var(--rdt-menu-bar-item-border-radius);border:var(--rdt-menu-bar-item-border);background-color:var(--rdt-menu-bar-item-background);color:var(--rdt-menu-bar-item-text-color);outline:var(--rdt-menu-bar-item-outline);font-size:inherit}.menu-bar-item-content:hover{--rdt-menu-bar-item-background: var(--rdt-menu-bar-item-hover-background);--rdt-menu-bar-item-text-color: var(--rdt-menu-bar-item-hover-text-color);--rdt-menu-bar-item-border: var(--rdt-menu-bar-item-hover-border);--rdt-menu-bar-item-outline: var(--rdt-menu-bar-item-hover-outline)}.menu-bar-item .menu-bar-item-content.focus-visible:focus,.menu-bar-item .menu-bar-item-content:focus-visible{--rdt-menu-bar-item-background: var(--rdt-menu-bar-item-focus-background);--rdt-menu-bar-item-text-color: var(--rdt-menu-bar-item-focus-text-color);--rdt-menu-bar-item-border: var(--rdt-menu-bar-item-focus-border);--rdt-menu-bar-item-outline: var(--rdt-menu-bar-item-focus-outline)}.menu-bar-item-icon.rdt-menu-icon-down{width:0;height:0;border-left:var(--rdt-menu-default-icon-size) solid transparent;border-right:var(--rdt-menu-default-icon-size) solid transparent;border-top:var(--rdt-menu-default-icon-size) solid var(--rdt-menu-bar-item-text-color)}\n"], dependencies: [{ kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i2.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "directive", type: i3.RdtAnyRouteActiveDirective, selector: "[rdtAnyRouteActive]", inputs: ["rdtAnyRouteActive", "watchedRoutes", "anyRouteActiveOptions", "ariaCurrentWhenActive"] }, { kind: "directive", type: i4.RdtKeyListenerDirective, selector: "[rdtKeyListener]", outputs: ["rdtKeyListener"] }, { kind: "component", type: RdtMenuOverlayComponent, selector: "rdt-menu-overlay", inputs: ["item", "level", "preferredHorizontalDir", "preferredVerticalDir", "expanded", "autofocusItem", "anchorElement"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
1205
1231
|
}
|
|
1206
1232
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuBarComponent, decorators: [{
|
|
1207
1233
|
type: Component,
|
|
@@ -1210,8 +1236,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImpor
|
|
|
1210
1236
|
provide: RdtMenuBaseComponent,
|
|
1211
1237
|
useExisting: RdtMenuBarComponent,
|
|
1212
1238
|
},
|
|
1213
|
-
], template: "<ul class=\"menu-bar-item-container\" role=\"presentation\">\r\n
|
|
1214
|
-
}], propDecorators: {
|
|
1239
|
+
], template: "<ul class=\"menu-bar-item-container\" role=\"presentation\" #buttonContainer>\r\n @for(item of parsedItems; track item; let i = $index) {\r\n <li\r\n class=\"menu-bar-item\"\r\n role=\"presentation\"\r\n rdtAnyRouteActive=\"menu-bar-item-route-active\"\r\n [watchedRoutes]=\"getChildRoutes(item)\"\r\n (rdtKeyListener)=\"onKeyDown(i, $event)\"\r\n #anchorEl\r\n >\r\n @if(!item.routerLink && !item.externalLink) {\r\n <button\r\n #focusableItem\r\n class=\"menu-bar-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n (pointerenter)=\"onItemPointerEnter(item)\"\r\n [attr.aria-haspopup]=\"item.items ? 'menu' : null\"\r\n [attr.aria-expanded]=\"item === expandedChild?.item\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n {{ item.label }}\r\n\r\n <div class=\"menu-bar-item-right-content\">\r\n @if(item.shortcut) {\r\n <span class=\"menu-item-shortcut\">\r\n {{ item.shortcut.label }}\r\n </span>\r\n }\r\n <!-- TODO\r\n <rdt-icon\r\n *ngIf=\"item.items\"\r\n name=\"expand_more\"\r\n class=\"menu-bar-item-icon\"\r\n inverted\r\n />\r\n <rdt-icon\r\n *ngIf=\"item.icon\"\r\n [name]=\"item.icon\"\r\n class=\"menu-bar-item-icon\"\r\n inverted\r\n />\r\n -->\r\n @if(item.items) {\r\n <span class=\"menu-bar-item-icon rdt-menu-icon-down\"></span>\r\n }\r\n </div>\r\n </button>\r\n }\r\n\r\n <ng-template #linkBody let-item>\r\n {{ item.label }}\r\n\r\n <div class=\"menu-bar-item-right-content\">\r\n @if(item.shortcut) {\r\n <span class=\"menu-item-shortcut\">\r\n {{ item.shortcut.label }}\r\n </span>\r\n }\r\n <!--\r\n <rdt-icon\r\n *ngIf=\"item.icon\"\r\n [name]=\"item.icon\"\r\n class=\"menu-bar-item-icon\"\r\n inverted\r\n />\r\n --></div>\r\n </ng-template>\r\n\r\n @if(item.routerLink) {\r\n <a\r\n #focusableItem\r\n class=\"menu-bar-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n [routerLink]=\"item.routerLink\"\r\n [target]=\"item.target!\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n <ng-container\r\n *ngTemplateOutlet=\"linkBody; context: { $implicit: item }\"\r\n />\r\n </a>\r\n } @if(item.externalLink) {\r\n <a\r\n #focusableItem\r\n class=\"menu-bar-item-content\"\r\n role=\"menuitem\"\r\n (click)=\"onItemClick(item)\"\r\n [href]=\"item.externalLink\"\r\n [target]=\"item.target\"\r\n [attr.tabindex]=\"0\"\r\n [attr.data-testid]=\"item.dataTestId\"\r\n >\r\n <ng-container\r\n *ngTemplateOutlet=\"linkBody; context: { $implicit: item }\"\r\n />\r\n </a>\r\n } @if (item.items) {\r\n <rdt-menu-overlay\r\n [item]=\"$any(item)\"\r\n [expanded]=\"item === expandedChild?.item\"\r\n [autofocusItem]=\"autofocusSubmenuItem\"\r\n [preferredHorizontalDir]=\"preferredHorizontalDir\"\r\n [preferredVerticalDir]=\"preferredVerticalDir\"\r\n [level]=\"0\"\r\n [anchorElement]=\"anchorEl\"\r\n />\r\n }\r\n </li>\r\n }\r\n</ul>\r\n", styles: ["a.menu-bar-item-content,a.menu-item-content,button.menu-bar-item-content,button.menu-item-content{white-space:nowrap;appearance:none;text-decoration:none;box-sizing:border-box}.menu-item-right-content,.menu-bar-item-right-content{margin-left:auto;display:flex;align-items:center}.menu-item-shortcut,.menu-bar-item-shortcut{margin-left:2rem}.menu-item-icon,.menu-bar-item-icon{margin-left:.5rem;font-size:1.2rem}.dp3-menu-base ul{margin-bottom:0}.rdt-menu-root{margin-left:0}.rdt-menu-root.rdt-overlay-down{margin-top:var(--rdt-menu-overlay-margin-y)}.rdt-menu-root.rdt-overlay-up{margin-top:calc(-1 * var(--rdt-menu-overlay-margin-y))}.rdt-menu-sub.rdt-overlay-left{margin-left:calc(-1 * var(--rdt-menu-overlay-margin-x))}.rdt-menu-sub.rdt-overlay-right{margin-left:var(--rdt-menu-overlay-margin-x)}rdt-menu-bar{-webkit-user-select:none;user-select:none;pointer-events:none;padding:var(--rdt-menu-bar-padding)}.menu-bar-item-container{display:flex;list-style-type:none;margin-bottom:0;margin-top:0;margin-block-start:0;margin-block-end:0;padding-left:0}.menu-bar-item{pointer-events:all;margin:var(--rdt-menu-bar-item-margin);position:relative;display:flex;align-items:center;justify-content:center}.menu-bar-item.menu-bar-item-route-active .menu-bar-item-content{--rdt-menu-bar-item-background: var( --rdt-menu-bar-item-route-active-background );--rdt-menu-bar-item-text-color: var( --rdt-menu-bar-item-route-active-text-color );--rdt-menu-bar-item-border: var(--rdt-menu-bar-item-route-active-border);--rdt-menu-bar-item-outline: var(--rdt-menu-bar-item-route-active-outline)}.menu-bar-item [aria-expanded=true].menu-bar-item-content{--rdt-menu-bar-item-background: var( --rdt-menu-bar-item-expanded-background );--rdt-menu-bar-item-text-color: var( --rdt-menu-bar-item-expanded-text-color );--rdt-menu-bar-item-border: var(--rdt-menu-bar-item-expanded-border);--rdt-menu-bar-item-outline: var(--rdt-menu-bar-item-expanded-outline)}.menu-bar-item-content{cursor:pointer;display:flex;align-items:center;overflow:hidden;padding:var(--rdt-menu-bar-item-padding);border-radius:var(--rdt-menu-bar-item-border-radius);border:var(--rdt-menu-bar-item-border);background-color:var(--rdt-menu-bar-item-background);color:var(--rdt-menu-bar-item-text-color);outline:var(--rdt-menu-bar-item-outline);font-size:inherit}.menu-bar-item-content:hover{--rdt-menu-bar-item-background: var(--rdt-menu-bar-item-hover-background);--rdt-menu-bar-item-text-color: var(--rdt-menu-bar-item-hover-text-color);--rdt-menu-bar-item-border: var(--rdt-menu-bar-item-hover-border);--rdt-menu-bar-item-outline: var(--rdt-menu-bar-item-hover-outline)}.menu-bar-item .menu-bar-item-content.focus-visible:focus,.menu-bar-item .menu-bar-item-content:focus-visible{--rdt-menu-bar-item-background: var(--rdt-menu-bar-item-focus-background);--rdt-menu-bar-item-text-color: var(--rdt-menu-bar-item-focus-text-color);--rdt-menu-bar-item-border: var(--rdt-menu-bar-item-focus-border);--rdt-menu-bar-item-outline: var(--rdt-menu-bar-item-focus-outline)}.menu-bar-item-icon.rdt-menu-icon-down{width:0;height:0;border-left:var(--rdt-menu-default-icon-size) solid transparent;border-right:var(--rdt-menu-default-icon-size) solid transparent;border-top:var(--rdt-menu-default-icon-size) solid var(--rdt-menu-bar-item-text-color)}\n"] }]
|
|
1240
|
+
}], propDecorators: { buttonContainerRef: [{
|
|
1241
|
+
type: ViewChild,
|
|
1242
|
+
args: ['buttonContainer', { static: true }]
|
|
1243
|
+
}], items: [{
|
|
1215
1244
|
type: Input
|
|
1216
1245
|
}], headerHeight: [{
|
|
1217
1246
|
type: Input,
|
|
@@ -1224,6 +1253,92 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImpor
|
|
|
1224
1253
|
args: ['attr.role']
|
|
1225
1254
|
}] } });
|
|
1226
1255
|
|
|
1256
|
+
class RdtMenuComponent extends RdtMenuBaseComponent {
|
|
1257
|
+
buttonClass = inject(RDT_BUTTON_BASE_PROVIDER);
|
|
1258
|
+
trigger;
|
|
1259
|
+
dataTestId = '';
|
|
1260
|
+
get items() {
|
|
1261
|
+
return this._items;
|
|
1262
|
+
}
|
|
1263
|
+
set items(value) {
|
|
1264
|
+
this._items = value;
|
|
1265
|
+
const wrapper = {
|
|
1266
|
+
label: '',
|
|
1267
|
+
icon: '',
|
|
1268
|
+
items: value,
|
|
1269
|
+
};
|
|
1270
|
+
this.allParsedItems = parseMenuItems([wrapper], this.injector);
|
|
1271
|
+
this.filterItems();
|
|
1272
|
+
}
|
|
1273
|
+
_items;
|
|
1274
|
+
focusableElements = new QueryList();
|
|
1275
|
+
get buttonContainer() {
|
|
1276
|
+
return this.anchorElement ?? undefined;
|
|
1277
|
+
}
|
|
1278
|
+
get parsedItem() {
|
|
1279
|
+
return this.parsedItems[0];
|
|
1280
|
+
}
|
|
1281
|
+
get anchorElement() {
|
|
1282
|
+
return this.trigger.anchorElement;
|
|
1283
|
+
}
|
|
1284
|
+
ngOnInit() {
|
|
1285
|
+
super.ngOnInit();
|
|
1286
|
+
this.trigger.tabIndex = 0;
|
|
1287
|
+
this.trigger.dataTestId = this.dataTestId;
|
|
1288
|
+
this.trigger.click$.subscribe(() => this.toggle());
|
|
1289
|
+
this.listenPointerOver();
|
|
1290
|
+
if (this.anchorElement) {
|
|
1291
|
+
console.log('Anchor element:', this.anchorElement);
|
|
1292
|
+
this.focusableElements.reset([{ nativeElement: this.anchorElement }]);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
ngDoCheck() {
|
|
1296
|
+
if (this.trigger) {
|
|
1297
|
+
this.trigger.aria = {
|
|
1298
|
+
role: 'menuitem',
|
|
1299
|
+
'aria-haspopup': 'true',
|
|
1300
|
+
'aria-expanded': this.expandedChild?.item === this.parsedItem,
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
toggle() {
|
|
1305
|
+
this.onItemClick(this.parsedItem);
|
|
1306
|
+
this.cd.markForCheck();
|
|
1307
|
+
}
|
|
1308
|
+
listenPointerOver() {
|
|
1309
|
+
const target = this.anchorElement;
|
|
1310
|
+
const listener = this.renderer.listen(target, 'pointerover', (event) => {
|
|
1311
|
+
this.onItemPointerEnter(this.parsedItem);
|
|
1312
|
+
this.cd.markForCheck();
|
|
1313
|
+
});
|
|
1314
|
+
this.destroyRef.onDestroy(() => listener());
|
|
1315
|
+
}
|
|
1316
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
1317
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.7", type: RdtMenuComponent, selector: "rdt-menu", inputs: { trigger: "trigger", dataTestId: "dataTestId", items: "items" }, providers: [
|
|
1318
|
+
{
|
|
1319
|
+
provide: RdtMenuBaseComponent,
|
|
1320
|
+
useExisting: RdtMenuComponent,
|
|
1321
|
+
},
|
|
1322
|
+
], usesInheritance: true, ngImport: i0, template: "<rdt-menu-overlay\r\n *ngIf=\"parsedItem\"\r\n [anchorElement]=\"anchorElement!\"\r\n [item]=\"$any(parsedItem)\"\r\n [expanded]=\"expandedChild?.item === parsedItem\"\r\n [autofocusItem]=\"autofocusSubmenuItem\"\r\n [preferredHorizontalDir]=\"preferredHorizontalDir\"\r\n [preferredVerticalDir]=\"preferredVerticalDir\"\r\n [level]=\"0\"\r\n/>\r\n", styles: ["a.menu-bar-item-content,a.menu-item-content,button.menu-bar-item-content,button.menu-item-content{white-space:nowrap;appearance:none;text-decoration:none;box-sizing:border-box}.menu-item-right-content,.menu-bar-item-right-content{margin-left:auto;display:flex;align-items:center}.menu-item-shortcut,.menu-bar-item-shortcut{margin-left:2rem}.menu-item-icon,.menu-bar-item-icon{margin-left:.5rem;font-size:1.2rem}.dp3-menu-base ul{margin-bottom:0}.rdt-menu-root{margin-left:0}.rdt-menu-root.rdt-overlay-down{margin-top:var(--rdt-menu-overlay-margin-y)}.rdt-menu-root.rdt-overlay-up{margin-top:calc(-1 * var(--rdt-menu-overlay-margin-y))}.rdt-menu-sub.rdt-overlay-left{margin-left:calc(-1 * var(--rdt-menu-overlay-margin-x))}.rdt-menu-sub.rdt-overlay-right{margin-left:var(--rdt-menu-overlay-margin-x)}rdt-menu{display:block;position:relative}\n"], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: RdtMenuOverlayComponent, selector: "rdt-menu-overlay", inputs: ["item", "level", "preferredHorizontalDir", "preferredVerticalDir", "expanded", "autofocusItem", "anchorElement"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
1323
|
+
}
|
|
1324
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuComponent, decorators: [{
|
|
1325
|
+
type: Component,
|
|
1326
|
+
args: [{ selector: 'rdt-menu', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [
|
|
1327
|
+
{
|
|
1328
|
+
provide: RdtMenuBaseComponent,
|
|
1329
|
+
useExisting: RdtMenuComponent,
|
|
1330
|
+
},
|
|
1331
|
+
], template: "<rdt-menu-overlay\r\n *ngIf=\"parsedItem\"\r\n [anchorElement]=\"anchorElement!\"\r\n [item]=\"$any(parsedItem)\"\r\n [expanded]=\"expandedChild?.item === parsedItem\"\r\n [autofocusItem]=\"autofocusSubmenuItem\"\r\n [preferredHorizontalDir]=\"preferredHorizontalDir\"\r\n [preferredVerticalDir]=\"preferredVerticalDir\"\r\n [level]=\"0\"\r\n/>\r\n", styles: ["a.menu-bar-item-content,a.menu-item-content,button.menu-bar-item-content,button.menu-item-content{white-space:nowrap;appearance:none;text-decoration:none;box-sizing:border-box}.menu-item-right-content,.menu-bar-item-right-content{margin-left:auto;display:flex;align-items:center}.menu-item-shortcut,.menu-bar-item-shortcut{margin-left:2rem}.menu-item-icon,.menu-bar-item-icon{margin-left:.5rem;font-size:1.2rem}.dp3-menu-base ul{margin-bottom:0}.rdt-menu-root{margin-left:0}.rdt-menu-root.rdt-overlay-down{margin-top:var(--rdt-menu-overlay-margin-y)}.rdt-menu-root.rdt-overlay-up{margin-top:calc(-1 * var(--rdt-menu-overlay-margin-y))}.rdt-menu-sub.rdt-overlay-left{margin-left:calc(-1 * var(--rdt-menu-overlay-margin-x))}.rdt-menu-sub.rdt-overlay-right{margin-left:var(--rdt-menu-overlay-margin-x)}rdt-menu{display:block;position:relative}\n"] }]
|
|
1332
|
+
}], propDecorators: { trigger: [{
|
|
1333
|
+
type: Input,
|
|
1334
|
+
args: [{ required: true }]
|
|
1335
|
+
}], dataTestId: [{
|
|
1336
|
+
type: Input
|
|
1337
|
+
}], items: [{
|
|
1338
|
+
type: Input,
|
|
1339
|
+
args: [{ required: true }]
|
|
1340
|
+
}] } });
|
|
1341
|
+
|
|
1227
1342
|
class RdtMenuModule {
|
|
1228
1343
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1229
1344
|
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.7", ngImport: i0, type: RdtMenuModule, declarations: [RdtMenuOverlayComponent,
|