Skip to content

Commit 0a15bd7

Browse files
committed
feat(aria/menu): Add accessors for pattern properties
1 parent 64f1d43 commit 0a15bd7

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),
@@ -118,7 +127,7 @@ export class MenuTrigger<V> {
118127
'role': 'menu',
119128
'class': 'ng-menu',
120129
'[attr.id]': '_pattern.id()',
121-
'[attr.data-visible]': '_pattern.isVisible()',
130+
'[attr.data-visible]': 'isVisible()',
122131
'(keydown)': '_pattern.onKeydown($event)',
123132
'(mouseover)': '_pattern.onMouseOver($event)',
124133
'(mouseout)': '_pattern.onMouseOut($event)',
@@ -183,8 +192,14 @@ export class Menu<V> {
183192
*/
184193
readonly items = () => this._items().map(i => i._pattern);
185194

195+
/** Whether the menu or any of its child elements are currently focused. */
196+
readonly isFocused = computed(() => this._pattern.isFocused());
197+
198+
/** Whether the menu has received focus. */
199+
readonly hasBeenFocused = computed(() => this._pattern.hasBeenFocused());
200+
186201
/** Whether the menu is visible. */
187-
isVisible = computed(() => this._pattern.isVisible());
202+
readonly isVisible = computed(() => this._pattern.isVisible());
188203

189204
/** A callback function triggered when a menu item is selected. */
190205
onSelect = output<V>();
@@ -313,6 +328,12 @@ export class MenuBar<V> {
313328
/** The delay in seconds before the typeahead buffer is cleared. */
314329
readonly typeaheadDelay = input<number>(0.5);
315330

331+
/** Whether the menubar or any of its child elements are currently focused. */
332+
readonly isFocused = computed(() => this._pattern.isFocused());
333+
334+
/** Whether the menu has received focus. */
335+
readonly hasBeenFocused = computed(() => this._pattern.hasBeenFocused());
336+
316337
/** The menu ui pattern instance. */
317338
readonly _pattern: MenuBarPattern<V>;
318339

@@ -374,11 +395,11 @@ export class MenuBar<V> {
374395
'role': 'menuitem',
375396
'class': 'ng-menu-item',
376397
'(focusin)': 'onFocusIn()',
377-
'[attr.tabindex]': '_pattern.tabindex()',
378-
'[attr.data-active]': '_pattern.isActive()',
379-
'[attr.aria-haspopup]': '_pattern.hasPopup()',
380-
'[attr.aria-expanded]': '_pattern.expanded()',
381-
'[attr.aria-disabled]': '_pattern.disabled()',
398+
'[attr.tabindex]': 'tabindex()',
399+
'[attr.data-active]': 'isActive()',
400+
'[attr.aria-haspopup]': 'hasPopup()',
401+
'[attr.aria-expanded]': 'expanded()',
402+
'[attr.aria-disabled]': 'disabled()',
382403
'[attr.aria-controls]': '_pattern.submenu()?.id()',
383404
},
384405
})
@@ -415,9 +436,21 @@ export class MenuItem<V> {
415436
/** The submenu associated with the menu item. */
416437
readonly submenu = input<Menu<V> | undefined>(undefined);
417438

439+
/** Whether the menu item is active. */
440+
readonly isActive = computed(() => this._pattern.isActive());
441+
418442
/** Whether the menu item has been focused. */
419443
readonly hasBeenFocused = signal(false);
420444

445+
/** Whether the menuis expanded. */
446+
readonly expanded = computed(() => this._pattern.expanded());
447+
448+
/** Whether the menu item has a popup. */
449+
readonly hasPopup = computed(() => this._pattern.hasPopup());
450+
451+
/** The tabindex of the menu item. */
452+
readonly tabindex = computed(() => this._pattern.tabindex());
453+
421454
/** The menu item ui pattern instance. */
422455
readonly _pattern: MenuItemPattern<V> = new MenuItemPattern<V>({
423456
id: this.id,

0 commit comments

Comments
 (0)