Skip to content

Commit e709fd4

Browse files
committed
feat(aria/menu): Add accessors for pattern properties
1 parent 17662bc commit e709fd4

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

src/aria/menu/menu.ts

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ import {DeferredContent, DeferredContentAware} from '@angular/aria/deferred-cont
4444
exportAs: 'ngMenuTrigger',
4545
host: {
4646
'class': 'ng-menu-trigger',
47-
'[attr.tabindex]': '_pattern.tabindex()',
48-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
49-
'[attr.aria-expanded]': '_pattern.expanded()',
47+
'[attr.tabindex]': 'tabindex()',
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)',
@@ -69,6 +69,15 @@ export class MenuTrigger<V> {
6969
/** Whether the menu item has been focused. */
7070
readonly hasBeenFocused = signal(false);
7171

72+
/** Whether the menu is expanded. */
73+
readonly expanded = computed(() => this._pattern.expanded());
74+
75+
/** Whether the menu trigger has a popup. */
76+
readonly hasPopup = computed(() => this._pattern.hasPopup());
77+
78+
/** The tabindex of the menu trigger. */
79+
readonly tabindex = computed(() => this._pattern.tabindex());
80+
7281
/** The menu trigger ui pattern instance. */
7382
_pattern: MenuTriggerPattern<V> = new MenuTriggerPattern({
7483
element: computed(() => this._elementRef.nativeElement),
@@ -108,7 +117,7 @@ export class MenuTrigger<V> {
108117
'role': 'menu',
109118
'class': 'ng-menu',
110119
'[attr.id]': '_pattern.id()',
111-
'[attr.data-visible]': '_pattern.isVisible()',
120+
'[attr.data-visible]': 'isVisible()',
112121
'(keydown)': '_pattern.onKeydown($event)',
113122
'(mouseover)': '_pattern.onMouseOver($event)',
114123
'(mouseout)': '_pattern.onMouseOut($event)',
@@ -173,8 +182,14 @@ export class Menu<V> {
173182
*/
174183
readonly items = () => this._items().map(i => i._pattern);
175184

185+
/** Whether the menu or any of its child elements are currently focused. */
186+
readonly isFocused = computed(() => this._pattern.isFocused());
187+
188+
/** Whether the menu has received focus. */
189+
readonly hasBeenFocused = computed(() => this._pattern.hasBeenFocused());
190+
176191
/** Whether the menu is visible. */
177-
isVisible = computed(() => this._pattern.isVisible());
192+
readonly isVisible = computed(() => this._pattern.isVisible());
178193

179194
/** A callback function triggered when a menu item is selected. */
180195
onSelect = output<V>();
@@ -293,6 +308,12 @@ export class MenuBar<V> {
293308
/** The delay in seconds before the typeahead buffer is cleared. */
294309
readonly typeaheadDelay = input<number>(0.5);
295310

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

@@ -339,11 +360,11 @@ export class MenuBar<V> {
339360
'role': 'menuitem',
340361
'class': 'ng-menu-item',
341362
'(focusin)': 'onFocusIn()',
342-
'[attr.tabindex]': '_pattern.tabindex()',
343-
'[attr.data-active]': '_pattern.isActive()',
344-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
345-
'[attr.aria-expanded]': '_pattern.expanded()',
346-
'[attr.aria-disabled]': '_pattern.disabled()',
363+
'[attr.tabindex]': 'tabindex()',
364+
'[attr.data-active]': 'isActive()',
365+
'[attr.aria-haspopup]': 'hasPopup()',
366+
'[attr.aria-expanded]': 'expanded()',
367+
'[attr.aria-disabled]': 'disabled()',
347368
'[attr.aria-controls]': '_pattern.submenu()?.id()',
348369
},
349370
})
@@ -380,9 +401,21 @@ export class MenuItem<V> {
380401
/** The submenu associated with the menu item. */
381402
readonly submenu = input<Menu<V> | undefined>(undefined);
382403

404+
/** Whether the menu item is active. */
405+
readonly isActive = computed(() => this._pattern.isActive());
406+
383407
/** Whether the menu item has been focused. */
384408
readonly hasBeenFocused = signal(false);
385409

410+
/** Whether the menuis expanded. */
411+
readonly expanded = computed(() => this._pattern.expanded());
412+
413+
/** Whether the menu item has a popup. */
414+
readonly hasPopup = computed(() => this._pattern.hasPopup());
415+
416+
/** The tabindex of the menu item. */
417+
readonly tabindex = computed(() => this._pattern.tabindex());
418+
386419
/** The menu item ui pattern instance. */
387420
readonly _pattern: MenuItemPattern<V> = new MenuItemPattern<V>({
388421
id: this.id,

0 commit comments

Comments
 (0)