Skip to content

Commit 1ee5b1e

Browse files
committed
refactor(aria/menu): Add accessors for pattern properties
1 parent 5d1ff93 commit 1ee5b1e

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

src/aria/menu/menu.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ import {Directionality} from '@angular/cdk/bidi';
4646
host: {
4747
'class': 'ng-menu-trigger',
4848
'[attr.tabindex]': '_pattern.tabIndex()',
49-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
50-
'[attr.aria-expanded]': '_pattern.expanded()',
49+
'[attr.aria-haspopup]': 'hasPopup()',
50+
'[attr.aria-expanded]': 'expanded()',
5151
'[attr.aria-controls]': '_pattern.menu()?.id()',
5252
'(click)': '_pattern.onClick()',
5353
'(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
element: computed(() => this._elementRef.nativeElement),
@@ -109,7 +115,7 @@ export class MenuTrigger<V> {
109115
'role': 'menu',
110116
'class': 'ng-menu',
111117
'[attr.id]': '_pattern.id()',
112-
'[attr.data-visible]': '_pattern.isVisible()',
118+
'[attr.data-visible]': 'isVisible()',
113119
'(keydown)': '_pattern.onKeydown($event)',
114120
'(mouseover)': '_pattern.onMouseOver($event)',
115121
'(mouseout)': '_pattern.onMouseOut($event)',
@@ -174,8 +180,14 @@ export class Menu<V> {
174180
*/
175181
readonly items = () => this._items().map(i => i._pattern);
176182

183+
/** Whether the menu or any of its child elements are currently focused. */
184+
readonly isFocused = computed(() => this._pattern.isFocused());
185+
186+
/** Whether the menu has received focus. */
187+
readonly hasBeenFocused = computed(() => this._pattern.hasBeenFocused());
188+
177189
/** Whether the menu is visible. */
178-
isVisible = computed(() => this._pattern.isVisible());
190+
readonly isVisible = computed(() => this._pattern.isVisible());
179191

180192
/** A callback function triggered when a menu item is selected. */
181193
onSelect = output<V>();
@@ -294,6 +306,12 @@ export class MenuBar<V> {
294306
/** The delay in seconds before the typeahead buffer is cleared. */
295307
readonly typeaheadDelay = input<number>(0.5);
296308

309+
/** Whether the menubar or any of its child elements are currently focused. */
310+
readonly isFocused = computed(() => this._pattern.isFocused());
311+
312+
/** Whether the menu has received focus. */
313+
readonly hasBeenFocused = computed(() => this._pattern.hasBeenFocused());
314+
297315
/** The menu ui pattern instance. */
298316
readonly _pattern: MenuBarPattern<V>;
299317

@@ -341,9 +359,9 @@ export class MenuBar<V> {
341359
'class': 'ng-menu-item',
342360
'(focusin)': 'onFocusIn()',
343361
'[attr.tabindex]': '_pattern.tabIndex()',
344-
'[attr.data-active]': '_pattern.isActive()',
345-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
346-
'[attr.aria-expanded]': '_pattern.expanded()',
362+
'[attr.data-active]': 'isActive()',
363+
'[attr.aria-haspopup]': 'hasPopup()',
364+
'[attr.aria-expanded]': 'expanded()',
347365
'[attr.aria-disabled]': '_pattern.disabled()',
348366
'[attr.aria-controls]': '_pattern.submenu()?.id()',
349367
},
@@ -381,9 +399,18 @@ export class MenuItem<V> {
381399
/** The submenu associated with the menu item. */
382400
readonly submenu = input<Menu<V> | undefined>(undefined);
383401

402+
/** Whether the menu item is active. */
403+
readonly isActive = computed(() => this._pattern.isActive());
404+
384405
/** Whether the menu item has been focused. */
385406
readonly hasBeenFocused = signal(false);
386407

408+
/** Whether the menuis expanded. */
409+
readonly expanded = computed(() => this._pattern.expanded());
410+
411+
/** Whether the menu item has a popup. */
412+
readonly hasPopup = computed(() => this._pattern.hasPopup());
413+
387414
/** The menu item ui pattern instance. */
388415
readonly _pattern: MenuItemPattern<V> = new MenuItemPattern<V>({
389416
id: this.id,

0 commit comments

Comments
 (0)