Skip to content

Commit 0fc90c8

Browse files
committed
refactor(aria/menu): Add accessors for pattern properties
1 parent ff5e7bb commit 0fc90c8

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

src/aria/menu/menu.ts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ import {DeferredContent, DeferredContentAware} from '@angular/aria/deferred-cont
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)',
@@ -69,6 +69,12 @@ 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+
7278
/** The menu trigger ui pattern instance. */
7379
_pattern: MenuTriggerPattern<V> = new MenuTriggerPattern({
7480
element: computed(() => this._elementRef.nativeElement),
@@ -108,7 +114,7 @@ export class MenuTrigger<V> {
108114
'role': 'menu',
109115
'class': 'ng-menu',
110116
'[attr.id]': '_pattern.id()',
111-
'[attr.data-visible]': '_pattern.isVisible()',
117+
'[attr.data-visible]': 'isVisible()',
112118
'(keydown)': '_pattern.onKeydown($event)',
113119
'(mouseover)': '_pattern.onMouseOver($event)',
114120
'(mouseout)': '_pattern.onMouseOut($event)',
@@ -173,8 +179,14 @@ export class Menu<V> {
173179
*/
174180
readonly items = () => this._items().map(i => i._pattern);
175181

182+
/** Whether the menu or any of its child elements are currently focused. */
183+
readonly isFocused = computed(() => this._pattern.isFocused());
184+
185+
/** Whether the menu has received focus. */
186+
readonly hasBeenFocused = computed(() => this._pattern.hasBeenFocused());
187+
176188
/** Whether the menu is visible. */
177-
isVisible = computed(() => this._pattern.isVisible());
189+
readonly isVisible = computed(() => this._pattern.isVisible());
178190

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

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

@@ -339,11 +357,11 @@ export class MenuBar<V> {
339357
'role': 'menuitem',
340358
'class': 'ng-menu-item',
341359
'(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()',
360+
'[attr.tabindex]': 'tabindex()',
361+
'[attr.data-active]': 'isActive()',
362+
'[attr.aria-haspopup]': 'hasPopup()',
363+
'[attr.aria-expanded]': 'expanded()',
364+
'[attr.aria-disabled]': 'disabled()',
347365
'[attr.aria-controls]': '_pattern.submenu()?.id()',
348366
},
349367
})
@@ -380,9 +398,21 @@ export class MenuItem<V> {
380398
/** The submenu associated with the menu item. */
381399
readonly submenu = input<Menu<V> | undefined>(undefined);
382400

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

407+
/** Whether the menuis expanded. */
408+
readonly expanded = computed(() => this._pattern.expanded());
409+
410+
/** Whether the menu item has a popup. */
411+
readonly hasPopup = computed(() => this._pattern.hasPopup());
412+
413+
/** The tabindex of the menu item. */
414+
readonly tabindex = computed(() => this._pattern.tabindex());
415+
386416
/** The menu item ui pattern instance. */
387417
readonly _pattern: MenuItemPattern<V> = new MenuItemPattern<V>({
388418
id: this.id,

0 commit comments

Comments
 (0)