Skip to content

Commit 9100c6d

Browse files
committed
refactor(aria/menu): Add accessors for pattern properties
fix menu
1 parent ac5addc commit 9100c6d

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/aria/menu/menu.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ import {Directionality} from '@angular/cdk/bidi';
4545
host: {
4646
'class': 'ng-menu-trigger',
4747
'[attr.tabindex]': '_pattern.tabIndex()',
48-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
49-
'[attr.aria-expanded]': '_pattern.expanded()',
48+
'[attr.aria-haspopup]': 'hasPopup()',
49+
'[attr.aria-expanded]': 'expanded()',
5050
'[attr.aria-controls]': '_pattern.menu()?.id()',
5151
'(click)': '_pattern.onClick()',
5252
'(keydown)': '_pattern.onKeydown($event)',
@@ -70,6 +70,12 @@ export class MenuTrigger<V> {
7070
/** Whether the menu item has been focused. */
7171
readonly hasBeenFocused = signal(false);
7272

73+
/** Whether the menu is expanded. */
74+
readonly expanded = computed(() => this._pattern.expanded());
75+
76+
/** Whether the menu trigger has a popup. */
77+
readonly hasPopup = computed(() => this._pattern.hasPopup());
78+
7379
/** The menu trigger ui pattern instance. */
7480
_pattern: MenuTriggerPattern<V> = new MenuTriggerPattern({
7581
textDirection: this.textDirection,
@@ -110,7 +116,7 @@ export class MenuTrigger<V> {
110116
'role': 'menu',
111117
'class': 'ng-menu',
112118
'[attr.id]': '_pattern.id()',
113-
'[attr.data-visible]': '_pattern.isVisible()',
119+
'[attr.data-visible]': 'isVisible()',
114120
'(keydown)': '_pattern.onKeydown($event)',
115121
'(mouseover)': '_pattern.onMouseOver($event)',
116122
'(mouseout)': '_pattern.onMouseOut($event)',
@@ -171,7 +177,7 @@ export class Menu<V> {
171177
readonly items = () => this._items().map(i => i._pattern);
172178

173179
/** Whether the menu is visible. */
174-
isVisible = computed(() => this._pattern.isVisible());
180+
readonly isVisible = computed(() => this._pattern.isVisible());
175181

176182
/** A callback function triggered when a menu item is selected. */
177183
onSelect = output<V>();
@@ -335,9 +341,9 @@ export class MenuBar<V> {
335341
'class': 'ng-menu-item',
336342
'(focusin)': 'onFocusIn()',
337343
'[attr.tabindex]': '_pattern.tabIndex()',
338-
'[attr.data-active]': '_pattern.isActive()',
339-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
340-
'[attr.aria-expanded]': '_pattern.expanded()',
344+
'[attr.data-active]': 'isActive()',
345+
'[attr.aria-haspopup]': 'hasPopup()',
346+
'[attr.aria-expanded]': 'expanded()',
341347
'[attr.aria-disabled]': '_pattern.disabled()',
342348
'[attr.aria-controls]': '_pattern.submenu()?.id()',
343349
},
@@ -375,8 +381,14 @@ export class MenuItem<V> {
375381
/** The submenu associated with the menu item. */
376382
readonly submenu = input<Menu<V> | undefined>(undefined);
377383

378-
/** Whether the menu item has been focused. */
379-
readonly hasBeenFocused = signal(false);
384+
/** Whether the menu item is active. */
385+
readonly isActive = computed(() => this._pattern.isActive());
386+
387+
/** Whether the menu is expanded. */
388+
readonly expanded = computed(() => this._pattern.expanded());
389+
390+
/** Whether the menu item has a popup. */
391+
readonly hasPopup = computed(() => this._pattern.hasPopup());
380392

381393
/** The menu item ui pattern instance. */
382394
readonly _pattern: MenuItemPattern<V> = new MenuItemPattern<V>({

0 commit comments

Comments
 (0)